Skip to content

Commit 6d78dbe

Browse files
committed
fix: support concurrently in DROP INDEX
The `concurrently` flag was previously ignored in drop index statements.
1 parent f1df82e commit 6d78dbe

File tree

4 files changed

+626
-3
lines changed

4 files changed

+626
-3
lines changed

__fixtures__/drops.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ DROP DOMAIN IF EXISTS no_such_schema.foo;
8181
DROP FOREIGN TABLE IF EXISTS no_such_schema.foo;
8282

8383
DROP INDEX IF EXISTS no_such_schema.foo;
84+
DROP INDEX my_index;
85+
DROP INDEX CONCURRENTLY my_index;
86+
DROP INDEX IF EXISTS my_index;
87+
DROP INDEX CONCURRENTLY IF EXISTS my_index;
88+
DROP INDEX schema.my_index;
89+
DROP INDEX CONCURRENTLY schema.my_index;
90+
DROP INDEX CONCURRENTLY IF EXISTS schema.my_index;
91+
DROP INDEX my_index CASCADE;
92+
DROP INDEX CONCURRENTLY my_index CASCADE;
93+
DROP INDEX CONCURRENTLY IF EXISTS my_index CASCADE;
8494
DROP MATERIALIZED VIEW IF EXISTS no_such_schema.foo;
8595

8696
-- DROP OPERATOR IF EXISTS no_such_schema.+ (int, int);

packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap

Lines changed: 327 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8431,6 +8431,331 @@ exports[`drops 113`] = `
84318431
exports[`drops 114`] = `"DROP INDEX IF EXISTS no_such_schema.foo;"`;
84328432

84338433
exports[`drops 115`] = `
8434+
{
8435+
"RawStmt": {
8436+
"stmt": {
8437+
"DropStmt": {
8438+
"behavior": "DROP_RESTRICT",
8439+
"objects": [
8440+
{
8441+
"List": {
8442+
"items": [
8443+
{
8444+
"String": {
8445+
"str": "my_index",
8446+
},
8447+
},
8448+
],
8449+
},
8450+
},
8451+
],
8452+
"removeType": "OBJECT_INDEX",
8453+
},
8454+
},
8455+
"stmt_len": 20,
8456+
"stmt_location": 2764,
8457+
},
8458+
}
8459+
`;
8460+
8461+
exports[`drops 116`] = `"DROP INDEX my_index;"`;
8462+
8463+
exports[`drops 117`] = `
8464+
{
8465+
"RawStmt": {
8466+
"stmt": {
8467+
"DropStmt": {
8468+
"behavior": "DROP_RESTRICT",
8469+
"concurrent": true,
8470+
"objects": [
8471+
{
8472+
"List": {
8473+
"items": [
8474+
{
8475+
"String": {
8476+
"str": "my_index",
8477+
},
8478+
},
8479+
],
8480+
},
8481+
},
8482+
],
8483+
"removeType": "OBJECT_INDEX",
8484+
},
8485+
},
8486+
"stmt_len": 33,
8487+
"stmt_location": 2785,
8488+
},
8489+
}
8490+
`;
8491+
8492+
exports[`drops 118`] = `"DROP INDEX CONCURRENTLY my_index;"`;
8493+
8494+
exports[`drops 119`] = `
8495+
{
8496+
"RawStmt": {
8497+
"stmt": {
8498+
"DropStmt": {
8499+
"behavior": "DROP_RESTRICT",
8500+
"missing_ok": true,
8501+
"objects": [
8502+
{
8503+
"List": {
8504+
"items": [
8505+
{
8506+
"String": {
8507+
"str": "my_index",
8508+
},
8509+
},
8510+
],
8511+
},
8512+
},
8513+
],
8514+
"removeType": "OBJECT_INDEX",
8515+
},
8516+
},
8517+
"stmt_len": 30,
8518+
"stmt_location": 2819,
8519+
},
8520+
}
8521+
`;
8522+
8523+
exports[`drops 120`] = `"DROP INDEX IF EXISTS my_index;"`;
8524+
8525+
exports[`drops 121`] = `
8526+
{
8527+
"RawStmt": {
8528+
"stmt": {
8529+
"DropStmt": {
8530+
"behavior": "DROP_RESTRICT",
8531+
"concurrent": true,
8532+
"missing_ok": true,
8533+
"objects": [
8534+
{
8535+
"List": {
8536+
"items": [
8537+
{
8538+
"String": {
8539+
"str": "my_index",
8540+
},
8541+
},
8542+
],
8543+
},
8544+
},
8545+
],
8546+
"removeType": "OBJECT_INDEX",
8547+
},
8548+
},
8549+
"stmt_len": 43,
8550+
"stmt_location": 2850,
8551+
},
8552+
}
8553+
`;
8554+
8555+
exports[`drops 122`] = `"DROP INDEX CONCURRENTLY IF EXISTS my_index;"`;
8556+
8557+
exports[`drops 123`] = `
8558+
{
8559+
"RawStmt": {
8560+
"stmt": {
8561+
"DropStmt": {
8562+
"behavior": "DROP_RESTRICT",
8563+
"objects": [
8564+
{
8565+
"List": {
8566+
"items": [
8567+
{
8568+
"String": {
8569+
"str": "schema",
8570+
},
8571+
},
8572+
{
8573+
"String": {
8574+
"str": "my_index",
8575+
},
8576+
},
8577+
],
8578+
},
8579+
},
8580+
],
8581+
"removeType": "OBJECT_INDEX",
8582+
},
8583+
},
8584+
"stmt_len": 27,
8585+
"stmt_location": 2894,
8586+
},
8587+
}
8588+
`;
8589+
8590+
exports[`drops 124`] = `"DROP INDEX schema.my_index;"`;
8591+
8592+
exports[`drops 125`] = `
8593+
{
8594+
"RawStmt": {
8595+
"stmt": {
8596+
"DropStmt": {
8597+
"behavior": "DROP_RESTRICT",
8598+
"concurrent": true,
8599+
"objects": [
8600+
{
8601+
"List": {
8602+
"items": [
8603+
{
8604+
"String": {
8605+
"str": "schema",
8606+
},
8607+
},
8608+
{
8609+
"String": {
8610+
"str": "my_index",
8611+
},
8612+
},
8613+
],
8614+
},
8615+
},
8616+
],
8617+
"removeType": "OBJECT_INDEX",
8618+
},
8619+
},
8620+
"stmt_len": 40,
8621+
"stmt_location": 2922,
8622+
},
8623+
}
8624+
`;
8625+
8626+
exports[`drops 126`] = `"DROP INDEX CONCURRENTLY schema.my_index;"`;
8627+
8628+
exports[`drops 127`] = `
8629+
{
8630+
"RawStmt": {
8631+
"stmt": {
8632+
"DropStmt": {
8633+
"behavior": "DROP_RESTRICT",
8634+
"concurrent": true,
8635+
"missing_ok": true,
8636+
"objects": [
8637+
{
8638+
"List": {
8639+
"items": [
8640+
{
8641+
"String": {
8642+
"str": "schema",
8643+
},
8644+
},
8645+
{
8646+
"String": {
8647+
"str": "my_index",
8648+
},
8649+
},
8650+
],
8651+
},
8652+
},
8653+
],
8654+
"removeType": "OBJECT_INDEX",
8655+
},
8656+
},
8657+
"stmt_len": 50,
8658+
"stmt_location": 2963,
8659+
},
8660+
}
8661+
`;
8662+
8663+
exports[`drops 128`] = `"DROP INDEX CONCURRENTLY IF EXISTS schema.my_index;"`;
8664+
8665+
exports[`drops 129`] = `
8666+
{
8667+
"RawStmt": {
8668+
"stmt": {
8669+
"DropStmt": {
8670+
"behavior": "DROP_CASCADE",
8671+
"objects": [
8672+
{
8673+
"List": {
8674+
"items": [
8675+
{
8676+
"String": {
8677+
"str": "my_index",
8678+
},
8679+
},
8680+
],
8681+
},
8682+
},
8683+
],
8684+
"removeType": "OBJECT_INDEX",
8685+
},
8686+
},
8687+
"stmt_len": 28,
8688+
"stmt_location": 3014,
8689+
},
8690+
}
8691+
`;
8692+
8693+
exports[`drops 130`] = `"DROP INDEX my_index CASCADE;"`;
8694+
8695+
exports[`drops 131`] = `
8696+
{
8697+
"RawStmt": {
8698+
"stmt": {
8699+
"DropStmt": {
8700+
"behavior": "DROP_CASCADE",
8701+
"concurrent": true,
8702+
"objects": [
8703+
{
8704+
"List": {
8705+
"items": [
8706+
{
8707+
"String": {
8708+
"str": "my_index",
8709+
},
8710+
},
8711+
],
8712+
},
8713+
},
8714+
],
8715+
"removeType": "OBJECT_INDEX",
8716+
},
8717+
},
8718+
"stmt_len": 41,
8719+
"stmt_location": 3043,
8720+
},
8721+
}
8722+
`;
8723+
8724+
exports[`drops 132`] = `"DROP INDEX CONCURRENTLY my_index CASCADE;"`;
8725+
8726+
exports[`drops 133`] = `
8727+
{
8728+
"RawStmt": {
8729+
"stmt": {
8730+
"DropStmt": {
8731+
"behavior": "DROP_CASCADE",
8732+
"concurrent": true,
8733+
"missing_ok": true,
8734+
"objects": [
8735+
{
8736+
"List": {
8737+
"items": [
8738+
{
8739+
"String": {
8740+
"str": "my_index",
8741+
},
8742+
},
8743+
],
8744+
},
8745+
},
8746+
],
8747+
"removeType": "OBJECT_INDEX",
8748+
},
8749+
},
8750+
"stmt_len": 51,
8751+
"stmt_location": 3085,
8752+
},
8753+
}
8754+
`;
8755+
8756+
exports[`drops 134`] = `"DROP INDEX CONCURRENTLY IF EXISTS my_index CASCADE;"`;
8757+
8758+
exports[`drops 135`] = `
84348759
{
84358760
"RawStmt": {
84368761
"stmt": {
@@ -8459,12 +8784,12 @@ exports[`drops 115`] = `
84598784
},
84608785
},
84618786
"stmt_len": 52,
8462-
"stmt_location": 2764,
8787+
"stmt_location": 3137,
84638788
},
84648789
}
84658790
`;
84668791

8467-
exports[`drops 116`] = `"DROP MATERIALIZED VIEW IF EXISTS no_such_schema.foo;"`;
8792+
exports[`drops 136`] = `"DROP MATERIALIZED VIEW IF EXISTS no_such_schema.foo;"`;
84688793

84698794
exports[`kitchen sink alias 1`] = `
84708795
{

packages/deparser/src/deparser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,6 +2525,9 @@ export default class Deparser {
25252525
const output = [];
25262526
output.push('DROP');
25272527
output.push(objtypeName(node.removeType));
2528+
if (node.concurrent) {
2529+
output.push('CONCURRENTLY');
2530+
}
25282531
if (node.missing_ok) {
25292532
output.push('IF EXISTS');
25302533
}

0 commit comments

Comments
 (0)