Skip to content

Commit fe9d1df

Browse files
committed
Update fk migration
1 parent 68d322e commit fe9d1df

File tree

1 file changed

+0
-46
lines changed

1 file changed

+0
-46
lines changed

containers/ecr-viewer/src/app/api/migrate-db/migrations/core/20250430160000_condition_fk.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,6 @@ export async function up(db: Kysely<AnyDb>): Promise<void> {
2525
cb.references("condition_reference.code"),
2626
)
2727
.execute();
28-
29-
if (dbDialect() === "postgres") {
30-
await sql`
31-
CREATE OR REPLACE FUNCTION set_condition_code()
32-
RETURNS TRIGGER AS $$
33-
BEGIN
34-
IF NEW.condition_code IS NULL THEN
35-
SELECT code INTO NEW.condition_code
36-
FROM ${sql.raw(schema)}.condition_reference
37-
WHERE condition_reference.condition_name = NEW.condition
38-
LIMIT 1;
39-
END IF;
40-
RETURN NEW;
41-
END;
42-
$$ LANGUAGE plpgsql;
43-
`.execute(_db);
44-
45-
await sql`
46-
CREATE TRIGGER trg_set_condition_code
47-
BEFORE INSERT ON ${sql.raw(schema)}.ecr_rr_conditions
48-
FOR EACH ROW
49-
EXECUTE FUNCTION set_condition_code();
50-
`.execute(_db);
51-
} else if (dbDialect() === "sqlserver") {
52-
await sql`
53-
CREATE TRIGGER trg_set_condition_code
54-
ON [${sql.raw(schema)}].[ecr_rr_conditions]
55-
INSTEAD OF INSERT
56-
AS
57-
BEGIN
58-
INSERT INTO [${sql.raw(
59-
schema,
60-
)}].[ecr_rr_conditions] (uuid, eicr_id, condition, condition_code)
61-
SELECT
62-
i.uuid,
63-
i.eicr_id,
64-
i.condition,
65-
COALESCE(i.condition_code, cr.code)
66-
FROM inserted i
67-
LEFT JOIN [${sql.raw(schema)}].[condition_reference] cr
68-
ON cr.condition_name = i.condition;
69-
END;
70-
`.execute(_db);
71-
} else {
72-
throw new Error("Unsupported database dialect for trigger creation.");
73-
}
7428
}
7529

7630
/**

0 commit comments

Comments
 (0)