diff --git a/mci_database/db/alembic/alembic.ini b/mci_database/db/alembic/alembic.ini index 8fee37b..cd2cb97 100644 --- a/mci_database/db/alembic/alembic.ini +++ b/mci_database/db/alembic/alembic.ini @@ -1,7 +1,7 @@ # A generic, single database configuration. [alembic] -script_location = alembic +script_location = . # template used to generate migration files # file_template = %%(rev)s_%%(slug)s diff --git a/mci_database/db/alembic/env.py b/mci_database/db/alembic/env.py index 169d487..1938a52 100644 --- a/mci_database/db/alembic/env.py +++ b/mci_database/db/alembic/env.py @@ -17,14 +17,22 @@ fileConfig(config.config_file_name) logger = logging.getLogger('alembic.env') +# Helper variable to indicate that Alembic is operating outside of an app context. +is_offline = False + # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata from flask import current_app -config.set_main_option('sqlalchemy.url', + +try: + config.set_main_option('sqlalchemy.url', current_app.config.get('SQLALCHEMY_DATABASE_URI')) -target_metadata = current_app.extensions['migrate'].db.metadata + target_metadata = current_app.extensions['migrate'].db.metadata +except RuntimeError as e: + is_offline = True + # other values from the config, defined by the needs of env.py, # can be acquired: @@ -89,7 +97,7 @@ def process_revision_directives(context, revision, directives): context.run_migrations() -if context.is_offline_mode(): +if context.is_offline_mode() or is_offline: run_migrations_offline() else: run_migrations_online() diff --git a/mci_database/db/alembic/versions/3b012868551d_.py b/mci_database/db/alembic/versions/3b012868551d_.py new file mode 100644 index 0000000..9ba3b3b --- /dev/null +++ b/mci_database/db/alembic/versions/3b012868551d_.py @@ -0,0 +1,26 @@ +"""empty message + +Revision ID: 3b012868551d +Revises: 3187a44ef222 +Create Date: 2019-06-20 21:56:27.664585 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '3b012868551d' +down_revision = '3187a44ef222' +branch_labels = None +depends_on = None + +def upgrade(): + op.add_column('individual', sa.Column( + 'telephone_2', sa.String(length=20), nullable=True)) + op.add_column('individual', sa.Column( + 'telephone_3', sa.String(length=20), nullable=True)) + +def downgrade(): + op.drop_column('individual', 'telephone_2') + op.drop_column('individual', 'telephone_3')