Update migration

This commit is contained in:
x032205
2025-09-05 13:16:18 -04:00
parent 17b6ab0db0
commit 3a75a50d0b
@@ -24,6 +24,7 @@ export async function up(knex: Knex): Promise<void> {
t.string("url").nullable().alter(); t.string("url").nullable().alter();
}); });
if (!hasEncryptedCredentials) {
const superAdminDAL = superAdminDALFactory(knex); const superAdminDAL = superAdminDALFactory(knex);
const envConfig = await getMigrationEnvConfig(superAdminDAL); const envConfig = await getMigrationEnvConfig(superAdminDAL);
const keyStore = inMemoryKeyStore(); const keyStore = inMemoryKeyStore();
@@ -116,6 +117,7 @@ export async function up(knex: Knex): Promise<void> {
}); });
} }
} }
}
// IMPORTANT: The down migration does not utilize the existing "url" and encrypted header columns // IMPORTANT: The down migration does not utilize the existing "url" and encrypted header columns
// because we're taking the latest data from the credentials column and re-encrypting it into relevant columns // because we're taking the latest data from the credentials column and re-encrypting it into relevant columns
@@ -125,6 +127,10 @@ export async function up(knex: Knex): Promise<void> {
export async function down(knex: Knex): Promise<void> { export async function down(knex: Knex): Promise<void> {
if (await knex.schema.hasTable(TableName.AuditLogStream)) { if (await knex.schema.hasTable(TableName.AuditLogStream)) {
const hasProvider = await knex.schema.hasColumn(TableName.AuditLogStream, "provider");
const hasEncryptedCredentials = await knex.schema.hasColumn(TableName.AuditLogStream, "encryptedCredentials");
if (hasEncryptedCredentials) {
const superAdminDAL = superAdminDALFactory(knex); const superAdminDAL = superAdminDALFactory(knex);
const envConfig = await getMigrationEnvConfig(superAdminDAL); const envConfig = await getMigrationEnvConfig(superAdminDAL);
const keyStore = inMemoryKeyStore(); const keyStore = inMemoryKeyStore();
@@ -203,12 +209,13 @@ export async function down(knex: Knex): Promise<void> {
void qb.whereNot("provider", "custom").orWhereNull("url"); void qb.whereNot("provider", "custom").orWhereNull("url");
}) })
.del(); .del();
}
await knex.schema.alterTable(TableName.AuditLogStream, (t) => { await knex.schema.alterTable(TableName.AuditLogStream, (t) => {
t.string("url").notNullable().alter(); t.string("url").notNullable().alter();
t.dropColumn("provider"); if (hasProvider) t.dropColumn("provider");
t.dropColumn("encryptedCredentials"); if (hasEncryptedCredentials) t.dropColumn("encryptedCredentials");
}); });
} }
} }