mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 10:58:14 +00:00
fix(migrations): use CREATE TYPE IF NOT EXISTS for invoices enum
Allows migration to run when enum already exists in prod DB. Prevents 'type already exists' error on redeployment. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,16 +15,22 @@ export class CreateInvoices1821000000002 implements MigrationInterface {
|
|||||||
name = "CreateInvoices1821000000002";
|
name = "CreateInvoices1821000000002";
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
await queryRunner.query(`
|
const typeExists = await queryRunner.query(
|
||||||
CREATE TYPE freight.invoices_status_enum AS ENUM (
|
`SELECT 1 FROM pg_type WHERE typname = 'invoices_status_enum' AND typnamespace = 'freight'::regnamespace;`,
|
||||||
'DRAFT',
|
);
|
||||||
'PENDING',
|
|
||||||
'PAID',
|
if (!typeExists.length) {
|
||||||
'OVERDUE',
|
await queryRunner.query(`
|
||||||
'CANCELLED',
|
CREATE TYPE freight.invoices_status_enum AS ENUM (
|
||||||
'REFUNDED'
|
'DRAFT',
|
||||||
);
|
'PENDING',
|
||||||
`);
|
'PAID',
|
||||||
|
'OVERDUE',
|
||||||
|
'CANCELLED',
|
||||||
|
'REFUNDED'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
await queryRunner.query(`
|
await queryRunner.query(`
|
||||||
CREATE TABLE freight.invoices (
|
CREATE TABLE freight.invoices (
|
||||||
|
|||||||
Reference in New Issue
Block a user