Replies: 5 comments 2 replies
|
I will change the example of the table name so that it's not confusing. I was in the process of creating a migration table when I realized it was already implemented, that's why it's the example. |
|
Looks pretty good! This is not a request to change anything, but I want to leave a comment. I'm always asked by people that "generate-migrations" doesn't generate as people intended, but it's not what it's supposed to do. |
|
Thanks! TIL. my 2c: say again that during development, it is possible to not use migrations files, but to rely on |
|
Hi, I've tried using If I use mito/src/migration/versions.lisp Line 368 in 5d315c8 with the Then, the generated migration files are not really executing. I keep checking the DB and the columns which are supposed to be added with the migration files are not added, even though the messages say it worked. I get these outputs: CL-USER> (let*
((my-app-dir (asdf:system-source-directory "my-app"))
(db-path (uiop:merge-pathnames* my-app-dir #P"/db"))
(db-dir (uiop:ensure-directory-pathname db-path)))
(mito:migrate db-dir :dry-run t :force t))
;; SELECT "version" FROM "schema_migrations" ORDER BY "version" DESC LIMIT 1 () [0 rows] (206ms) | MITO.MIGRATION.VERSIONS:CURRENT-MIGRATION-VERSION
;; INSERT INTO "schema_migrations" ("version") VALUES ($1) (20251215020651) [1 row] (1361ms) | MITO.MIGRATION.VERSIONS:MIGRATE
No problems were found while migration.
0 (0 bits, #x0, #o0, #b0)
CL-USER> (let*
((my-app-dir (asdf:system-source-directory "my-app"))
(db-path (uiop:merge-pathnames* my-app-dir #P"/db"))
(db-dir (uiop:ensure-directory-pathname db-path)))
(mito:migrate db-dir :force t))
;; SELECT "version" FROM "schema_migrations" ORDER BY "version" DESC LIMIT 1 () [0 rows] (195ms) | MITO.MIGRATION.VERSIONS:CURRENT-MIGRATION-VERSION
;; INSERT INTO "schema_migrations" ("version") VALUES ($1) (20251215020651) [1 row] (189ms) | MITO.MIGRATION.VERSIONS:MIGRATE
Successfully updated to the version 20251215020651.
NIL
CL-USER> (let*
((my-app-dir (asdf:system-source-directory "my-app"))
(db-path (uiop:merge-pathnames* my-app-dir #P"/db"))
(db-dir (uiop:ensure-directory-pathname db-path)))
(mito:migrate db-dir))
;; SELECT "version" FROM "schema_migrations" ORDER BY "version" DESC LIMIT 1 () [1 row] (1175ms) | MITO.MIGRATION.VERSIONS:CURRENT-MIGRATION-VERSION
;; SELECT "version" FROM "schema_migrations" WHERE ("applied_at" IS NOT NULL) ORDER BY "version" () [1 row] (158ms) | MITO.MIGRATION.VERSIONS::%MIGRATION-STATUS
Version 20251215020651 is up to date.
NIL
CL-USER> (let*
((my-app-dir (asdf:system-source-directory "my-app"))
(db-path (uiop:merge-pathnames* my-app-dir #P"/db"))
(db-dir (uiop:ensure-directory-pathname db-path))
(migrations-dir (uiop:ensure-directory-pathname (uiop:merge-pathnames* db-dir #P"migrations"))))
migrations-dir)
#P"/home/my-app/db/migrations/"
CL-USER> (mito:migrate #P"/home/my-app/db/migrations/20251215020651.up.sql")
;; SELECT "version" FROM "schema_migrations" ORDER BY "version" DESC LIMIT 1 () [1 row] (204ms) | MITO.MIGRATION.VERSIONS:CURRENT-MIGRATION-VERSION
;; SELECT "version" FROM "schema_migrations" WHERE ("applied_at" IS NOT NULL) ORDER BY "version" () [1 row] (181ms) | MITO.MIGRATION.VERSIONS::%MIGRATION-STATUS
Version 20251215020651 is up to date.
NIL
CL-USER> Any ideas? Am I doing something wrong? Thanks! |
UPDATEI finally managed to get this working. The problems I had were that this does not work well with an existing database which already mostly conforms to the generated schema. If there is no existing migration, (unless (mito.migration.versions:current-migration-version))
(mito.migration.versions:update-migration-version 1))
(mito.migration.versions:generate-migrations db-dir)That generates the migration files. To apply the migrations, do the following: (unless (mito.migration.versions:current-migration-version))
(mito.migration.versions:update-migration-version 1))
(mito.migration.versions:migrate db-dir)Note I just added the code to update the migration version in both places in case there is no current migration. This bypasses mito trying to apply the schema instead of the latest up migration file. I have not actually tried using the code on a db with no tables, but presumably that should work since the application of the schema should cause no issues. I don't know if after applying the schema mito will update the migration version to the latest up file or not. @fukamachi This was my workaround because of an existing db. Should I add this as part of the docs? Is this how the library is intended to work or is this a bug? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I was about to write a lot of code for migrations just to realize it seems to all be there already, just not documented.
Question is: once the files are generated how should they be executed?
I can write the docs, I just need a bit of guidance.
This is what I have so far (needs to be edited). Does it look like a good enough approach? If so I can fix the formatting and add it to the docs.
Question is: once the files are generated: how should they be executed?
I tried using
But this gave me an error saying:
This seems to be trying to execute the
schema.sqlfile instead of the migration files.If instead I run:
So the migration file is not actually executed.
So how do we execute the migration files with mito?
All reactions