Skip to content

fix: support concurrently in DROP INDEX #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions __fixtures__/drops.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ DROP DOMAIN IF EXISTS no_such_schema.foo;
DROP FOREIGN TABLE IF EXISTS no_such_schema.foo;

DROP INDEX IF EXISTS no_such_schema.foo;
DROP INDEX my_index;
DROP INDEX CONCURRENTLY my_index;
DROP INDEX IF EXISTS my_index;
DROP INDEX CONCURRENTLY IF EXISTS my_index;
DROP INDEX schema.my_index;
DROP INDEX CONCURRENTLY schema.my_index;
DROP INDEX CONCURRENTLY IF EXISTS schema.my_index;
DROP INDEX my_index CASCADE;
DROP INDEX CONCURRENTLY my_index CASCADE;
DROP INDEX CONCURRENTLY IF EXISTS my_index CASCADE;
DROP MATERIALIZED VIEW IF EXISTS no_such_schema.foo;

-- DROP OPERATOR IF EXISTS no_such_schema.+ (int, int);
Expand Down
329 changes: 327 additions & 2 deletions packages/deparser/__tests__/__snapshots__/kitchen-sink.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8431,6 +8431,331 @@ exports[`drops 113`] = `
exports[`drops 114`] = `"DROP INDEX IF EXISTS no_such_schema.foo;"`;

exports[`drops 115`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_RESTRICT",
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 20,
"stmt_location": 2764,
},
}
`;

exports[`drops 116`] = `"DROP INDEX my_index;"`;

exports[`drops 117`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_RESTRICT",
"concurrent": true,
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 33,
"stmt_location": 2785,
},
}
`;

exports[`drops 118`] = `"DROP INDEX CONCURRENTLY my_index;"`;

exports[`drops 119`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_RESTRICT",
"missing_ok": true,
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 30,
"stmt_location": 2819,
},
}
`;

exports[`drops 120`] = `"DROP INDEX IF EXISTS my_index;"`;

exports[`drops 121`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_RESTRICT",
"concurrent": true,
"missing_ok": true,
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 43,
"stmt_location": 2850,
},
}
`;

exports[`drops 122`] = `"DROP INDEX CONCURRENTLY IF EXISTS my_index;"`;

exports[`drops 123`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_RESTRICT",
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "schema",
},
},
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 27,
"stmt_location": 2894,
},
}
`;

exports[`drops 124`] = `"DROP INDEX schema.my_index;"`;

exports[`drops 125`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_RESTRICT",
"concurrent": true,
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "schema",
},
},
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 40,
"stmt_location": 2922,
},
}
`;

exports[`drops 126`] = `"DROP INDEX CONCURRENTLY schema.my_index;"`;

exports[`drops 127`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_RESTRICT",
"concurrent": true,
"missing_ok": true,
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "schema",
},
},
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 50,
"stmt_location": 2963,
},
}
`;

exports[`drops 128`] = `"DROP INDEX CONCURRENTLY IF EXISTS schema.my_index;"`;

exports[`drops 129`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_CASCADE",
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 28,
"stmt_location": 3014,
},
}
`;

exports[`drops 130`] = `"DROP INDEX my_index CASCADE;"`;

exports[`drops 131`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_CASCADE",
"concurrent": true,
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 41,
"stmt_location": 3043,
},
}
`;

exports[`drops 132`] = `"DROP INDEX CONCURRENTLY my_index CASCADE;"`;

exports[`drops 133`] = `
{
"RawStmt": {
"stmt": {
"DropStmt": {
"behavior": "DROP_CASCADE",
"concurrent": true,
"missing_ok": true,
"objects": [
{
"List": {
"items": [
{
"String": {
"str": "my_index",
},
},
],
},
},
],
"removeType": "OBJECT_INDEX",
},
},
"stmt_len": 51,
"stmt_location": 3085,
},
}
`;

exports[`drops 134`] = `"DROP INDEX CONCURRENTLY IF EXISTS my_index CASCADE;"`;

exports[`drops 135`] = `
{
"RawStmt": {
"stmt": {
Expand Down Expand Up @@ -8459,12 +8784,12 @@ exports[`drops 115`] = `
},
},
"stmt_len": 52,
"stmt_location": 2764,
"stmt_location": 3137,
},
}
`;

exports[`drops 116`] = `"DROP MATERIALIZED VIEW IF EXISTS no_such_schema.foo;"`;
exports[`drops 136`] = `"DROP MATERIALIZED VIEW IF EXISTS no_such_schema.foo;"`;

exports[`kitchen sink alias 1`] = `
{
Expand Down
3 changes: 3 additions & 0 deletions packages/deparser/src/deparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,9 @@ export default class Deparser {
const output = [];
output.push('DROP');
output.push(objtypeName(node.removeType));
if (node.concurrent) {
output.push('CONCURRENTLY');
}
if (node.missing_ok) {
output.push('IF EXISTS');
}
Expand Down
Loading