rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.23k stars 280 forks source link

Migrations applied as a library, CLI says they are not #98

Closed jlpellicer closed 6 years ago

jlpellicer commented 6 years ago

I started by applying migrations with the CLI, and they went up and the went down.

Then, I integrated the migrations in my app, so that when it starts up, it would apply any pending migrations. It worked, cool.

Now, I tried to take down a migration using the CLI: >sql-migrate down Applied 0 migrations

Then asked, still on the CLI:

>sql-migrate status
+------------------------------+---------+
|          MIGRATION           | APPLIED |
+------------------------------+---------+
| 20171214173958-invoice.sql   | no      |
| 20180104181534-pdf-queue.sql | no      |
+------------------------------+---------+

Is this expected or am I missing something?

This is the dbconfig.yml:

development:
  dialect: postgres
  datasource: dbname=ascApp sslmode=disable
  table: migrations

There is a table in my db called gorp_migrations with the two migrations applied.

And I am running the commands on the CLI on the same level where the dbconfig.yml is.

Thank you.

g-harel commented 6 years ago

Having the same problem, I think the lib just ignores dbconfig

rubenv commented 6 years ago

The config file is only used by the CLI. Any configuration in there also needs to be configured in your application.

jlpellicer commented 6 years ago

Indeed, my configuration pointed to a different table (I had migrations and gorp_migrations. It was a matter of making sure that the dbconfig.yml had the correct table. Thanks!

g-harel commented 6 years ago

If you want to use the package, you can set the table with this

https://godoc.org/github.com/rubenv/sql-migrate#SetTable