Skip to content

Commit

Permalink
task: Create migration (manually) and start to hack env.py
Browse files Browse the repository at this point in the history
  • Loading branch information
reginafcompton committed Jun 21, 2019
1 parent 6f8c003 commit c4532db
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mci_database/db/alembic/alembic.ini
Original file line number Diff line number Diff line change
@@ -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

Expand Down
14 changes: 11 additions & 3 deletions mci_database/db/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
26 changes: 26 additions & 0 deletions mci_database/db/alembic/versions/3b012868551d_.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit c4532db

Please sign in to comment.