node-pg-migrate icon indicating copy to clipboard operation
node-pg-migrate copied to clipboard

Adding a comment to `addConstraint` for a table in a schema fails

Open osdiab opened this issue 10 months ago • 1 comments

This command:

  pgm.addConstraint({schema: "payroll_reports", name: "upload_headers"}, "chk_only_one_header_type", {
    check: [
      `(
      CASE WHEN paycode_type IS NOT NULL THEN 1 ELSE 0 END +
      CASE WHEN aggregate_paycode_type IS NOT NULL THEN 1 ELSE 0 END +
      CASE WHEN meta_field_type IS NOT NULL THEN 1 ELSE 0 END +
      CASE WHEN is_remark THEN 1 ELSE 0 END
     ) <= 1`,
    ],
    comment:
      "If no type present/truthy, it's ignored; cannot have more than one active at once",
  });

fails with this error:

Error executing:
ALTER TABLE "payroll_reports"."upload_headers"
  ADD CONSTRAINT "chk_only_one_header_type" CHECK ((       CASE WHEN paycode_type IS NOT NULL THEN 1 ELSE 0 END +       CASE WHEN aggregate_paycode_type IS NOT NULL THEN 1 ELSE 0 END +       CASE WHEN meta_field_type IS NOT NULL THEN 1 ELSE 0 END +       CASE WHEN is_remark THEN 1 ELSE 0 END      ) <= 1);
COMMENT ON CONSTRAINT "chk_only_one_header_type" ON "upload_headers" IS $pga$If no type present/truthy, it's ignored; cannot have more than one active at once$pga$;
error: relation "upload_headers" does not exist

> Rolling back attempted migration ...
error: relation "upload_headers" does not exist

This doesn't fail when you remove the comment field. Looks like it's failing to prepend the schema name when applying the comment.

osdiab avatar Aug 24 '23 02:08 osdiab