diff --git a/__fixtures__/misc.sql b/__fixtures__/misc.sql index 05cd1e69..8519e76b 100644 --- a/__fixtures__/misc.sql +++ b/__fixtures__/misc.sql @@ -19,4 +19,6 @@ create table if not exists users ( handle text not null, created_at timestamp not null default now(), updated_at timestamp not null default now() -) \ No newline at end of file +); + +CREATE INDEX CONCURRENTLY IF NOT EXISTS index_email_logs_on_created_at ON public.email_logs USING btree (created_at DESC); \ No newline at end of file diff --git a/packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap b/packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap index c6550a86..c35126da 100644 --- a/packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap +++ b/packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap @@ -246734,7 +246734,7 @@ exports[`misc 15`] = ` ], }, }, - "stmt_len": undefined, + "stmt_len": 238, "stmt_location": 629, }, } @@ -246747,9 +246747,44 @@ name text NOT NULL, handle text NOT NULL, created_at timestamp NOT NULL DEFAULT ( now() ), updated_at timestamp NOT NULL DEFAULT ( now() ) -)" +);" `; +exports[`misc 17`] = ` +{ + "RawStmt": { + "stmt": { + "IndexStmt": { + "accessMethod": "btree", + "concurrent": true, + "idxname": "index_email_logs_on_created_at", + "if_not_exists": true, + "indexParams": [ + { + "IndexElem": { + "name": "created_at", + "nulls_ordering": "SORTBY_NULLS_DEFAULT", + "ordering": "SORTBY_DESC", + }, + }, + ], + "relation": { + "inh": true, + "location": 944, + "relname": "email_logs", + "relpersistence": "p", + "schemaname": "public", + }, + }, + }, + "stmt_len": 123, + "stmt_location": 868, + }, +} +`; + +exports[`misc 18`] = `"CREATE INDEX CONCURRENTLY IF NOT EXISTS index_email_logs_on_created_at ON public.email_logs ( created_at DESC );"`; + exports[`parens 1`] = ` { "RawStmt": { diff --git a/packages/deparser/src/deparser.ts b/packages/deparser/src/deparser.ts index 221112f6..b4f4e52d 100644 --- a/packages/deparser/src/deparser.ts +++ b/packages/deparser/src/deparser.ts @@ -1510,6 +1510,9 @@ export default class Deparser { if (node.concurrent) { output.push('CONCURRENTLY'); } + if (node.if_not_exists) { + output.push('IF NOT EXISTS'); + } if (node.idxname) { output.push(node.idxname);