コード例 #1
0
 def _create_storm_database(self, revision):
     version_table = Table(
         'version',
         Model.metadata,
         Column('id', Integer, primary_key=True),
         Column('component', SAUnicode),
         Column('version', SAUnicode),
     )
     version_table.create(config.db.engine)
     config.db.store.execute(version_table.insert().values(
         component='schema', version=revision))
     config.db.commit()
     # Other Storm specific changes, those SQL statements hopefully work on
     # all DB engines...
     config.db.engine.execute(
         'ALTER TABLE mailinglist ADD COLUMN acceptable_aliases_id INT')
     # In case of MySQL, you cannot create/drop indexes on primary keys
     # manually as it is handled automatically by MySQL.
     if not is_mysql(config.db.engine):
         Index('ix_user__user_id').drop(bind=config.db.engine)
         # Don't pollute our main metadata object, create a new one.
         md = MetaData()
         user_table = Model.metadata.tables['user'].tometadata(md)
         Index('ix_user_user_id',
               user_table.c._user_id).create(bind=config.db.engine)
     config.db.commit()
def downgrade():
    op.drop_index(op.f('ix_address_email'), table_name='address')
    # MySQL automatically creates and removes the indexes for primary keys.
    # So, you cannot drop it without removing the foreign key constraint.
    if not is_mysql(op.get_bind()):
        op.drop_index(op.f('ix_member_user_id'), table_name='member')
        op.drop_index(op.f('ix_member_preferences_id'), table_name='member')
        op.drop_index(op.f('ix_member_address_id'), table_name='member')
コード例 #3
0
def maybe_truncate_mysql(value):
    # For MySQL, column type SAUnicode is VARCHAR(255).  In many MySQL
    # configurations, attempts to store longer values are fatal.
    if is_mysql(config.db.engine) and len(value) > 255:
        # This actually is covered but only if db is MySQL.
        print(  # pragma: nocover
            """Length of value for {} is {} which is too long for MySQL.
Truncated from {}
to {}""".format(key, len(value), value, value[:255]),
            file=sys.stderr)
        return value[:255]  # pragma: nocover
    return value
コード例 #4
0
def downgrade():
    with op.batch_alter_table('headermatch') as batch_op:
        batch_op.drop_index(op.f('ix_headermatch_position'))
        batch_op.drop_column('position')

        if not is_mysql(op.get_bind()):
            # MySQL automatically creates and removes the indexes for primary
            # keys.  So, you cannot drop it without removing the foreign key
            # constraint.
            batch_op.drop_index(op.f('ix_headermatch_mailing_list_id'))
            # MySQL doesn't allow changing columns used in foreign_key
            # constraints.
            batch_op.alter_column(
                'mailing_list_id', existing_type=sa.INTEGER(), nullable=True)
コード例 #5
0
    def _drop_storm_database(self):
        """Remove the leftovers from a Storm DB.

        A drop_all() must be issued afterwards.
        """
        if 'version' in Model.metadata.tables:
            version = Model.metadata.tables['version']
            version.drop(config.db.engine, checkfirst=True)
            Model.metadata.remove(version)
        # If it's nonexistent, PostgreSQL raises a ProgrammingError while
        # SQLite raises an OperationalError. Since MySQL automatically handles
        # indexes for primary keys, don't try doing it with that backend.
        if not is_mysql(config.db.engine):
            with suppress(ProgrammingError, OperationalError):
                Index('ix_user_user_id').drop(bind=config.db.engine)
        config.db.commit()
def upgrade():
    op.create_index(op.f('ix_address_email'),
                    'address', ['email'],
                    unique=False)
    # MySQL automatically creates the indexes for primary keys so don't need
    # to do it explicitly again.
    if not is_mysql(op.get_bind()):
        op.create_index(op.f('ix_member_address_id'),
                        'member', ['address_id'],
                        unique=False)
        op.create_index(op.f('ix_member_preferences_id'),
                        'member', ['preferences_id'],
                        unique=False)
        op.create_index(op.f('ix_member_user_id'),
                        'member', ['user_id'],
                        unique=False)
コード例 #7
0
def upgrade():
    with op.batch_alter_table('headermatch') as batch_op:
        batch_op.add_column(
            sa.Column('position', sa.Integer(), nullable=True))
        batch_op.create_index(
            op.f('ix_headermatch_position'), ['position'], unique=False)
        if not is_mysql(op.get_bind()):
            # MySQL automatically creates indexes for primary keys.
            batch_op.create_index(
                op.f('ix_headermatch_mailing_list_id'), ['mailing_list_id'],
                unique=False)
            # MySQL doesn't allow changing columns used in a foreign key
            # constrains since MySQL version 5.6.  We need to drop the
            # constraint before changing the column.  But, since the
            # constraint name is auto-generated, we can't really hardcode the
            # name here to use batch_op.drop_constraint().  Until we have a
            # better fix for this, it should be safe to skip this.
            batch_op.alter_column(
                'mailing_list_id', existing_type=sa.INTEGER(), nullable=False)