weavejester / ragtime

Database-independent migration library
Eclipse Public License 1.0
610 stars 85 forks source link

Migration not working with SQLite :memory: #116

Closed smotti closed 7 years ago

smotti commented 7 years ago

Migrations don't work when the database is a SQLite in-memory db.

(def config
  {:datastore (jdbc/sql-database {:connection-uri "jdbc:sqlite::memory:"})
   :migrations (jdbc/load-resources "migrations")})

(repl/migrate config)

org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such table: ragtime_migrations)
weavejester commented 7 years ago

This is because SQLite creates a new in-memory database per connection. So each time the database is accessed, it's an entirely new database. To get this to work, you need to hang onto the connection:

(def conn
  (clojure.java.jdbc/get-connection {:connection-uri "jdbc:sqlite::memory:"}))

(def config
  {:datastore  (jdbc/sql-database {:connection conn})
   :migrations (jdbc/load-resources "migrations")})
smotti commented 7 years ago

@weavejester Thank you very much! I didn't know that.