From f151a8ac3a8f944829e55fc007823b167f1a2597 Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Tue, 5 Jan 2021 22:58:41 +0200 Subject: chore: Move statistics related functions to it's own file fix: Extract database constructor to a separate file to ensure we only create one knex instance/db feat: Add cron for saving the stats to the database every hour feat: Get cached stats from database (if a stat is not found in the db, generate it) --- .../migrations/20210105222742_addStatisticsTable.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/api/database/migrations/20210105222742_addStatisticsTable.js (limited to 'src/api/database/migrations/20210105222742_addStatisticsTable.js') diff --git a/src/api/database/migrations/20210105222742_addStatisticsTable.js b/src/api/database/migrations/20210105222742_addStatisticsTable.js new file mode 100644 index 0000000..d920ac1 --- /dev/null +++ b/src/api/database/migrations/20210105222742_addStatisticsTable.js @@ -0,0 +1,16 @@ + +exports.up = async knex => { + await knex.schema.createTable('statistics', table => { + table.increments(); + table.integer('batchId'); + table.string('type'); + table.json('data'); + table.timestamp('createdAt'); + + table.unique(['batchId', 'type']); + }); +}; + +exports.down = async knex => { + await knex.schema.dropTableIfExists('statistics'); +}; -- cgit v1.2.3