Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __fixtures__/generated/generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -21372,6 +21372,8 @@
"misc/issues-18.sql": "SELECT (- (-10 - -12))::numeric AS delta",
"misc/issues-19.sql": "SELECT (- (a.actual_eur - a.budget_eur))::numeric AS delta_eur FROM accounts a",
"misc/issues-20.sql": "CREATE TABLE test_exclude_where (\n id uuid PRIMARY KEY,\n database_id uuid NOT NULL,\n status text NOT NULL DEFAULT 'pending',\n EXCLUDE USING btree (database_id WITH =)\n WHERE (status = 'pending')\n)",
"misc/issues-21.sql": "CREATE TABLE test_named_exclude (\n id uuid PRIMARY KEY,\n database_id uuid NOT NULL,\n status text NOT NULL DEFAULT 'pending',\n CONSTRAINT one_pending_per_database\n EXCLUDE USING btree (database_id WITH =)\n WHERE (status = 'pending')\n)",
"misc/issues-22.sql": "ALTER TABLE test_named_exclude ADD CONSTRAINT no_overlap EXCLUDE USING gist (room WITH =, during WITH &&)",
"misc/inflection-1.sql": "CREATE SCHEMA inflection",
"misc/inflection-2.sql": "GRANT USAGE ON SCHEMA inflection TO PUBLIC",
"misc/inflection-3.sql": "ALTER DEFAULT PRIVILEGES IN SCHEMA inflection \n GRANT EXECUTE ON FUNCTIONS TO PUBLIC",
Expand Down
11 changes: 11 additions & 0 deletions __fixtures__/kitchen-sink/misc/issues.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,14 @@ CREATE TABLE test_exclude_where (
EXCLUDE USING btree (database_id WITH =)
WHERE (status = 'pending')
);

-- Named EXCLUDE constraint: the deparser dropped `CONSTRAINT <name>` for CONSTR_EXCLUSION
CREATE TABLE test_named_exclude (
id uuid PRIMARY KEY,
database_id uuid NOT NULL,
status text NOT NULL DEFAULT 'pending',
CONSTRAINT one_pending_per_database
EXCLUDE USING btree (database_id WITH =)
WHERE (status = 'pending')
);
ALTER TABLE test_named_exclude ADD CONSTRAINT no_overlap EXCLUDE USING gist (room WITH =, during WITH &&);
4 changes: 3 additions & 1 deletion packages/deparser/__tests__/kitchen-sink/misc-issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ it('misc-issues', async () => {
"misc/issues-17.sql",
"misc/issues-18.sql",
"misc/issues-19.sql",
"misc/issues-20.sql"
"misc/issues-20.sql",
"misc/issues-21.sql",
"misc/issues-22.sql"
]);
});
2 changes: 1 addition & 1 deletion packages/deparser/src/deparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2807,7 +2807,7 @@ export class Deparser implements DeparserVisitor {
const output: string[] = [];

// Handle constraint name if present
if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN' || node.contype === 'CONSTR_NOTNULL')) {
if (node.conname && (node.contype === 'CONSTR_CHECK' || node.contype === 'CONSTR_UNIQUE' || node.contype === 'CONSTR_PRIMARY' || node.contype === 'CONSTR_FOREIGN' || node.contype === 'CONSTR_NOTNULL' || node.contype === 'CONSTR_EXCLUSION')) {
output.push('CONSTRAINT');
output.push(QuoteUtils.quoteIdentifier(node.conname));
}
Expand Down
Loading