From 23a54632081aa589e05a820ac774c8b4f6993252 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 17 Aug 2016 17:10:07 -0700 Subject: [PATCH] Hack around the "last migration doesn't stamp" Alembic bug (#967) * Hack around the "last migration doesn't stamp" Alembic bug This makes MySQL, Sqlite and Postgres work with a special hard coded rule. I'm hoping Alembic fixes the root cause eventually. * Running db upgrade twice in tests --- caravel/assets/package.json | 2 +- caravel/migrations/env.py | 12 +++++++++++- run_tests.sh | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/caravel/assets/package.json b/caravel/assets/package.json index 0c12986daf..d9d9f8b1d3 100644 --- a/caravel/assets/package.json +++ b/caravel/assets/package.json @@ -9,7 +9,7 @@ "scripts": { "test": "npm run lint && mocha --compilers js:babel-core/register --required spec/helpers/browser.js spec/**/*_spec.*", "dev": "NODE_ENV=dev webpack -d --watch --colors", - "prod": "NODE_ENV=production webpack -p --colors", + "prod": "NODE_ENV=production webpack -p --colors --progress", "lint": "npm run --silent lint:js", "lint:js": "eslint --ignore-path=.eslintignore --ext .js ." }, diff --git a/caravel/migrations/env.py b/caravel/migrations/env.py index 3a313439ba..5232c7e5c2 100755 --- a/caravel/migrations/env.py +++ b/caravel/migrations/env.py @@ -72,11 +72,21 @@ def run_migrations_online(): poolclass=pool.NullPool) connection = engine.connect() + kwargs = {} + if engine.name in ('sqlite', 'mysql'): + kwargs = { + 'transaction_per_migration': True, + 'transactional_ddl': True, + } + configure_args = current_app.extensions['migrate'].configure_args + if configure_args: + kwargs.update(configure_args) + context.configure(connection=connection, target_metadata=target_metadata, #compare_type=True, process_revision_directives=process_revision_directives, - **current_app.extensions['migrate'].configure_args) + **kwargs) try: with context.begin_transaction(): diff --git a/run_tests.sh b/run_tests.sh index 37ea9249bb..1897918576 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,9 +1,10 @@ #!/usr/bin/env bash echo $DB -rm /tmp/caravel_unittests.db +rm ~/.caravel/caravel_unittests.db rm -f .coverage export CARAVEL_CONFIG=tests.caravel_test_config set -e caravel/bin/caravel db upgrade +caravel/bin/caravel db upgrade # running twice on purpose as a test caravel/bin/caravel version -v python setup.py nosetests