fix: analytics_type's enum check was not removed, even the data type changed to string on SQLite (#7729)

This commit is contained in:
Louis Lam
2026-08-18 16:58:26 +08:00
committed by GitHub
parent b980621689
commit 7598afbef8
@@ -0,0 +1,46 @@
// Fix #7727, force recreate analytics_type the column on SQLite to remove the enum check
// Because alter to string won't remove the enum the check (so stupid....)
exports.up = async function (knex) {
if (knex.client.dialect === "sqlite3") {
// Save all analytics_type to memory
const rows = await knex("status_page").select("id", "analytics_type");
await knex.schema.alterTable("status_page", function (table) {
table.dropColumn("analytics_type");
});
await knex.schema.alterTable("status_page", function (table) {
table.string("analytics_type").nullable().defaultTo(null);
});
for (const row of rows) {
if (row.analytics_type !== null) {
await knex("status_page").where({ id: row.id }).update({ analytics_type: row.analytics_type });
}
}
}
};
exports.down = async function (knex) {
if (knex.client.dialect === "sqlite3") {
const rows = await knex("status_page").select("id", "analytics_type");
await knex.schema.alterTable("status_page", function (table) {
table.dropColumn("analytics_type");
});
await knex.schema.alterTable("status_page", function (table) {
table
.enu("analytics_type", ["google", "umami", "plausible", "matomo", "rybbit"])
.nullable()
.defaultTo(null);
});
for (const row of rows) {
if (row.analytics_type !== null) {
await knex("status_page").where({ id: row.id }).update({ analytics_type: row.analytics_type });
}
}
}
};