This occurs when you have an explicit schema for your migrations table, like myschema.migrations.
ensure-migrations-table-exists ends up calling get-table-names* which only returns table names, which do not include schemas. table-exists? will then always returns false for the example table above, since it'll effectively be running:
The first time ensure-migrations-table-exists is called this doesn't cause a problem. It can't find the table (which doesn't exist yet) and so it creates it. The next time it's called, it still won't find the table, and will try to create it again, getting an error like this:
Exception in thread "main" org.postgresql.util.PSQLException: ERROR: relation "migrations" already exists
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:135)
at clojure.java.jdbc$db_do_execute_prepared_statement$fn__342.invoke(jdbc.clj:784)
at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:613)
at clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:585)
at clojure.java.jdbc$db_transaction_STAR_.invokeStatic(jdbc.clj:598)
at clojure.java.jdbc$db_transaction_STAR_.invoke(jdbc.clj:585)
at clojure.java.jdbc$db_do_execute_prepared_statement.invokeStatic(jdbc.clj:783)
at clojure.java.jdbc$db_do_execute_prepared_statement.invoke(jdbc.clj:778)
at clojure.java.jdbc$db_do_prepared.invokeStatic(jdbc.clj:814)
at clojure.java.jdbc$db_do_prepared.invoke(jdbc.clj:795)
at clojure.java.jdbc$execute_BANG_$execute_helper__385.invoke(jdbc.clj:961)
at clojure.java.jdbc$execute_BANG_.invokeStatic(jdbc.clj:965)
at clojure.java.jdbc$execute_BANG_.invoke(jdbc.clj:943)
at clojure.java.jdbc$execute_BANG_.invokeStatic(jdbc.clj:954)
at clojure.java.jdbc$execute_BANG_.invoke(jdbc.clj:943)
at ragtime.jdbc$ensure_migrations_table_exists.invokeStatic(jdbc.clj:36)
at ragtime.jdbc$ensure_migrations_table_exists.invoke(jdbc.clj:34)
at ragtime.jdbc.SqlDatabase.applied_migration_ids(jdbc.clj:55)
at ragtime.core$migrate_all.invokeStatic(core.clj:57)
at ragtime.core$migrate_all.invoke(core.clj:33)
at ragtime.repl$migrate.invokeStatic(repl.clj:32)
at ragtime.repl$migrate.invoke(repl.clj:17)
at job.migrate$_main.invokeStatic(migrate.clj:8)
This occurs when you have an explicit schema for your migrations table, like
myschema.migrations
.ensure-migrations-table-exists
ends up callingget-table-names*
which only returns table names, which do not include schemas.table-exists?
will then always returns false for the example table above, since it'll effectively be running:The first time
ensure-migrations-table-exists
is called this doesn't cause a problem. It can't find the table (which doesn't exist yet) and so it creates it. The next time it's called, it still won't find the table, and will try to create it again, getting an error like this: