Skip to content

Commit

Permalink
chore: add migration for traffic data collection (#6171)
Browse files Browse the repository at this point in the history
## About the changes

Adds migration for creating table `stat_traffic_usage`.
This table primary-keys on day, traffic_group, and status_code_series.
Adds individual indexes for day, traffic_group, and status_code_series.

Traffic group is the grouping for API endpoints for which traffic is
counted.
status_code_series is 200/202 etc = 200, 304 etc = 300
  • Loading branch information
daveleek committed Feb 9, 2024
1 parent 4c1dfbe commit 1b1bde8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/migrations/20240208123212-create-stat-traffic-usage-table.js
@@ -0,0 +1,30 @@

exports.up = (db, callback) => {
db.runSql(
`
CREATE TABLE IF NOT EXISTS stat_traffic_usage(
day DATE NOT NULL,
traffic_group TEXT NOT NULL,
status_code_series INT NOT NULL,
count BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY(day, traffic_group, status_code_series)
);
CREATE INDEX IF NOT EXISTS stat_traffic_usage_day_idx ON stat_traffic_usage (day);
CREATE INDEX IF NOT EXISTS stat_traffic_usage_traffic_group_idx ON stat_traffic_usage (traffic_group);
CREATE INDEX IF NOT EXISTS stat_traffic_usage_status_code_series_idx ON stat_traffic_usage (status_code_series);
`,
callback,
);
};

exports.down = (db, callback) => {
db.runSql(
`
DROP INDEX IF EXISTS stat_traffic_usage_day_idx;
DROP INDEX IF EXISTS stat_traffic_usage_traffic_group_idx;
DROP INDEX IF EXISTS stat_traffic_usage_status_code_series_idx;
DROP TABLE IF EXISTS stat_traffic_usage;
`,
callback,
);
};

0 comments on commit 1b1bde8

Please sign in to comment.