forked from dnarkiewicz/usagov-analytics
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a postgres db to the docker compose configuration so the analytics-reporter can write to a db when running in docker compose. A tradeoff is that the migrations had to be copied into this app from analytics-reporter-api. Hopefully, if we integrate analytics-reporter-api into our docker-compose configuration, we can remove the migrations from this repo and use the ones in the API repo.
- Loading branch information
Showing
8 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/bin/bash | ||
|
||
npm install | ||
npm run migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const config = require("./src/config") | ||
|
||
module.exports = { | ||
development: { | ||
client: 'postgresql', | ||
connection: config.postgres, | ||
}, | ||
test: { | ||
client: 'postgresql', | ||
connection: { | ||
database: process.env.TRAVIS ? "travis_ci_test" : "analytics_reporter_test", | ||
}, | ||
migrations: { | ||
tableName: 'knex_migrations', | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
exports.up = function(knex) { | ||
return knex.schema.createTable("analytics_data", table => { | ||
table.increments("id") | ||
table.string("report_name") | ||
table.string("report_agency") | ||
table.dateTime("date_time") | ||
table.jsonb("data") | ||
table.timestamps(true, true) | ||
}) | ||
}; | ||
|
||
exports.down = function(knex) { | ||
return knex.schema.dropTable('analytics_data') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
exports.up = function(knex) { | ||
return knex.schema.table("analytics_data", table => { | ||
table.index(["report_name", "report_agency"]) | ||
}).then(() => { | ||
return knex.schema.raw("CREATE INDEX analytics_data_date_time_desc ON analytics_data (date_time DESC NULLS LAST)") | ||
}) | ||
}; | ||
|
||
exports.down = function(knex, Promise) { | ||
return knex.schema.table("analytics_data", table => { | ||
table.dropIndex(["report_name", "report_agency"]) | ||
table.dropIndex("date_time", "analytics_data_date_time_desc") | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
exports.up = function(knex, Promise) { | ||
return knex.schema.raw("ALTER TABLE analytics_data RENAME COLUMN date_time TO date").then(() => { | ||
return knex.schema.raw("ALTER TABLE analytics_data ALTER COLUMN date TYPE date") | ||
}) | ||
}; | ||
|
||
exports.down = function(knex, Promise) { | ||
return knex.schema.raw("ALTER TABLE analytics_data RENAME COLUMN date TO date_time").then(() => { | ||
return knex.schema.raw("ALTER TABLE analytics_data ALTER COLUMN date_time TYPE timestamp with time zone") | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters