migratus version: 1.5.1
The following is the sample sqls in resources/migrations folder. I intentionally used incremental integers for brevity.
;; resources/migrations/1-create-foo-table.up.sql
CREATE TABLE IF NOT EXISTS foo(id BIGINT);
;; resources/migrations/1-create-foo-table.down.sql
DROP TABLE IF EXISTS foo;
;; resources/migrations/2-create-bar-table.up.sql
CREATE TABLE IF NOT EXISTS bar(id BIGINT);
;; resources/migrations/2-create-bar-table.down.sql
DROP TABLE IF EXISTS bar;
;; resources/migrations/3-create-baz-table.up.sql
CREATE TABLE IF NOT EXISTS baz(id BIGINT);
;; resources/migrations/3-create-baz-table.down.sql
DROP TABLE IF EXISTS baz;
The following is my project.clj related to Migratus.
:plugins [[migratus-lein "0.7.3"]]
:migratus {:store :database
:migration-dir "resources/migrations/"
:db {:dbtype "mysql"
:dbname "hcp_safety"
:user "root"
:password "my_password"}}
lein migratus migrate worked as I expected.
$ lein migratus migrate
migrating all outstanding migrations
$ mysql
mysql> use hcp_safety;
mysql> show tables;
+----------------------+
| Tables_in_hcp_safety |
+----------------------+
| bar |
| baz |
| foo |
| schema_migrations |
+----------------------+
4 rows in set (0.00 sec)
mysql> select * from schema_migrations;
+----+---------------------+------------------+
| id | applied | description |
+----+---------------------+------------------+
| 1 | 2023-08-02 20:11:38 | create-foo-table |
| 2 | 2023-08-02 20:11:38 | create-bar-table |
| 3 | 2023-08-02 20:11:38 | create-baz-table |
+----+---------------------+------------------+
3 rows in set (0.00 sec)
However, lein migratus rollback didn't work as I expected.
$ lein migratus rollback
rolling back last migration
$ mysql
mysql> use hcp_safety;
mysql> show tables;
+----------------------+
| Tables_in_hcp_safety |
+----------------------+
| bar |
| baz |
| schema_migrations |
+----------------------+
3 rows in set (0.01 sec)
mysql> select * from schema_migrations;
+----+---------------------+------------------+
| id | applied | description |
+----+---------------------+------------------+
| 2 | 2023-08-02 20:11:38 | create-bar-table |
| 3 | 2023-08-02 20:11:38 | create-baz-table |
+----+---------------------+------------------+
2 rows in set (0.00 sec)
Migratus rollback doesn't bring down the last migration (create-baz-table), but the first migration (create-foo-table).
migratus version: 1.5.1
The following is the sample sqls in resources/migrations folder. I intentionally used incremental integers for brevity.
The following is my project.clj related to Migratus.
lein migratus migrateworked as I expected.However,
lein migratus rollbackdidn't work as I expected.Migratus rollback doesn't bring down the last migration (create-baz-table), but the first migration (create-foo-table).