mirror of
https://github.com/louislam/uptime-kuma.git
synced 2026-06-27 14:25:49 +00:00
chore: change analytics_type to string type from enum (#7544)
This commit is contained in:
@@ -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<void>}
|
||||
*/
|
||||
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();
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user