def upgrade():
    if context.get_impl().bind.dialect.name == "mysql":
        return
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('roles', schema=None) as batch_op:
        batch_op.create_unique_constraint(batch_op.f('uq_roles_name'),
                                          ['name'])
Esempio n. 2
0
def upgrade():
    # it possible that this script is being called on new database
    # in this case we should not do anything
    insp = reflection.Inspector.from_engine(ptah.get_base().metadata.bind)

    if "annotations" in [r["name"] for r in insp.get_columns("ptah_nodes")]:
        return

    # ptah_nodes
    op.add_column("ptah_nodes", sa.Column("annotations", ptah.JsonDictType(), default={}))

    # ptah_content
    op.add_column("ptah_content", sa.Column("lang", sa.String(12), default="en"))

    op.create_index("ix_ptah_content_path", "ptah_content", ("path",))

    # sqlite doesnt support column drop
    impl = context.get_impl()

    if impl.__dialect__ != "sqlite":
        op.drop_column("ptah_content", "view")
        op.drop_column("ptah_content", "creators")
        op.drop_column("ptah_content", "subjects")
        op.drop_column("ptah_content", "publisher")
        op.drop_column("ptah_content", "contributors")

    op.drop_table("test_sqla_table")
Esempio n. 3
0
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.

    """
    engine = engine_from_config(
        config.get_section(config.config_ini_section),
        prefix='sqlalchemy.',
        poolclass=pool.NullPool)

    target_metadata.reflect(engine)

    connection = engine.connect()
    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        include_object=include_object,
    )

    try:
        with context.begin_transaction():
            context.run_migrations()
        try:
            impl = context.get_impl().context_opts['template_args']
            downgrades = impl['downgrades']
            upgrades = impl['upgrades']
            if 'pass' in downgrades and 'pass' in upgrades:
                raise Exception("Empty migration")
        except KeyError:
            pass
    finally:
        connection.close()
Esempio n. 4
0
def upgrade():
    # it possible that this script is being called on new database
    # in this case we should not do anything
    insp = reflection.Inspector.from_engine(ptah.get_base().metadata.bind)

    if 'annotations' in [r['name'] for r in insp.get_columns('ptah_nodes')]:
        return

    # ptah_nodes
    op.add_column('ptah_nodes',
                  sa.Column('annotations', ptah.JsonDictType(), default={}))

    # ptah_content
    op.add_column('ptah_content', sa.Column('lang',
                                            sa.String(12),
                                            default='en'))

    op.create_index('ix_ptah_content_path', 'ptah_content', ('path', ))

    # sqlite doesnt support column drop
    impl = context.get_impl()

    if impl.__dialect__ != 'sqlite':
        op.drop_column('ptah_content', 'view')
        op.drop_column('ptah_content', 'creators')
        op.drop_column('ptah_content', 'subjects')
        op.drop_column('ptah_content', 'publisher')
        op.drop_column('ptah_content', 'contributors')

    op.drop_table('test_sqla_table')