How to run particular migration

I’m learning Elixir by creating an application that requires 3 tables clients, workers and placements. I created and migrated the clients table first. I created the workers schema but forgot to create the associated migrations then went of to create and migrate the placements table.

I later created an alter migration for the placements table to add references to the workers and clients tables plus some indexes. When I tried to migrate these changes I got an error that the workers table doesn’t exist which is true.

I therefore created the migration to create the workers table and tried to migrate that with the command mix ecto.migrate workers but I still get the error that the workers table doesn’t exist because it seems to run the migration for the altering of the placements table before the creation of the workers table.

How do I run only the migration to create the workers table without running the alter placements table migration?

In case You messed up migrations, You can always run…

$ mix ecto.reset

… to reset your database (If You are using Phoenix)

As far as I remember you can’t actually run a migration by file or module name, you need to manipulate the timestamp in the filename to have the correct order.

3 Likes

Thanks @NobbZ, neat trick that worked :smile: