File tree Expand file tree Collapse file tree 4 files changed +35
-2
lines changed
lib/activerecord-pg-format-db-structure/transforms
spec/activerecord-pg-format-db-structure/transforms Expand file tree Collapse file tree 4 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 1
1
## [ Unreleased]
2
2
3
+ - Remove no-op ` NOT VALID ` setting when inlining constraints
4
+
3
5
## [ 0.3.0] - 2025-03-15
4
6
5
7
- Introduce StatementAppender for better spacing between statements
Original file line number Diff line number Diff line change @@ -347,7 +347,9 @@ sequence indeed has default settings.
347
347
348
348
### InlineConstraints
349
349
350
- Inline non-foreign key constraints into table declaration
350
+ Inline non-foreign key constraints into table declaration.
351
+
352
+ Note that this also remove the ` NOT VALID ` setting if present, since that's a no-op when the constraint is created at the same time as the table.
351
353
352
354
### MoveIndicesAfterCreateTable
353
355
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ def match_alter_column_statement(raw_statement)
64
64
65
65
def add_constraint! ( raw_statement , constraint )
66
66
raw_statement . stmt . create_stmt . table_elts << PgQuery ::Node . from (
67
- PgQuery ::Constraint . new ( constraint )
67
+ PgQuery ::Constraint . new ( constraint . merge ( skip_validation : nil ) )
68
68
)
69
69
end
70
70
end
Original file line number Diff line number Diff line change 97
97
;
98
98
SQL
99
99
end
100
+
101
+ it "removes NO VALID when inlining since that's a no-op when inlined" do
102
+ formatter = ActiveRecordPgFormatDbStructure ::Formatter . new (
103
+ transforms : [ described_class ]
104
+ )
105
+
106
+ source = +<<~SQL
107
+ CREATE TABLE public.posts (
108
+ id bigint NOT NULL,
109
+ score int NOT NULL,
110
+ created_at timestamp(6) without time zone NOT NULL,
111
+ updated_at timestamp(6) without time zone NOT NULL
112
+ );
113
+
114
+ ALTER TABLE ONLY public.posts ADD CONSTRAINT postive_score CHECK (score > 0) NOT VALID;
115
+ SQL
116
+
117
+ expect ( formatter . format ( source ) ) . to eq ( <<~SQL )
118
+ -- Name: posts; Type: TABLE;
119
+
120
+ CREATE TABLE public.posts (
121
+ id bigint NOT NULL,
122
+ score int NOT NULL,
123
+ created_at timestamp(6) NOT NULL,
124
+ updated_at timestamp(6) NOT NULL,
125
+ CONSTRAINT postive_score CHECK (score > 0)
126
+ );
127
+ SQL
128
+ end
100
129
end
101
130
end
You can’t perform that action at this time.
0 commit comments