fix: renamed migration

This commit is contained in:
Daniel Hougaard
2024-11-11 21:45:05 +04:00
parent f096a567de
commit cfc0b2fb8d
@@ -3,21 +3,21 @@ import { Knex } from "knex";
import { TableName } from "../schemas"; import { TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> { export async function up(knex: Knex): Promise<void> {
const hasIsEncryptedByHsmCol = await knex.schema.hasColumn(TableName.KmsServerRootConfig, "isEncryptedByHsm"); const hasEncryptionStrategy = await knex.schema.hasColumn(TableName.KmsServerRootConfig, "encryptionStrategy");
const hasTimestampsCol = await knex.schema.hasColumn(TableName.KmsServerRootConfig, "createdAt"); const hasTimestampsCol = await knex.schema.hasColumn(TableName.KmsServerRootConfig, "createdAt");
await knex.schema.alterTable(TableName.KmsServerRootConfig, (t) => { await knex.schema.alterTable(TableName.KmsServerRootConfig, (t) => {
if (!hasIsEncryptedByHsmCol) t.boolean("isEncryptedByHsm").defaultTo(false).notNullable(); if (!hasEncryptionStrategy) t.string("encryptionStrategy").defaultTo("BASIC");
if (!hasTimestampsCol) t.timestamps(true, true); if (!hasTimestampsCol) t.timestamps(true, true, true);
}); });
} }
export async function down(knex: Knex): Promise<void> { export async function down(knex: Knex): Promise<void> {
const hasIsEncryptedByHsmCol = await knex.schema.hasColumn(TableName.KmsServerRootConfig, "isEncryptedByHsm"); const hasEncryptionStrategy = await knex.schema.hasColumn(TableName.KmsServerRootConfig, "encryptionStrategy");
const hasTimestampsCol = await knex.schema.hasColumn(TableName.KmsServerRootConfig, "createdAt"); const hasTimestampsCol = await knex.schema.hasColumn(TableName.KmsServerRootConfig, "createdAt");
await knex.schema.alterTable(TableName.KmsServerRootConfig, (t) => { await knex.schema.alterTable(TableName.KmsServerRootConfig, (t) => {
if (hasIsEncryptedByHsmCol) t.dropColumn("isEncryptedByHsm"); if (hasEncryptionStrategy) t.dropColumn("encryptionStrategy");
if (hasTimestampsCol) t.dropTimestamps(true); if (hasTimestampsCol) t.dropTimestamps(true);
}); });
} }