Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(gateways): make the direct transport migration idempotent

bernie-g51f2d7fb9d98
diff --git a/backend/src/db/migrations/20260904120000_add-direct-gateway-transport.ts b/backend/src/db/migrations/20260904120000_add-direct-gateway-transport.ts
index a405ca0c37..b265762379 100644
--- a/backend/src/db/migrations/20260904120000_add-direct-gateway-transport.ts
+++ b/backend/src/db/migrations/20260904120000_add-direct-gateway-transport.ts
@@ -3,14 +3,29 @@ import { Knex } from "knex";
import { TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> {
+ const hasDirectAddress = await knex.schema.hasColumn(TableName.GatewayV2, "directAddress");
+ const hasDirectHeartbeat = await knex.schema.hasColumn(TableName.GatewayV2, "directHeartbeat");
+
await knex.schema.alterTable(TableName.GatewayV2, (table) => {
- table.text("directAddress").nullable();
- table.timestamp("directHeartbeat", { useTz: true }).nullable();
+ if (!hasDirectAddress) {
+ table.text("directAddress").nullable();
+ }
+ if (!hasDirectHeartbeat) {
+ table.timestamp("directHeartbeat", { useTz: true }).nullable();
+ }
});
}
export async function down(knex: Knex): Promise<void> {
+ const hasDirectAddress = await knex.schema.hasColumn(TableName.GatewayV2, "directAddress");
+ const hasDirectHeartbeat = await knex.schema.hasColumn(TableName.GatewayV2, "directHeartbeat");
+
await knex.schema.alterTable(TableName.GatewayV2, (table) => {
- table.dropColumns("directAddress", "directHeartbeat");
+ if (hasDirectAddress) {
+ table.dropColumn("directAddress");
+ }
+ if (hasDirectHeartbeat) {
+ table.dropColumn("directHeartbeat");
+ }
});
}