Closed apa512 closed 4 years ago
Looks like the table hasn't been created before migrate
was run, did you run init
first to initialize the schema?
I did not run init
. Am I supposed to manually create the migrations table?
Running the init
function will create the migration table.
@yogthos Are you sure sure? Maybe I'm misreading the code, but it looks to me like init
is only supposed to run an optional init.sql
while migrate
is supposed to create the migrations table if it's missing.
I've done some more digging and what happens for me is that the SQL exception in migratus.database/table-exists?
when the migrations table doesn't exist "escapes" to migratus.databse/init-schema!
which causes migratus.database/create-migration-table!
not to be called.
If I .rollback
the transaction before returning false
in table-exists?
everything works like I expected, i.e. migrate
creates my migrations table and runs all the migrations.
Ah, you're right the table is created by the [init-schema!]((defn init-schema! [db table-name modify-sql-fn]) function, and that's called on connect here, and that in turn is clled in run that's used by migrate
.
I'm not able to reproduce the issue on my end, so not sure what's causing it in your case, but If doing a rollback before returning false addresses it then would make sense to add it in. If you'd like to do a PR with your version I can push out
Something happened in org.postgresql/postgresql {:mvn/version "42.2.11"}
. Before this, everything works fine.
I guess https://github.com/pgjdbc/pgjdbc/pull/1729 is the relevant change.
Ah, that would do it. So, just have to add db-set-rollback-only!
in the transaction then, and that should do the trick?
(sql/with-db-transaction
[t-con db]
(try
(sql/db-set-rollback-only! t-con)
(sql/query t-con [(str "SELECT 1 FROM " table-name)])
true
(catch SQLException _
false)))
Yes, this fixes it for me.
Great, just pushed out 1.2.8
with the fix. Thanks for digging in, and sorry I misled you there at the start. :)
:+1: Thanks for the quick release
I have a confusing issue. It looks like
SQLException
isn't being caught intable-exists?
.=>
Stacktrace:
And in the CLJ REPL:
But
I really have no idea what to make of this. The only thing I can think of is that this is my first time using Migratus with a deps.edn project.