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

[BUG] cannot drop column of table because other objects depend on it #181

Closed
aleclarson opened this issue Nov 22, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@aleclarson
Copy link

Describe the bug
The following error occurs when attempting to drop a column that is used by a view.

Error: executing migration statement. the database maybe be in a dirty state:
   {ALTER TABLE "public"."person" DROP COLUMN "name" 3s 3s
   [DELETES_DATA: Deletes all values in the column]}:
   ERROR: cannot drop column name of table person because other objects depend on it (SQLSTATE 2BP01)

Expected behavior
If the DELETES_DATA hazard is allowed, the column should be dropped with CASCADE.

To Reproduce

  1. Start with this SQL:
    CREATE TABLE person (
      id serial PRIMARY KEY,
      name text
    );
    
    CREATE VIEW person_view AS SELECT name FROM person;
  2. Run the migration:
    pg-schema-diff apply
    
  3. Update it to this:
    CREATE TABLE person (
      id serial PRIMARY KEY,
      first_name text,
      last_name text
    );
    
    CREATE VIEW person_view AS
    SELECT
      first_name,
      last_name
    FROM person;
  4. Run the migration:
    pg-schema-diff apply
    

Context
pg-schema-diff version: 5fe8259
pg-schema-diff usage: CLI
Postgres version: 14

@aleclarson aleclarson added the bug Something isn't working label Nov 22, 2024
@bplunkett-stripe
Copy link
Collaborator

We intentionally do not cascade deletes -- this is to avoid implicit deletes. We want all deletes to be done explicitly, i.e., it's a better behavior to fail loudly then implicitly delete the view. This is really just an unfortunate consequence of views not being supported.

#135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants