Skip to content

Commit

Permalink
Create schema.sql on migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
swlkr committed Dec 3, 2019
1 parent 9023d89 commit cc17288
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/joy/migrator.janet
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
(print up)
(db/execute conn up)
(db/execute conn "insert into schema_migrations (version) values (:version)" {:version version})
(let [rows (db/query conn "select sql from sqlite_master where sql is not null order by rootpage")]
(helper/with-file [f "db/schema.sql" :w]
(file/write f
(string/join
(map |(get $ :sql) rows)
"\n"))))
(print "Successfully migrated [" migration "]")))))))


Expand All @@ -73,6 +79,12 @@
(print down)
(db/execute conn down)
(db/execute conn "delete from schema_migrations where version = :version" {:version version})
(let [rows (db/query conn "select sql from sqlite_master where sql is not null order by rootpage")]
(helper/with-file [f "db/schema.sql" :w]
(file/write f
(string/join
(map |(get $ :sql) rows)
"\n"))))
(print "Successfully rolled back [" migration "]"))))))


0 comments on commit cc17288

Please sign in to comment.