Skip to content

Commit

Permalink
cli: table creation order fix
Browse files Browse the repository at this point in the history
* Fixes issue with tables not being created in correct order with
  respect to foreign key constraints.

Signed-off-by: Lars Holm Nielsen <lars.holm.nielsen@cern.ch>
  • Loading branch information
lnielsen committed Oct 17, 2015
1 parent 99bb968 commit 4225631
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion invenio_db/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def db():
def create(verbose):
"""Create tables."""
click.secho('Creating all tables!', fg='yellow', bold=True)
with click.progressbar(reversed(_db.metadata.sorted_tables)) as bar:
with click.progressbar(_db.metadata.sorted_tables) as bar:
for table in bar:
if verbose:
click.echo(' Creating table {0}'.format(table))
Expand Down
5 changes: 5 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@


class MockEntryPoint(EntryPoint):
"""Mocking of entrypoint."""

def load(self):
"""Mock load entry point."""
if self.name == 'importfail':
raise ImportError()
else:
Expand All @@ -61,6 +64,7 @@ def _mock_entry_points(name):


def test_init():
"""Test extension initialization."""
app = Flask('demo')
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get(
'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'
Expand All @@ -75,6 +79,7 @@ class Demo(db.Model):
class Demo2(db.Model):
__tablename__ = 'demo2'
pk = sa.Column(sa.Integer, primary_key=True)
fk = sa.Column(sa.Integer, sa.ForeignKey(Demo.pk))

with app.app_context():
create_database(db.engine.url)
Expand Down

0 comments on commit 4225631

Please sign in to comment.