From d1465199d83d75d924a0ce4f57363e23b1f53b41 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 17:53:06 +0000 Subject: [PATCH] Simplify fix migration as requested in code review Co-authored-by: CommanderStorm <26258709+CommanderStorm@users.noreply.github.com> --- ...1-06-0000-fix-domain-expiry-column-type.js | 75 +++---------------- 1 file changed, 10 insertions(+), 65 deletions(-) diff --git a/db/knex_migrations/2026-01-06-0000-fix-domain-expiry-column-type.js b/db/knex_migrations/2026-01-06-0000-fix-domain-expiry-column-type.js index 6f0dea28d..6728c5fb8 100644 --- a/db/knex_migrations/2026-01-06-0000-fix-domain-expiry-column-type.js +++ b/db/knex_migrations/2026-01-06-0000-fix-domain-expiry-column-type.js @@ -1,69 +1,14 @@ -// Fix domain column type from TEXT to VARCHAR(255) for MySQL/MariaDB compatibility -// TEXT columns cannot have UNIQUE constraints in MySQL 8.0 and older MariaDB versions -// Maximum domain name length is 253 characters (255 octets on the wire) -exports.up = async function (knex) { - const isSQLite = knex.client.dialect === "sqlite3"; - - if (isSQLite) { - // For SQLite, we need to recreate the table since ALTER COLUMN is limited - // Check if the column type needs to be changed by checking if it's currently TEXT - const tableInfo = await knex.raw("PRAGMA table_info('domain_expiry')"); - const domainColumn = tableInfo.find(col => col.name === "domain"); - - if (domainColumn && domainColumn.type.toUpperCase() === "TEXT") { - // Create new table with correct column type - await knex.schema.createTable("domain_expiry_new", (table) => { - table.increments("id"); - table.datetime("last_check"); - table.string("domain", 255).unique().notNullable(); - table.datetime("expiry"); - table.integer("last_expiry_notification_sent").defaultTo(null); - }); - - // Copy data from old table to new table - await knex.raw(` - INSERT INTO domain_expiry_new (id, last_check, domain, expiry, last_expiry_notification_sent) - SELECT id, last_check, domain, expiry, last_expiry_notification_sent - FROM domain_expiry - `); - - // Drop old table and rename new table - await knex.schema.dropTable("domain_expiry"); - await knex.schema.renameTable("domain_expiry_new", "domain_expiry"); - } - } else { - // For MySQL/MariaDB - // Check if column is TEXT type and alter to VARCHAR(255) if needed - const dbName = knex.client.config.connection.database; - const columnInfo = await knex.raw(` - SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_SCHEMA = ? AND TABLE_NAME = 'domain_expiry' AND COLUMN_NAME = 'domain' - `, [ dbName ]); - - const dataType = columnInfo[0]?.[0]?.DATA_TYPE?.toUpperCase(); - - if (dataType === "TEXT") { - // Drop the unique constraint first (if it exists) - try { - await knex.raw("ALTER TABLE domain_expiry DROP INDEX domain_expiry_domain_unique"); - } catch (e) { - // Index might not exist, ignore error - } - - // Alter column type to VARCHAR(255) - await knex.schema.alterTable("domain_expiry", function (table) { - table.string("domain", 255).notNullable().alter(); - }); - - // Re-add unique constraint - await knex.schema.alterTable("domain_expiry", function (table) { - table.unique("domain"); - }); - } - } +// Ensure domain column is VARCHAR(255) across all database types. +// This migration ensures MySQL, SQLite, and MariaDB have consistent column type, +// even if a user installed 2.1.0-beta.0 or 2.1.0-beta.1 which had TEXT type for this column. +// Maximum domain name length is 253 characters (255 octets on the wire). +// Note: The unique constraint is already present from the original migration. +exports.up = function (knex) { + return knex.schema.alterTable("domain_expiry", function (table) { + table.string("domain", 255).notNullable().alter(); + }); }; -exports.down = async function (knex) { +exports.down = function (knex) { // No rollback needed - keeping VARCHAR(255) is the correct state - // Rolling back to TEXT would cause issues with unique constraints };