Skip to content
Snippets Groups Projects
Commit 70895636 authored by kaiyou's avatar kaiyou
Browse files

Repair Alembic automatic generation

parent e0f8ed4b
No related branches found
No related tags found
No related merge requests found
Generic single-database configuration.
\ No newline at end of file
# A generic, single database configuration.
[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
......
......@@ -8,43 +8,19 @@ from sqlalchemy import pool
from alembic import context
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
# 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', current_app.config.get(
'SQLALCHEMY_DATABASE_URI').replace('%', '%%'))
target_metadata = current_app.extensions['migrate'].db.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline():
"""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
......@@ -55,29 +31,17 @@ def run_migrations_offline():
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
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,
......@@ -85,7 +49,6 @@ def run_migrations_online():
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args
)
with context.begin_transaction():
context.run_migrations()
......
......@@ -4,8 +4,10 @@ Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
import hiboo
${imports if imports else ""}
revision = ${repr(up_revision)}
......
""" Add authorization codes in the database
Revision ID: 5271f611b98b
Revises: cfb466a78348
Create Date: 2019-11-03 17:57:55.989647
"""
from alembic import op
import sqlalchemy as sa
revision = '5271f611b98b'
down_revision = 'cfb466a78348'
branch_labels = None
depends_on = None
def upgrade():
op.create_table('oidc_authorization_code',
sa.Column('code', sa.String(length=120), nullable=False),
sa.Column('client_id', sa.String(length=48), nullable=True),
sa.Column('redirect_uri', sa.Text(), nullable=True),
sa.Column('response_type', sa.Text(), nullable=True),
sa.Column('scope', sa.Text(), nullable=True),
sa.Column('auth_time', sa.Integer(), nullable=False),
sa.Column('nonce', sa.Text(), nullable=True),
sa.Column('user_id', sa.Text(), nullable=True),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('comment', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('uuid'),
sa.UniqueConstraint('code')
)
def downgrade():
op.drop_table('oidc_authorization_code')
""" empty message
Revision ID: cfb466a78348
Revises:
Create Date: 2019-10-05 17:05:31.015711
"""
from alembic import op
import sqlalchemy as sa
revision = 'cfb466a78348'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
op.create_table('service',
sa.Column('protocol', sa.String(length=25), nullable=True),
sa.Column('name', sa.String(length=255), nullable=True),
sa.Column('provider', sa.String(length=255), nullable=True),
sa.Column('application', sa.String(length=255), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.Column('policy', sa.String(length=255), nullable=True),
sa.Column('max_profiles', sa.Integer(), nullable=False),
sa.Column('config', sa.String(), nullable=True),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('comment', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('uuid')
)
op.create_table('user',
sa.Column('username', sa.String(length=255), nullable=False),
sa.Column('is_admin', sa.Boolean(), nullable=False),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('comment', sa.String(length=255), nullable=True),
sa.PrimaryKeyConstraint('uuid'),
sa.UniqueConstraint('username')
)
op.create_table('auth',
sa.Column('user_uuid', sa.String(length=36), nullable=True),
sa.Column('value', sa.String(), nullable=True),
sa.Column('extra', sa.String(), nullable=True),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('comment', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'], ),
sa.PrimaryKeyConstraint('uuid')
)
op.create_table('identity',
sa.Column('user_uuid', sa.String(length=36), nullable=True),
sa.Column('service_uuid', sa.String(length=36), nullable=True),
sa.Column('username', sa.String(length=255), nullable=False),
sa.Column('status', sa.String(length=25), nullable=False),
sa.Column('extra', sa.String(), nullable=True),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('comment', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['service_uuid'], ['service.uuid'], ),
sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'], ),
sa.PrimaryKeyConstraint('uuid')
)
op.create_table('history',
sa.Column('user_uuid', sa.String(length=36), nullable=True),
sa.Column('identity_uuid', sa.String(length=36), nullable=True),
sa.Column('service_uuid', sa.String(length=36), nullable=True),
sa.Column('actor_uuid', sa.String(length=36), nullable=True),
sa.Column('category', sa.String(length=25), nullable=True),
sa.Column('value', sa.String(), nullable=True),
sa.Column('uuid', sa.String(length=36), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('comment', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['actor_uuid'], ['user.uuid'], ),
sa.ForeignKeyConstraint(['identity_uuid'], ['identity.uuid'], ),
sa.ForeignKeyConstraint(['service_uuid'], ['service.uuid'], ),
sa.ForeignKeyConstraint(['user_uuid'], ['user.uuid'], ),
sa.PrimaryKeyConstraint('uuid')
)
def downgrade():
op.drop_table('history')
op.drop_table('identity')
op.drop_table('auth')
op.drop_table('user')
op.drop_table('service')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment