From 2b0a2d561b0ea7e6868508699f1b240609a28819 Mon Sep 17 00:00:00 2001 From: Ionut Filip Date: Wed, 9 Jan 2019 12:53:59 +0200 Subject: [PATCH] Fix connection to mysql db --- core/admin/Dockerfile | 2 +- core/admin/migrations/env.py | 9 ++++++++- core/admin/migrations/versions/049fed905da7_.py | 4 ++-- core/admin/migrations/versions/5aeb5811408e_.py | 14 +++++++------- core/admin/migrations/versions/9c28df23f77e_.py | 8 ++++---- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/core/admin/Dockerfile b/core/admin/Dockerfile index b7109977..33c0bde7 100644 --- a/core/admin/Dockerfile +++ b/core/admin/Dockerfile @@ -8,7 +8,7 @@ RUN mkdir -p /app WORKDIR /app COPY requirements-prod.txt requirements.txt -RUN apk add --no-cache libressl curl postgresql-libs\ +RUN apk add --no-cache libressl curl postgresql-libs mariadb-connector-c \ && apk add --no-cache --virtual build-dep \ libressl-dev libffi-dev python3-dev build-base postgresql-dev mariadb-connector-c-dev \ && pip3 install -r requirements.txt \ diff --git a/core/admin/migrations/env.py b/core/admin/migrations/env.py index a3f9cf18..cdfd2248 100755 --- a/core/admin/migrations/env.py +++ b/core/admin/migrations/env.py @@ -72,7 +72,14 @@ def run_migrations_online(): engine = engine_from_config(config.get_section(config.config_ini_section), prefix='sqlalchemy.', poolclass=pool.NullPool) - connection = retry(engine.connect, stop=tenacity.stop_after_attempt(100), wait=tenacity.wait_random(min=2, max=5))() + + connection = tenacity.Retrying( + stop=tenacity.stop_after_attempt(100), + wait=tenacity.wait_random(min=2, max=5), + before=tenacity.before_log(logging.getLogger("tenacity.retry"), logging.DEBUG), + before_sleep=tenacity.before_sleep_log(logging.getLogger("tenacity.retry"), logging.INFO), + after=tenacity.after_log(logging.getLogger("tenacity.retry"), logging.DEBUG) + ).call(engine.connect) context.configure(connection=connection, target_metadata=target_metadata, diff --git a/core/admin/migrations/versions/049fed905da7_.py b/core/admin/migrations/versions/049fed905da7_.py index 5398ad20..d8af41d3 100644 --- a/core/admin/migrations/versions/049fed905da7_.py +++ b/core/admin/migrations/versions/049fed905da7_.py @@ -16,10 +16,10 @@ import sqlalchemy as sa def upgrade(): with op.batch_alter_table('user') as batch: - batch.alter_column('email', type_=sa.String(length=255)) + batch.alter_column('email', type_=sa.String(length=255), nullable=False) def downgrade(): with op.batch_alter_table('user') as batch: - batch.alter_column('email', type_=sa.String(length=255)) + batch.alter_column('email', type_=sa.String(length=255), nullable=False) diff --git a/core/admin/migrations/versions/5aeb5811408e_.py b/core/admin/migrations/versions/5aeb5811408e_.py index 37a2c924..2ea06ea9 100644 --- a/core/admin/migrations/versions/5aeb5811408e_.py +++ b/core/admin/migrations/versions/5aeb5811408e_.py @@ -43,18 +43,18 @@ def upgrade(): # drop foreign key constraints with op.batch_alter_table('alias') as batch_op: - batch_op.drop_constraint('alias_domain_name_fkey') + batch_op.drop_constraint('alias_domain_name_fkey', type_='foreignkey') with op.batch_alter_table('alternative') as batch_op: - batch_op.drop_constraint('alternative_domain_name_fkey') + batch_op.drop_constraint('alternative_domain_name_fkey', type_='foreignkey') with op.batch_alter_table('manager') as batch_op: - batch_op.drop_constraint('manager_domain_name_fkey') - batch_op.drop_constraint('manager_user_email_fkey') + batch_op.drop_constraint('manager_domain_name_fkey', type_='foreignkey') + batch_op.drop_constraint('manager_user_email_fkey', type_='foreignkey') with op.batch_alter_table('token') as batch_op: - batch_op.drop_constraint('token_user_email_fkey') + batch_op.drop_constraint('token_user_email_fkey', type_='foreignkey') with op.batch_alter_table('fetch') as batch_op: - batch_op.drop_constraint('fetch_user_email_fkey') + batch_op.drop_constraint('fetch_user_email_fkey', type_='foreignkey') with op.batch_alter_table('user') as batch_op: - batch_op.drop_constraint('user_domain_name_fkey') + batch_op.drop_constraint('user_domain_name_fkey', type_='foreignkey') # lower domain names for domain in connection.execute(domain_table.select()): diff --git a/core/admin/migrations/versions/9c28df23f77e_.py b/core/admin/migrations/versions/9c28df23f77e_.py index ce712761..ba3e0098 100644 --- a/core/admin/migrations/versions/9c28df23f77e_.py +++ b/core/admin/migrations/versions/9c28df23f77e_.py @@ -16,13 +16,13 @@ import sqlalchemy as sa def upgrade(): with op.batch_alter_table('user') as batch: - batch.alter_column('email', type_=sa.String(length=255)) + batch.alter_column('email', type_=sa.String(length=255), nullable=False) with op.batch_alter_table('alias') as batch: - batch.alter_column('email', type_=sa.String(length=255)) + batch.alter_column('email', type_=sa.String(length=255), nullable=False) def downgrade(): with op.batch_alter_table('user') as batch: - batch.alter_column('email', type_=sa.String(length=255)) + batch.alter_column('email', type_=sa.String(length=255), nullable=False) with op.batch_alter_table('alias') as batch: - batch.alter_column('email', type_=sa.String(length=255)) + batch.alter_column('email', type_=sa.String(length=255), nullable=False)