Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a comment to addConstraint for a table in a schema fails #939

Closed
osdiab opened this issue Aug 24, 2023 · 1 comment · Fixed by #1139
Closed

Adding a comment to addConstraint for a table in a schema fails #939

osdiab opened this issue Aug 24, 2023 · 1 comment · Fixed by #1139
Assignees
Labels
c: bug Something isn't working p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Milestone

Comments

@osdiab
Copy link
Collaborator

osdiab commented Aug 24, 2023

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
Copy link
Collaborator Author

osdiab commented Aug 24, 2023

this probably is happenign because the relevant constraint function first strips out the name and then passes that directly to the makeComment() function:

const tableName = typeof table === 'object' ? table.name : table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
2 participants