From 584fc0761cb75e952af1d3fc53f8f78feb0bda0f Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Thu, 25 Jun 2026 19:06:54 +0800 Subject: [PATCH] chore: change analytics_type to string type from enum (#7544) --- ...26-06-19-1411-add-rybbit-analytics-type.js | 32 +++---------------- ...026-06-19-1412-analytics-type-to-string.js | 18 +++++++++++ 2 files changed, 22 insertions(+), 28 deletions(-) create mode 100644 db/knex_migrations/2026-06-19-1412-analytics-type-to-string.js diff --git a/db/knex_migrations/2026-06-19-1411-add-rybbit-analytics-type.js b/db/knex_migrations/2026-06-19-1411-add-rybbit-analytics-type.js index 345a0fc55..086cd36d7 100644 --- a/db/knex_migrations/2026-06-19-1411-add-rybbit-analytics-type.js +++ b/db/knex_migrations/2026-06-19-1411-add-rybbit-analytics-type.js @@ -1,33 +1,9 @@ -const newValues = ["google", "umami", "plausible", "matomo", "rybbit"]; -const oldValues = ["google", "umami", "plausible", "matomo"]; - -/** - * Rebuild the status_page.analytics_type enum with the given values, keeping existing data. - * The column is dropped and re-created because SQLite's .enu().alter() does not replace the old CHECK constraint. - * @param {import("knex").Knex} knex The knex instance - * @param {string[]} allowedValues Allowed analytics_type values - * @returns {Promise} - */ -async function rebuildAnalyticsType(knex, allowedValues) { - const rows = await knex("status_page").whereNotNull("analytics_type").select("id", "analytics_type"); - - await knex.schema.alterTable("status_page", (table) => { - table.dropColumn("analytics_type"); - }); - await knex.schema.alterTable("status_page", (table) => { - table.enu("analytics_type", allowedValues).defaultTo(null); - }); - - for (const row of rows) { - await knex("status_page").where("id", row.id).update({ analytics_type: row.analytics_type }); - } -} - exports.up = function (knex) { - return rebuildAnalyticsType(knex, newValues); + // Intentionally left blank - no operation + return Promise.resolve(); }; exports.down = async function (knex) { - await knex("status_page").where("analytics_type", "rybbit").update({ analytics_type: null }); - await rebuildAnalyticsType(knex, oldValues); + // Intentionally left blank - no operation + return Promise.resolve(); }; diff --git a/db/knex_migrations/2026-06-19-1412-analytics-type-to-string.js b/db/knex_migrations/2026-06-19-1412-analytics-type-to-string.js new file mode 100644 index 000000000..45b27ad44 --- /dev/null +++ b/db/knex_migrations/2026-06-19-1412-analytics-type-to-string.js @@ -0,0 +1,18 @@ +const oldValues = ["google", "umami", "plausible", "matomo", "rybbit"]; + +exports.up = function (knex) { + return knex.schema.alterTable("status_page", function (table) { + table.string("analytics_type").nullable().defaultTo(null).alter(); + }); +}; + +exports.down = async function (knex) { + await knex("status_page") + .whereNotNull("analytics_type") + .whereNotIn("analytics_type", oldValues) + .update({ analytics_type: null }); + + return knex.schema.alterTable("status_page", function (table) { + table.enu("analytics_type", oldValues).nullable().defaultTo(null).alter(); + }); +};