Skip to content
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

sql: implement the DROP TYPE ... CASCADE command #51480

Closed
rohany opened this issue Jul 15, 2020 · 5 comments
Closed

sql: implement the DROP TYPE ... CASCADE command #51480

rohany opened this issue Jul 15, 2020 · 5 comments
Labels
A-schema-changes A-tools-efcore C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@rohany
Copy link
Contributor

rohany commented Jul 15, 2020

We don't currently support the CASCADE suffix.

Jira issue: CRDB-4040
Epic link: CRDB-13664

@rohany rohany added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Jul 15, 2020
@solongordon
Copy link
Contributor

Probably won't be completed for 20.2. Per Rohan this is difficult to implement with the current schema change framework because the type cannot be dropped until all objects which use it have been dropped. Rollback is also quite tricky.

@simplenotezy
Copy link

Currently using TypeORM with cockroachdb as a driver; is there a workaround on this? The app simply won't boot:

[Nest] 85679  - 06/20/2022, 8:47:09 PM     LOG [RedisModule] default: Connected successfully to the server
query: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
query: CREATE EXTENSION IF NOT EXISTS "postgis"
query: SHOW server_version;
query: START TRANSACTION
query: SHOW SERVER_VERSION
query: SELECT 'DROP VIEW IF EXISTS "' || schemaname || '"."' || viewname || '" CASCADE;' as "query" FROM "pg_views" WHERE "schemaname" IN (current_schema()) AND "viewname" NOT IN ('geography_columns', 'geometry_columns', 'raster_columns', 'raster_overviews')
query: SELECT 'DROP MATERIALIZED VIEW IF EXISTS "' || schemaname || '"."' || matviewname || '" CASCADE;' as "query" FROM "pg_matviews" WHERE "schemaname" IN (current_schema())
query: SELECT 'DROP TABLE IF EXISTS "' || schemaname || '"."' || tablename || '" CASCADE;' as "query" FROM "pg_tables" WHERE "schemaname" IN (current_schema()) AND "tablename" NOT IN ('spatial_ref_sys')
query: SELECT 'DROP TYPE IF EXISTS "' || n.nspname || '"."' || t.typname || '" CASCADE;' as "query" FROM "pg_type" "t" INNER JOIN "pg_enum" "e" ON "e"."enumtypid" = "t"."oid" INNER JOIN "pg_namespace" "n" ON "n"."oid" = "t"."typnamespace" WHERE "n"."nspname" IN (current_schema()) GROUP BY "n"."nspname", "t"."typname"
query: DROP TYPE IF EXISTS "public"."gender_enum" CASCADE;
query: DROP TYPE IF EXISTS "public"."sexual_orientations_enum" CASCADE;
query failed: DROP TYPE IF EXISTS "public"."gender_enum" CASCADE;
error: error: unimplemented: DROP TYPE CASCADE is not yet supported
    at Parser.parseErrorMessage (/Users/me/Projects/project/backend/node_modules/pg-protocol/src/parser.ts:369:69)
    at Parser.handlePacket (/Users/me/Projects/project/backend/node_modules/pg-protocol/src/parser.ts:188:21)
    at Parser.parse (/Users/me/Projects/project/backend/node_modules/pg-protocol/src/parser.ts:103:30)
    at Socket.<anonymous> (/Users/me/Projects/project/backend/node_modules/pg-protocol/src/index.ts:7:48)
    at Socket.emit (node:events:526:28)
    at Socket.emit (node:domain:475:12)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 213,
  severity: 'ERROR',
  code: '0A000',
  detail: undefined,
  hint: 'You have attempted to use a feature that is not yet implemented.\n' +
    'See: https://go.crdb.dev/issue-v/51480/v22.1',
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'drop_type.go',
  line: '53',
  routine: 'DropType'
}
query: ROLLBACK
query failed: DROP TYPE IF EXISTS "public"."sexual_orientations_enum" CASCADE;
error: error: current transaction is aborted, commands ignored until end of transaction block
    at Parser.parseErrorMessage (/Users/me/Projects/project/backend/node_modules/pg-protocol/src/parser.ts:369:69)
    at Parser.handlePacket (/Users/me/Projects/project/backend/node_modules/pg-protocol/src/parser.ts:188:21)
    at Parser.parse (/Users/me/Projects/project/backend/node_modules/pg-protocol/src/parser.ts:103:30)
    at Socket.<anonymous> (/Users/me/Projects/project/backend/node_modules/pg-protocol/src/index.ts:7:48)
    at Socket.emit (node:events:526:28)
    at Socket.emit (node:domain:475:12)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 143,
  severity: 'ERROR',
  code: '25P02',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'errors.go',
  line: '39',
  routine: 'NewTransactionAbortedError'
}

@postamar
Copy link
Contributor

postamar commented Jul 7, 2022

This will be trivial to implement in the declarative schema changer once DROP COLUMN support is added. This is required because in postgres, if you have a table with a column with a user-defined type, and you DROP TYPE CASCADE that type, this drops the column from the table.

@kris-lwks
Copy link

We run into this issue when testing migrating a mysql database into CockroachDB.

@postamar postamar self-assigned this Aug 2, 2022
@postamar postamar removed their assignment Sep 16, 2022
postamar pushed a commit to postamar/cockroach that referenced this issue Feb 3, 2023
Recently, we've added support for constraint removal in the declarative
schema changer. This now makes it possible to support DROP TYPE ...
CASCADE statements. As a result, DROP OWNED BY now also performs
correctly when user-defined types are involved and no longer returns an
error.

This commit also extends the coverage of the declarative schema
changer's ALTER TABLE ... DROP COLUMN support, which no longer punts to
the legacy schema changer when the column to drop is referenced in
a constraint. Now, the constraint gets dropped.

Fixes cockroachdb#51480.
Fixes cockroachdb#55908.

Release note (sql change): DROP TYPE ... CASCADE is now supported and no
longer returns an error. Consequently DROP OWNED BY no longer returns an
error when it tries to drop a type in a cascading manner.
postamar pushed a commit to postamar/cockroach that referenced this issue Feb 4, 2023
Recently, we've added support for constraint removal in the declarative
schema changer. This now makes it possible to support DROP TYPE ...
CASCADE statements. As a result, DROP OWNED BY now also performs
correctly when user-defined types are involved and no longer returns an
error.

This commit also extends the coverage of the declarative schema
changer's ALTER TABLE ... DROP COLUMN support, which no longer punts to
the legacy schema changer when the column to drop is referenced in
a constraint. Now, the constraint gets dropped.

The declarative schema changer still differs from Postgres behaviour
when the column to drop is part of the primary key. Whereas postgres
happily removes the primary key constraint and the column, CRDB is
unable to do so straigtforwardly. What to do here remains an open
question, there are many possible solutions, in the meantime we return
an error.

Fixes cockroachdb#51480.
Fixes cockroachdb#55908.

Release note (sql change): DROP TYPE ... CASCADE is now supported and no
longer returns an error. Consequently DROP OWNED BY no longer returns an
error when it tries to drop a type in a cascading manner.
@exalate-issue-sync exalate-issue-sync bot added T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) and removed T-sql-schema-deprecated Use T-sql-foundations instead labels May 10, 2023
@rafiss
Copy link
Collaborator

rafiss commented Feb 13, 2024

This has been implemented under the new schema changer. We do not have plans to address this in the legacy schema changer. https://www.cockroachlabs.com/docs/stable/online-schema-changes#declarative-schema-changer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes A-tools-efcore C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants