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

Delete unreferenced tables in a schema #546

Open
lewish opened this issue Jan 7, 2020 · 2 comments
Open

Delete unreferenced tables in a schema #546

lewish opened this issue Jan 7, 2020 · 2 comments

Comments

@lewish
Copy link
Collaborator

lewish commented Jan 7, 2020

There should be a way to tell Dataform to remove any tables from schemas that no longer exist.

This is complicated by the fact that a run may not always contain all of the created tables/views:

  • When using e.g --tags to run only a subset of tables
  • When compiling with an environment, and having two environments that write to the same schema

As a solution to this, we can compute the tables to drop from the compiled graph. We can also for now make the assumption that any database + schema written to by a dataform action is considered "dataform managed".

In the future, we can allow the project to specify which database schemas are considered managed explicitly.

Proposal

Add a new action dataform prune that given the same args as compile, creates a list of all tables and views in any database schema that is written to by the current compiled graph that will not be created by the current compiled graph.

When called with dataform prune --drop, the command should remove all of the listed tables.

@lewish lewish changed the title Support for removing deleted relations from dataform managed schemas Support for removing unexpected relations from dataform managed schemas Jan 7, 2020
@BenBirt BenBirt added the P3 label Jan 13, 2020
@BenBirt BenBirt added P4 and removed P3 labels Jul 6, 2020
@Ekrekr Ekrekr changed the title Support for removing unexpected relations from dataform managed schemas Delete unreferenced tables in a schema Feb 10, 2023
@Ekrekr Ekrekr removed the P4 label Feb 10, 2023
@hobailey
Copy link

@lewish did you ever find a temporary workaround for this by any chance? (eg a specific script you wrote to do the same job until it's available natively)

@hrialan
Copy link

hrialan commented Jul 3, 2024

Hello @hobailey
Here is a script: https://github.com/hrialan/dataform-prune

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants