diff --git a/data/migrations/migration.sh b/data/migrations/migration.sh index 56f42e61e..8501090ef 100755 --- a/data/migrations/migration.sh +++ b/data/migrations/migration.sh @@ -10,7 +10,6 @@ up_mysql() { # Run a SQL database on port 3306 inside of Docker. docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql - # Sleep for 25s to get MySQL get started. echo 'Sleeping for 25...' sleep 25 @@ -27,7 +26,6 @@ up_mariadb() { # Run a SQL database on port 3306 inside of Docker. docker run --name mariadb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mariadb - # Sleep for 25s to get MySQL get started. echo 'Sleeping for 25...' sleep 25 @@ -44,7 +42,6 @@ up_percona() { # Run a SQL database on port 3306 inside of Docker. docker run --name percona -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d percona - # Sleep for 20s echo 'Sleeping for 25...' sleep 25 diff --git a/data/migrations/versions/53e2ac668296_remove_reference_to_subdir.py b/data/migrations/versions/53e2ac668296_remove_reference_to_subdir.py new file mode 100644 index 000000000..fcfc518f4 --- /dev/null +++ b/data/migrations/versions/53e2ac668296_remove_reference_to_subdir.py @@ -0,0 +1,61 @@ +"""Remove reference to subdir + +Revision ID: 53e2ac668296 +Revises: ed01e313d3cb +Create Date: 2017-03-28 15:01:31.073382 + +""" + +# revision identifiers, used by Alembic. +import json + +import logging +from alembic.script.revision import RevisionError +from alembic.util import CommandError +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql + +revision = '53e2ac668296' +down_revision = 'ed01e313d3cb' + +log = logging.getLogger(__name__) + + +def run_migration(migrate_function): + conn = op.get_bind() + triggers = conn.execute("SELECT id, config FROM repositorybuildtrigger") + for trigger in triggers: + config = json.dumps(migrate_function(json.loads(trigger[1]))) + try: + conn.execute("UPDATE repositorybuildtrigger SET config=%s WHERE id=%s", config, trigger[0]) + except(RevisionError, CommandError) as e: + log.warning("Failed to update build trigger %s with exception: ", trigger[0], e) + + +def upgrade(tables): + run_migration(delete_subdir) + + +def downgrade(tables): + run_migration(add_subdir) + + +def delete_subdir(config): + """ Remove subdir from config """ + if not config: + return config + if 'subdir' in config: + del config['subdir'] + + return config + + +def add_subdir(config): + """ Add subdir back into config """ + if not config: + return config + if 'context' in config: + config['subdir'] = config['context'] + + return config