From ff973432f1c3732e1830abd6a45daf1e7c662fdd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 26 Nov 2024 10:04:16 -0500 Subject: [PATCH] feat: add latest population table Signed-off-by: Evan Prodromou --- .../20241126144816-latest-population.js | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 api/migrations/20241126144816-latest-population.js diff --git a/api/migrations/20241126144816-latest-population.js b/api/migrations/20241126144816-latest-population.js new file mode 100644 index 00000000..d4bd19f4 --- /dev/null +++ b/api/migrations/20241126144816-latest-population.js @@ -0,0 +1,60 @@ +'use strict'; + +var dbm; +var type; +var seed; + +/** + * We receive the dbmigrate dependency from dbmigrate initially. + * This enables us to not have to rely on NODE_PATH. + */ +exports.setup = function (options, seedLink) { + dbm = options.dbmigrate; + type = dbm.dataType; + seed = seedLink; +}; + +exports.up = async (db) => + db.createTable('LatestPopulation', { + columns: { + actor_id: { + type: 'string', + length: 255, + primaryKey: true, + foreignKey: { + name: "latest_population_actor_actor_id_fk", + table: "Actor", + rules: { + onDelete: 'CASCADE', + onUpdate: 'RESTRICT', + }, + mapping: "actor_id", + }, + }, + year: { type: 'int' }, + population: { type: 'bigint' }, + created: { type: 'timestamp', notNull: true }, + last_updated: { type: 'timestamp', notNull: true }, + datasource_id: { + type: 'string', + length: 255, + notNull: true, + foreignKey: { + name: 'latest_population_datasource_datasource_id_fk', + table: 'DataSource', + rules: { + onDelete: 'CASCADE', + onUpdate: 'RESTRICT', + }, + mapping: 'datasource_id', + }, + } + }, + }) + +exports.down = async (db) => + db.dropTable('LatestPopulation') + +exports._meta = { + "version": 1 +};