pg migration raw sql CREATE FUNCTION gets error: "TypeError: Cannot redefine property: then"

When I try:
await sql`
CREATE FUNCTION universal_history_trigger_function()
RETURNS trigger AS $$
BEGIN
IF TG_OP='INSERT' THEN
INSERT INTO universal_history (table_name, schema_name, operation, who_id, new_val)
VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, NEW.last_modified_by_id, row_to_json(NEW));
RETURN NEW;
ELSIF TG_OP='UPDATE' THEN
INSERT INTO universal_history (table_name, schema_name, operation, who_id, new_val, old_val)
VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, NEW.last_modified_by_id,
row_to_json(NEW), row_to_json(OLD));
RETURN NEW;
ELSIF TG_OP='DELETE' THEN
INSERT INTO universal_history (table_name, schema_name, operation, who_id, old_val)
VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, NEW.last_modified_by_id, row_to_json(OLD));
RETURN OLD;
END IF;
END;
$$ LANGUAGE plpgsql;
`.execute(db);
await sql`
CREATE FUNCTION universal_history_trigger_function()
RETURNS trigger AS $$
BEGIN
IF TG_OP='INSERT' THEN
INSERT INTO universal_history (table_name, schema_name, operation, who_id, new_val)
VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, NEW.last_modified_by_id, row_to_json(NEW));
RETURN NEW;
ELSIF TG_OP='UPDATE' THEN
INSERT INTO universal_history (table_name, schema_name, operation, who_id, new_val, old_val)
VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, NEW.last_modified_by_id,
row_to_json(NEW), row_to_json(OLD));
RETURN NEW;
ELSIF TG_OP='DELETE' THEN
INSERT INTO universal_history (table_name, schema_name, operation, who_id, old_val)
VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP, NEW.last_modified_by_id, row_to_json(OLD));
RETURN OLD;
END IF;
END;
$$ LANGUAGE plpgsql;
`.execute(db);
in my migration "up" I get "✖ Migration failed with TypeError: Cannot redefine property: then" when migrating latest. When I try the same in pgadmin it works no issue. Any ideas/suggestions?
Solution:
So took a bit of searching every possible previous issue/thread and finally stumbled across this answer from @koskimas in another thread last year: https://discord.com/channels/890118421587578920/1108366659707736154/1108386004232060938
You have two (or more) incompatible versions of Kysely and you are mixing parts of them.
In my case this somehow occurred from kysely v0.27.3 + kysely-ctl 0.8.7. Bumped to v.0.27.4 + 0.9.0 respectively fixed it....
Jump to solution
1 Reply
Solution
WhyDoThis
WhyDoThis2w ago
So took a bit of searching every possible previous issue/thread and finally stumbled across this answer from @koskimas in another thread last year: https://discord.com/channels/890118421587578920/1108366659707736154/1108386004232060938
You have two (or more) incompatible versions of Kysely and you are mixing parts of them.
In my case this somehow occurred from kysely v0.27.3 + kysely-ctl 0.8.7. Bumped to v.0.27.4 + 0.9.0 respectively fixed it.
Want results from more Discord servers?
Add your server