Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = get_url()
# Default code: url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True)
with context.begin_transaction():
context.run_migrations()
# TODO: Allow loading a configuration file from a different location.
paasmaker_configuration = paasmaker.common.configuration.Configuration()
paasmaker_configuration.load_from_file(['paasmaker.yml', '/etc/paasmaker/paasmaker.yml'])
paasmaker_configuration.setup_database()
engine = create_engine(paasmaker_configuration.get_flat('pacemaker.dsn'))
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
def upgrade(pyramid_env):
with context.begin_transaction():
op.add_column('abstract_agent_account',
sa.Column('full_name', sa.Unicode))
# Do stuff with the app's models here.
from assembl import models as m
db = m.get_session_maker()()
with transaction.manager:
pass
if connectable is None:
# only create Engine if we don't have a Connection
# from the outside
connectable = create_engine(engine_url)
# connectable = engine_from_config(
# config.get_section(config.config_ini_section),
# prefix='sqlalchemy.',
# poolclass=pool.NullPool)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
def upgrade(pyramid_env):
with context.begin_transaction():
op.add_column('abstract_agent_account',
sa.Column(
'profile_id',
sa.Integer,
sa.ForeignKey('agent_profile.id', ondelete='CASCADE')))
op.execute(
'''UPDATE abstract_agent_account SET profile_id=(
SELECT profile_id FROM agent_email_account
WHERE agent_email_account.id = abstract_agent_account.id)
WHERE "type" = 'agent_email_account' ''')
op.execute('''UPDATE abstract_agent_account
SET type = 'idprovider_agent_account'
WHERE type = 'idprovider_account' ''')
op.execute(
'''UPDATE abstract_agent_account SET profile_id=(
SELECT profile_id FROM idprovider_agent_account
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True)
with context.begin_transaction():
context.run_migrations()
def downgrade(pyramid_env):
with context.begin_transaction():
### commands auto generated by Alembic - please adjust! ###
pass
### end Alembic commands ###
and associate a connection with the context.
"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
In this scenario we need to create an Engine
and associate a connection with the context.
"""
url = app.config['SQLALCHEMY_DATABASE_URI']
engine = create_engine(url, poolclass=pool.NullPool)
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata,
include_symbol=include_symbol
)
try:
with context.begin_transaction():
connection.execute('SELECT pg_advisory_lock(1)')
context.run_migrations()
finally:
connection.close()
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = sqlalchemy.create_engine(
aurweb.db.get_sqlalchemy_url(),
poolclass=sqlalchemy.pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()