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

drop tables on resources being missing #224

Open
zimakki opened this issue Mar 20, 2024 · 3 comments
Open

drop tables on resources being missing #224

zimakki opened this issue Mar 20, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@zimakki
Copy link

zimakki commented Mar 20, 2024

Is your feature request related to a problem? Please describe.

I have a Message resource that I would like to delete. I deleted the code and ran the mix ash_postgres.generate_migrations --name remove_message_resource but that came back with:

Extension Migrations:
No extensions to install

Generating Tenant Migrations:

Generating Migrations:
No changes detected, so no migrations or snapshots have been created.

Describe the solution you'd like

I would expect it to detect that a resource has been deleted and create the migration.

Describe alternatives you've considered

creating the migration using mix ecto.gen.migration remove_messaage_table seems to have worked.

Additional context

Chat about this idea in discord:
Zi Makki — Today at 14:09

I have a Message resource that I would like to delete. I deleted the code and ran the mix ash_postgres.generate_migrations --name remove_message_resource but that came back with:
Extension Migrations:

No extensions to install

Generating Tenant Migrations:

Generating Migrations:
No changes detected, so no migrations or snapshots have been created.

What is the ash way of deleting a resource and creating a migration to delete the db table?

barnabasj — Today at 15:00

It's possible that it's not diffing for removed Resources. But you can always just use the regular Ecto tasks to create a migration and drop the table there.

Zi Makki — Today at 15:17

ah ok... so I don't need to do anything "special" re the snapshots?

barnabasj — Today at 15:44

In this case it shouldn't make a difference as you already ran the generator and it did nothing.
I built something with ash where there was already an existing database and I built not all of the old stuff at the beginning but also added some new stuff. That way the things got sometimes a bit out of sync. But what I did from time to time was run the migration generator to update the snapshots and deleted the generated migrations. Next time you run the generator after things should be fine again.
But as said in the beginning it shouldn't be a problem in your case
If you add the same resource again in the future it would probably only create migrations for the diffs between the resource when you deleted it and the version you added again.
A GitHub issue would still be appreciated to track this and maybe integrate something for it

@zimakki zimakki added enhancement New feature or request needs review labels Mar 20, 2024
@zachdaniel zachdaniel changed the title mix ash_postgres.generate_migration does nothing if a resource has been removed/deleted drop tables on resources being missing Mar 20, 2024
@zachdaniel
Copy link
Contributor

At the moment, the migration generator does not delete tables. PRs welcome :)

@zachdaniel
Copy link
Contributor

This will also need to handle table renames, per: #256

@zachdaniel zachdaniel added the good first issue Good for newcomers label May 1, 2024
@sevenseacat
Copy link
Contributor

I think the difference between renaming/dropping is big enough to be separate issues. I also admire the developer willing to tackle it as a first issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants