From 2b25faa175a8dcfcb8500aecab205bdf8d4bb230 Mon Sep 17 00:00:00 2001 From: Laura Bergoens Date: Wed, 27 Nov 2024 15:33:02 +0100 Subject: [PATCH] Alter primary column from string to integer Co-authored-by: Nicolas Lepage --- .../factory/learning-content/build-mission.js | 2 +- ...ter-table-column-id-missions-to-integer.js | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 api/db/migrations/20241127142253_alter-table-column-id-missions-to-integer.js diff --git a/api/db/database-builder/factory/learning-content/build-mission.js b/api/db/database-builder/factory/learning-content/build-mission.js index d85eba5d280..b410c641bb6 100644 --- a/api/db/database-builder/factory/learning-content/build-mission.js +++ b/api/db/database-builder/factory/learning-content/build-mission.js @@ -1,7 +1,7 @@ import { databaseBuffer } from '../../database-buffer.js'; export function buildMission({ - id = 'missionIdA', + id = 1, status = 'status Mission A', name_i18n = { fr: 'name FR Mission A', en: 'name EN Mission A' }, content = { some: 'content' }, diff --git a/api/db/migrations/20241127142253_alter-table-column-id-missions-to-integer.js b/api/db/migrations/20241127142253_alter-table-column-id-missions-to-integer.js new file mode 100644 index 00000000000..9f1205771a7 --- /dev/null +++ b/api/db/migrations/20241127142253_alter-table-column-id-missions-to-integer.js @@ -0,0 +1,30 @@ +const TABLE_NAME = 'missions'; +const SCHEMA_NAME = 'learningcontent'; +/** + * @param { import("knex").Knex } knex + * @returns { Promise } + */ +export async function up(knex) { + await knex.schema.withSchema(SCHEMA_NAME).dropTable(TABLE_NAME); + await knex.schema.withSchema(SCHEMA_NAME).createTable('missions', function (table) { + table.integer('id').primary(); + table.string('status'); + table.jsonb('name_i18n'); + table.jsonb('content'); + table.jsonb('learningObjectives_i18n'); + table.jsonb('validatedObjectives_i18n'); + table.string('introductionMediaType'); + table.text('introductionMediaUrl'); + table.jsonb('introductionMediaAlt_i18n'); + table.text('documentationUrl'); + table.text('cardImageUrl'); + table.string('competenceId'); + }); +} + +/** + * @returns { Promise } + */ +export async function down() { + // non +}