kawadhiya21 / mysql-migrations

A tool to use with mysql package to maintain migrations
MIT License
31 stars 25 forks source link

Hangs when running `down` and no more migrations to run #28

Closed lewismoten closed 2 months ago

lewismoten commented 2 months ago

Keep running migration.js down to revert all migrations. Eventually you'll have a database without any values in mysql_migrations_347ertt3e. Run migration.js down one more time. The script will hang.

The problem appears to be due to the lack of a callback function if the query for timestamps in the database is zero. I see a truthy statement to perform some logic to execute queries if the database still has timestamps - but I don't see an else statement.

https://github.com/kawadhiya21/mysql-migrations/blob/65c52086c766d5c91508ba66c3b811682484c4b2/core_functions.js#L91

My proposal is to add an else condition that writes a message to the console indicating that the database does not have anymore migrations to rollback, and to call the cb() function.

} else {
   console.log("Database contains no migrations to rollback");
   cb();
}
lewismoten commented 2 months ago

Also of note, running migration.js refresh will also hang if the database does not have any migration timestamps since it also calls the same down_migrations function.

lewismoten commented 2 months ago

Closing as this duplicates #17 . Please see the cause and fix in my original comment.