Skip to content

Commit 929ea27

Browse files
authored
Always surround up and down clauses in parentheses (#481)
Closes #473
1 parent 7bc6eb8 commit 929ea27

21 files changed

+251
-76
lines changed

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ Here is the `pgroll` migration that will perform the migration to make the `desc
265265
"table": "users",
266266
"column": "description",
267267
"nullable": false,
268-
"up": "(SELECT CASE WHEN description IS NULL THEN 'description for ' || name ELSE description END)",
268+
"up": "SELECT CASE WHEN description IS NULL THEN 'description for ' || name ELSE description END",
269269
"down": "description"
270270
}
271271
}
@@ -307,7 +307,7 @@ You should see something like this:
307307
`pgroll` has added a `_pgroll_new_description` field to the table and populated the field for all rows using the `up` SQL from the `02_user_description_set_nullable.json` file:
308308

309309
```json
310-
"up": "(SELECT CASE WHEN description IS NULL THEN 'description for ' || name ELSE description END)",
310+
"up": "SELECT CASE WHEN description IS NULL THEN 'description for ' || name ELSE description END",
311311
```
312312

313313
This has copied over all `description` values into the `_pgroll_new_description` field, rewriting any `NULL` values using the provided SQL.

examples/16_set_nullable.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"table": "reviews",
77
"column": "review",
88
"nullable": false,
9-
"up": "(SELECT CASE WHEN review IS NULL THEN product || ' is good' ELSE review END)",
9+
"up": "SELECT CASE WHEN review IS NULL THEN product || ' is good' ELSE review END",
1010
"down": "review"
1111
}
1212
}

examples/21_add_foreign_key_constraint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"column": "id",
1212
"on_delete": "CASCADE"
1313
},
14-
"up": "(SELECT CASE WHEN EXISTS (SELECT 1 FROM users WHERE users.id = user_id) THEN user_id ELSE NULL END)",
14+
"up": "SELECT CASE WHEN EXISTS (SELECT 1 FROM users WHERE users.id = user_id) THEN user_id ELSE NULL END",
1515
"down": "user_id"
1616
}
1717
}

examples/22_add_check_constraint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"name": "title_length",
1010
"constraint": "length(title) > 3"
1111
},
12-
"up": "(SELECT CASE WHEN length(title) <= 3 THEN LPAD(title, 4, '-') ELSE title END)",
12+
"up": "SELECT CASE WHEN length(title) <= 3 THEN LPAD(title, 4, '-') ELSE title END",
1313
"down": "title"
1414
}
1515
}

examples/23_drop_check_constraint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"table": "posts",
77
"name": "title_length",
88
"up": "title",
9-
"down": "(SELECT CASE WHEN length(title) <= 3 THEN LPAD(title, 4, '-') ELSE title END)"
9+
"down": "SELECT CASE WHEN length(title) <= 3 THEN LPAD(title, 4, '-') ELSE title END"
1010
}
1111
}
1212
]

examples/24_drop_foreign_key_constraint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"table": "posts",
77
"name": "fk_users_id",
88
"up": "user_id",
9-
"down": "(SELECT CASE WHEN EXISTS (SELECT 1 FROM users WHERE users.id = user_id) THEN user_id ELSE NULL END)"
9+
"down": "SELECT CASE WHEN EXISTS (SELECT 1 FROM users WHERE users.id = user_id) THEN user_id ELSE NULL END"
1010
}
1111
}
1212
]

examples/31_unset_not_null.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"column": "title",
88
"nullable": true,
99
"up": "title",
10-
"down": "(SELECT CASE WHEN title IS NULL THEN 'placeholder title' ELSE title END)"
10+
"down": "SELECT CASE WHEN title IS NULL THEN 'placeholder title' ELSE title END"
1111
}
1212
}
1313
]

examples/35_alter_column_multiple.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"name": "event_name_length",
1818
"constraint": "length(name) > 3"
1919
},
20-
"up": "(SELECT CASE WHEN name IS NULL OR LENGTH(name) <= 3 THEN 'placeholder' ELSE name END)",
20+
"up": "SELECT CASE WHEN name IS NULL OR LENGTH(name) <= 3 THEN 'placeholder' ELSE name END",
2121
"down": "event_name"
2222
}
2323
}

examples/45_add_table_check_constraint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"check": "sellers_name = 'alice' OR sellers_zip > 0",
1414
"up": {
1515
"sellers_name": "sellers_name",
16-
"sellers_zip": "(SELECT CASE WHEN sellers_name != 'alice' AND sellers_zip <= 0 THEN 123 WHEN sellers_name != 'alice' THEN sellers_zip ELSE sellers_zip END)"
16+
"sellers_zip": "SELECT CASE WHEN sellers_name != 'alice' AND sellers_zip <= 0 THEN 123 WHEN sellers_name != 'alice' THEN sellers_zip ELSE sellers_zip END"
1717
},
1818
"down": {
1919
"sellers_name": "sellers_name",

internal/benchmarks/benchmarks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ var migAlterColumn = migrations.Migration{
256256
&migrations.OpAlterColumn{
257257
Table: "users",
258258
Column: "name",
259-
Up: "(SELECT CASE WHEN name IS NULL THEN 'placeholder' ELSE name END)",
259+
Up: "SELECT CASE WHEN name IS NULL THEN 'placeholder' ELSE name END",
260260
Down: "user_name",
261261
Comment: nullable.NewNullableWithValue("the name of the user"),
262262
Nullable: ptr(false),

0 commit comments

Comments
 (0)