How to Delete Resource?

Dirigible
2023-02-26

Dirigible:

I have a resource that has attributes and relationships to other resources. I want to delete it completely, how would I do that?

Dirigible:

Ok so I figured this out, in the end, posting here for posterity.

These are the steps I took:

  1. Take note of what the resource is called in the db (in my case cards )
  2. Delete the resource.
  3. remove the resource in the Registry, and in any other resource where its has a relationship.
  4. generate a migration mix ash_postgres.create_migrations --name
  5. add drop table() in my case drop table(:cards) into the up/0 function.
  6. Run mix ash_postgres.migrate

This worked for me, <@197905764424089601> hop in if I missed something. (Is there a topic for AshHQ on this, if not there probably should be?)

ZachDaniel:

Lol, go for it

ZachDaniel:

You may not have any changes when you generate migrations. So you may want to use mix ecto.gen.migration

zimt28:

You might also need to remove constrains & indexes I guess? Would be nice if there was a generator for this 🙂

ZachDaniel:

Yeah, that’s true. I think the migration generator should do it. PRs welcome ❤️