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

Multi-line check constraints incorrectly have commas after each line when reordering structure files #19

Open
aristocrates opened this issue Aug 31, 2023 · 0 comments

Comments

@aristocrates
Copy link

Multi-line check constraints incorrectly have commas after each line when reordering structure files.

Example:

SCHEMA_FILENAME = 'table_schema_for_repro.sql'

PgColumnBytePacker::PgDump.sort_columns_for_definition_file(
  SCHEMA_FILENAME,
  connection: ActiveRecord::Base.connection,
)
CREATE TABLE public.bug_repro_values (
    id bigint NOT NULL,
    condition_category text NOT NULL,
    condition_value integer NOT NULL
    CONSTRAINT contrived_condition_check CHECK (
CASE
    WHEN (condition_category = 'must_be_positive') THEN (condition_value > 0)
    WHEN (condition_category = 'must_be_negative') THEN (condition_value < 0)
    ELSE true
END)
);

The following diff occurs, which correctly reorders condition_value integer and condition_category text, but incorrectly adds commas to the end of all the check constraint lines:

--- table_schema_for_repro.sql	2023-08-31 04:44:55.438589724 +0000
+++ table_schema_for_repro_copy.sql	2023-08-31 04:53:12.714570483 +0000
@@ -1,11 +1,11 @@
 CREATE TABLE public.bug_repro_values (
     id bigint NOT NULL,
+    condition_value integer NOT NULL,
     condition_category text NOT NULL,
-    condition_value integer NOT NULL
-    CONSTRAINT contrived_condition_check CHECK (
-CASE
-    WHEN (condition_category = 'must_be_positive') THEN (condition_value > 0)
-    WHEN (condition_category = 'must_be_negative') THEN (condition_value < 0)
-    ELSE true
+    CONSTRAINT contrived_condition_check CHECK (,
+CASE,
+    WHEN (condition_category = 'must_be_positive') THEN (condition_value > 0),
+    WHEN (condition_category = 'must_be_negative') THEN (condition_value < 0),
+    ELSE true,
 END)
 );

Full repro Dockerfile and supporting files: https://github.com/aristocrates/pg_column_byte_packer_comma_bug_repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant