From d2914ebbf2ef579a0a07a63bbf5b7e25c62cd227 Mon Sep 17 00:00:00 2001 From: Jason Claxton Date: Mon, 9 Oct 2023 18:40:04 +0100 Subject: [PATCH] Create migration, model etc for `licence_versions` https://eaflood.atlassian.net/browse/WATER-3486 Whilst working on the unit tests for the enhancement in this PR https://github.com/DEFRA/water-abstraction-system/pull/443 it was found that we would need the migrations, model, helper and unit tests for table `licence_versions`. These will be created in this PR. --- ...009155523_create-water-licence-versions.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 db/migrations/20231009155523_create-water-licence-versions.js diff --git a/db/migrations/20231009155523_create-water-licence-versions.js b/db/migrations/20231009155523_create-water-licence-versions.js new file mode 100644 index 0000000000..00699ff1e4 --- /dev/null +++ b/db/migrations/20231009155523_create-water-licence-versions.js @@ -0,0 +1,34 @@ +'use strict' + +const tableName = 'licence_versions' + +exports.up = function (knex) { + return knex + .schema + .withSchema('water') + .createTable(tableName, (table) => { + // Primary Key + table.uuid('licence_version_id').primary().defaultTo(knex.raw('gen_random_uuid()')) + + // Data + table.uuid('licence_id').notNullable() + table.integer('issue').notNullable() + table.integer('increment').notNullable() + table.string('status').notNullable() + table.date('start_date').notNullable() + table.date('end_date') + table.string('external_id').notNullable() + table.boolean('is_test').notNullable().defaultTo(false) + + // Legacy timestamps + table.timestamp('date_created', { useTz: false }).notNullable() + table.timestamp('date_updated', { useTz: false }).notNullable() + }) +} + +exports.down = function (knex) { + return knex + .schema + .withSchema('water') + .dropTableIfExists(tableName) +}