karenc / db-migrator

GNU Affero General Public License v3.0
4 stars 5 forks source link

Running past migration after init with shared context #10

Closed mmulich closed 8 years ago

mmulich commented 8 years ago

I've run into an error on 'migrate' after initializing a fresh database.

The following steps should reproduce the error:

  1. dropdb, if you've got one
  2. createdb
  3. cnx-archive-initdb & cnx-publishing-initdb
  4. dbmigrator --config app.ini --context cnx-archive init
  5. dbmigrator --config app.ini --context cnx-publishing migrate
Traceback (most recent call last):
  File "/var/cnx/venvs/publishing/bin/dbmigrator", line 9, in <module>
    load_entry_point('db-migrator==0.0.7', 'console_scripts', 'dbmigrator')()
  File "/var/cnx/venvs/publishing/local/lib/python2.7/site-packages/dbmigrator/cli.py", line 70, in main
    return args['cmmd'](**args)
  File "/var/cnx/venvs/publishing/local/lib/python2.7/site-packages/dbmigrator/utils.py", line 66, in wrapper
    return func(cursor, *args, **kwargs)
  File "/var/cnx/venvs/publishing/local/lib/python2.7/site-packages/dbmigrator/commands/migrate.py", line 30, in cli_command
    migration)
  File "/var/cnx/venvs/publishing/local/lib/python2.7/site-packages/dbmigrator/utils.py", line 121, in compare_schema
    callback(*args, **kwargs)
  File "/var/cnx/venvs/publishing/local/lib/python2.7/site-packages/dbmigrator/utils.py", line 132, in run_migration
    migration.up(cursor)
  File "../../var/cnx/venvs/publishing/local/lib/python2.7/site-packages/cnxpublishing/sql/migrations/20160104115058_add_api_keys_table.py", line 18, in up
    """)
psycopg2.ProgrammingError: relation "api_keys" already exists

Also, the schema_migrations database looks like this:

cnxarchive=# select * from schema_migrations;
 version | applied 
---------+---------
(0 rows)
mmulich commented 8 years ago

As we discussed a few hours ago, 'init' enters existing migrations into the schema_migrations table. The problem is that our 'init' never finds the migrations in cnx-publishing, because this package is not currently in context. :frowning:

karenc commented 8 years ago

So... there are 2 things to fix here:

mmulich commented 8 years ago

Hopefully resolved via #11