Skip to content

Commit

Permalink
Merge pull request #2738 from Infisical/fix-cert-migration
Browse files Browse the repository at this point in the history
Fix ca version migration
  • Loading branch information
maidul98 authored Nov 15, 2024
2 parents d0c5096 + d6e1ed4 commit 796f76d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions backend/src/db/migrations/20240802181855_ca-cert-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,25 @@ export async function up(knex: Knex): Promise<void> {
}

if (await knex.schema.hasTable(TableName.Certificate)) {
await knex.schema.alterTable(TableName.Certificate, (t) => {
t.uuid("caCertId").nullable();
t.foreign("caCertId").references("id").inTable(TableName.CertificateAuthorityCert);
});
const hasCaCertIdColumn = await knex.schema.hasColumn(TableName.Certificate, "caCertId");
if (!hasCaCertIdColumn) {
await knex.schema.alterTable(TableName.Certificate, (t) => {
t.uuid("caCertId").nullable();
t.foreign("caCertId").references("id").inTable(TableName.CertificateAuthorityCert);
});

await knex.raw(`
await knex.raw(`
UPDATE "${TableName.Certificate}" cert
SET "caCertId" = (
SELECT caCert.id
FROM "${TableName.CertificateAuthorityCert}" caCert
WHERE caCert."caId" = cert."caId"
)
`);
)`);

await knex.schema.alterTable(TableName.Certificate, (t) => {
t.uuid("caCertId").notNullable().alter();
});
await knex.schema.alterTable(TableName.Certificate, (t) => {
t.uuid("caCertId").notNullable().alter();
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ volumes:
driver: local

networks:
infisical:
infisical:

0 comments on commit 796f76d

Please sign in to comment.