Skip to content
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.

Migrate doesn't work with CockroachDB #294

Closed
crosslogic opened this issue Oct 17, 2017 · 2 comments · Fixed by #305
Closed

Migrate doesn't work with CockroachDB #294

crosslogic opened this issue Oct 17, 2017 · 2 comments · Fixed by #305
Labels

Comments

@crosslogic
Copy link

I've compiled the CLI with cockroachdb tag and run this command on CocrkoachDB v1.1:

migrate \
            -database cockroachdb://test:test@localhost:26257/test_cl?sslmode=disable     \
            -source file://sqlfiles                                                     \
            -verbose up

This is the log:

2017/10/17 16:12:38 Start buffering 1/u persona
2017/10/17 16:12:38 Start buffering 2/u centros
2017/10/17 16:12:38 Start buffering 3/u conceptos
2017/10/17 16:12:38 Start buffering 4/u contratos
2017/10/17 16:12:38 Start buffering 5/u cuentas
2017/10/17 16:12:38 Start buffering 6/u sucursales
2017/10/17 16:12:38 Start buffering 7/u unicidades
2017/10/17 16:12:38 Start buffering 8/u ubicaciones
2017/10/17 16:12:38 Start buffering 9/u productos
2017/10/17 16:12:38 Start buffering 10/u skus
2017/10/17 16:12:38 Start buffering 11/u usuarios
2017/10/17 16:12:38 Start buffering 30/u ops
2017/10/17 16:12:39 error: pq: relation "schema_migrations" does not exist

Am I missing something?

@mattes mattes added the bug label Oct 20, 2017
@nickjackson
Copy link

I think there is an issue here where the table_name = $1 value needs double quoting.

I believe this is due to some changes made in v1.1.0 around case sensitivity of table names. https://www.cockroachlabs.com/docs/releases/v1.1.0.html#backwards-incompatible-changes

@zikes
Copy link
Contributor

zikes commented Nov 2, 2017

This is a result of using TRUNCATE to clear the migrations table within a transaction at https://github.com/mattes/migrate/blob/master/database/cockroachdb/cockroachdb.go#L224

One of the current limitations of CRDB is that schema changes can't be in the same transaction as data manipulation: https://www.cockroachlabs.com/docs/stable/known-limitations.html#schema-changes-within-transactions

Unfortunately, it seems that TRUNCATE is considered a schema change. My guess is that it drops and recreates the table behind the scenes for efficiency's sake, rather than deleting individual records. I changed that line to DELETE FROM and this error was resolved for me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants