Skip to content

Commit 1552533

Browse files
Merge pull request #219 from 18F/develop
Version Routing in support of UA to GA4 migration
2 parents 9015518 + c50436d commit 1552533

17 files changed

+5691
-7442
lines changed

.circleci/config.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2.1
1+
version: 2.1
22
jobs:
33
develop_deploy:
44
docker:
@@ -11,25 +11,25 @@ jobs:
1111
POSTGRES_DB: analytics-api-test
1212
steps:
1313
- checkout
14-
14+
1515
- restore_cache:
1616
keys:
1717
- v1-dependencies-{{ checksum "package.json" }}
1818
- v1-dependencies-
19-
19+
2020
- run:
2121
name: install dependencies
2222
command: npm install
23-
23+
2424
- save_cache:
2525
paths:
2626
- ./node_modules
2727
key: v1-dependencies-{{ checksum "package.json" }}
28-
28+
2929
- run:
3030
name: run tests
3131
command: npm test
32-
32+
3333
- run:
3434
name: Replace Data URL in manifest.yml file when deploying to develop
3535
command: |
@@ -51,14 +51,14 @@ jobs:
5151
rm ./src/config.js
5252
mv ./src/config.js.cloudgov ./src/config.js
5353
rm knexfile.js
54-
mv knexfile.js.cloudgov knexfile.js
54+
mv knexfile.js.cloudgov knexfile.js
5555
56-
- run:
56+
- run:
5757
name: Install CF CLI
5858
command: |
5959
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
6060
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
61-
61+
6262
- run:
6363
name: deploy
6464
command: |
@@ -68,7 +68,7 @@ jobs:
6868
cf login -u $CF_USERNAME_DEV -p $CF_PASSWORD_DEV -o gsa-opp-analytics -s analytics-dev
6969
cat manifest.yml
7070
cf push -f "./manifest.yml"
71-
cf set-env analytics-reporter-api-develop API_DATA_GOV_SECRET "$API_SECRET"
71+
cf set-env analytics-reporter-api-develop API_DATA_GOV_SECRET "$API_SECRET_LOWER"
7272
cf restage analytics-reporter-api-develop
7373
cf logout
7474
@@ -83,25 +83,25 @@ jobs:
8383
POSTGRES_DB: analytics-api-test
8484
steps:
8585
- checkout
86-
86+
8787
- restore_cache:
8888
keys:
8989
- v1-dependencies-{{ checksum "package.json" }}
9090
- v1-dependencies-
91-
91+
9292
- run:
9393
name: install dependencies
9494
command: npm install
95-
95+
9696
- save_cache:
9797
paths:
9898
- ./node_modules
9999
key: v1-dependencies-{{ checksum "package.json" }}
100-
100+
101101
- run:
102102
name: run tests
103103
command: npm test
104-
104+
105105
- run:
106106
name: Replace Data URL in manifest.yml file when deploying to staging
107107
command: |
@@ -125,12 +125,12 @@ jobs:
125125
rm ./src/config.js
126126
mv ./src/config.js.cloudgov ./src/config.js
127127
128-
- run:
128+
- run:
129129
name: Install CF CLI
130130
command: |
131131
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
132132
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
133-
133+
134134
- run:
135135
name: deploy
136136
command: |
@@ -140,7 +140,7 @@ jobs:
140140
cf login -u $CF_STAGING_SPACE_DEPLOYER_USERNAME -p $CF_STAGING_SPACE_DEPLOYER_PASSWORD -o gsa-opp-analytics -s analytics-staging
141141
cat manifest.yml
142142
cf push -f "./manifest.yml"
143-
cf set-env analytics-reporter-api-staging API_DATA_GOV_SECRET "$API_SECRET"
143+
cf set-env analytics-reporter-api-staging API_DATA_GOV_SECRET "$API_SECRET_LOWER"
144144
cf restage analytics-reporter-api-staging
145145
cf logout
146146
@@ -155,25 +155,25 @@ jobs:
155155
POSTGRES_DB: analytics-api-test
156156
steps:
157157
- checkout
158-
158+
159159
- restore_cache:
160160
keys:
161161
- v1-dependencies-{{ checksum "package.json" }}
162162
- v1-dependencies-
163-
163+
164164
- run:
165165
name: install dependencies
166166
command: npm install
167-
167+
168168
- save_cache:
169169
paths:
170170
- ./node_modules
171171
key: v1-dependencies-{{ checksum "package.json" }}
172-
172+
173173
- run:
174174
name: run tests
175175
command: npm test
176-
176+
177177
- run:
178178
name: Replace Data URL in manifest.yml file when deploying to production
179179
command: |
@@ -197,12 +197,12 @@ jobs:
197197
rm ./src/config.js
198198
mv ./src/config.js.cloudgov ./src/config.js
199199
200-
- run:
200+
- run:
201201
name: Install CF CLI
202202
command: |
203203
sudo curl -v -L -o cf8-cli-installer_8.7.4_x86-64.deb 'https://packages.cloudfoundry.org/stable?release=debian64&version=8.7.4'
204204
sudo dpkg -i cf8-cli-installer_8.7.4_x86-64.deb
205-
205+
206206
- run:
207207
name: deploy
208208
command: |
@@ -218,23 +218,23 @@ jobs:
218218
219219
workflows:
220220
develop_workflow:
221-
jobs:
221+
jobs:
222222
- develop_deploy:
223223
filters:
224224
branches:
225225
only:
226226
- develop
227227

228228
staging:
229-
jobs:
229+
jobs:
230230
- staging_deploy:
231231
filters:
232232
branches:
233233
only:
234234
- stage
235235

236236
main_workflow:
237-
jobs:
237+
jobs:
238238
- main_deploy:
239239
filters:
240240
branches:

.eslintrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.11

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ in response to HTTP requests.
1313

1414
This Analytics API maintains the schema for the database that the
1515
[Analytics Reporter](https://github.com/18F/analytics-reporter)
16-
writes to.
17-
Thus, the Analytics API must be setup and
16+
writes to. Thus, the Analytics API must be setup and
1817
configured before the Analytics Reporter starts writing data.
1918

2019
First, create the database:
@@ -23,6 +22,10 @@ First, create the database:
2322
createdb analytics-reporter
2423
```
2524

25+
````bash
26+
export NODE_ENV=development # developing locally
27+
````
28+
2629
Once the database is created, clone the app and install the dependencies via NPM.
2730
The install script has a postinstall hook that will migrate
2831
the database.
@@ -48,6 +51,7 @@ is configured to write to the same database and run with the `--write-to-databas
4851
# Using the API
4952

5053
The Analytics API exposes 3 API endpoints:
54+
include version in the request, ie `/v2/`
5155

5256
- `/reports/:report_name/data`
5357
- `/agencies/:agency_name/reports/:reportName/data`

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
export NEW_RELIC_APP_NAME="analytics-reporter-api"
3-
export NODE_ENV="test"
43
export PATH="$PATH:/home/vcap/deps/0/bin"
4+
npm run migrate
55
npm start

env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export NODE_ENV=development
2+
export POSTGRES_USER=postgres
3+
export POSTGRES_PASSWORD=123abc
4+
export POSTGRES_DATABASE=analytics-reporter

knexfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ module.exports = {
22
development: {
33
client: 'postgresql',
44
connection: {
5-
database: 'analytics-reporter'
5+
user: process.env.POSTGRES_USER || 'postgres',
6+
password: process.env.POSTGRES_PASSWORD || '123abc',
7+
database: process.env.POSTGRES_DATABASE || 'analytics-reporter',
68
}
79
},
810
production: {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
exports.up = function(knex) {
2+
return knex.schema.createTable("analytics_data_ga4", table => {
3+
table.increments("id")
4+
table.string("report_name")
5+
table.string("report_agency")
6+
table.dateTime("date")
7+
table.jsonb("data")
8+
table.timestamps(true, true)
9+
table.string("version")
10+
})
11+
};
12+
13+
exports.down = function(knex) {
14+
return knex.schema.dropTable('analytics_data_ga4')
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param { import("knex").Knex } knex
3+
* @returns { Promise<void> }
4+
*/
5+
exports.up = function(knex) {
6+
return knex.schema.raw("ALTER TABLE analytics_data_ga4 ALTER COLUMN date TYPE date")
7+
};
8+
9+
/**
10+
* @param { import("knex").Knex } knex
11+
* @returns { Promise<void> }
12+
*/
13+
exports.down = function(knex) {
14+
return knex.schema.raw("ALTER TABLE analytics_data_ga4 ALTER COLUMN date TYPE timestamp with time zone")
15+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param { import("knex").Knex } knex
3+
* @returns { Promise<void> }
4+
*/
5+
exports.up = function(knex) {
6+
return knex.schema.table("analytics_data_ga4", table => {
7+
table.dropColumn('version')
8+
})
9+
};
10+
11+
/**
12+
* @param { import("knex").Knex } knex
13+
* @returns { Promise<void> }
14+
*/
15+
exports.down = function(knex) {
16+
return knex.schema.table("analytics_data_ga4", table => {
17+
table.string('version')
18+
})
19+
};

0 commit comments

Comments
 (0)