mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
fix(backend): ensure idempotent migration
This commit is contained in:
@@ -2,14 +2,22 @@ import { Knex } from "knex";
|
|||||||
|
|
||||||
import { EnforcementLevel } from "@app/lib/types";
|
import { EnforcementLevel } from "@app/lib/types";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
export async function up(knex: Knex): Promise<void> {
|
||||||
await knex.schema.table("secret_approval_policies", (table) => {
|
const hasColumn = await knex.schema.hasColumn(TableName.SecretApprovalPolicy, "enforcementLevel");
|
||||||
table.specificType("enforcementLevel", "VARCHAR(10)").notNullable().defaultTo(EnforcementLevel.Hard);
|
if (!hasColumn) {
|
||||||
});
|
await knex.schema.table(TableName.SecretApprovalPolicy, (table) => {
|
||||||
|
table.string("enforcementLevel", 10).notNullable().defaultTo(EnforcementLevel.Hard);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
export async function down(knex: Knex): Promise<void> {
|
||||||
await knex.schema.table("secret_approval_policies", (table) => {
|
const hasColumn = await knex.schema.hasColumn(TableName.SecretApprovalPolicy, "enforcementLevel");
|
||||||
table.dropColumn("enforcementLevel");
|
if (hasColumn) {
|
||||||
});
|
await knex.schema.table(TableName.SecretApprovalPolicy, (table) => {
|
||||||
|
table.dropColumn("enforcementLevel");
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,22 @@ import { Knex } from "knex";
|
|||||||
|
|
||||||
import { EnforcementLevel } from "@app/lib/types";
|
import { EnforcementLevel } from "@app/lib/types";
|
||||||
|
|
||||||
|
import { TableName } from "../schemas";
|
||||||
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
export async function up(knex: Knex): Promise<void> {
|
||||||
await knex.schema.table("access_approval_policies", (table) => {
|
const hasColumn = await knex.schema.hasColumn(TableName.AccessApprovalPolicy, "enforcementLevel");
|
||||||
table.specificType("enforcementLevel", "VARCHAR(10)").notNullable().defaultTo(EnforcementLevel.Hard);
|
if (!hasColumn) {
|
||||||
});
|
await knex.schema.table(TableName.AccessApprovalPolicy, (table) => {
|
||||||
|
table.string("enforcementLevel", 10).notNullable().defaultTo(EnforcementLevel.Hard);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
export async function down(knex: Knex): Promise<void> {
|
||||||
await knex.schema.table("access_approval_policies", (table) => {
|
const hasColumn = await knex.schema.hasColumn(TableName.AccessApprovalPolicy, "enforcementLevel");
|
||||||
table.dropColumn("enforcementLevel");
|
if (hasColumn) {
|
||||||
});
|
await knex.schema.table(TableName.AccessApprovalPolicy, (table) => {
|
||||||
|
table.dropColumn("enforcementLevel");
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user