Python sqlalchemy.Integer() Examples

The following are code examples for showing how to use sqlalchemy.Integer(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: flasky   Author: RoseOu   File: 51f5ccfba190_comments.py    MIT License 7 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('comments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('body_html', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('disabled', sa.Boolean(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.Column('post_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_comments_timestamp', 'comments', ['timestamp'], unique=False)
    ### end Alembic commands ### 
Example 2
Project: flasky   Author: RoseOu   File: base.py    MIT License 6 votes vote down vote up
def visit_typeclause(self, typeclause):
        type_ = typeclause.type.dialect_impl(self.dialect)
        if isinstance(type_, sqltypes.Integer):
            if getattr(type_, 'unsigned', False):
                return 'UNSIGNED INTEGER'
            else:
                return 'SIGNED INTEGER'
        elif isinstance(type_, sqltypes.TIMESTAMP):
            return 'DATETIME'
        elif isinstance(type_, (sqltypes.DECIMAL, sqltypes.DateTime,
                                sqltypes.Date, sqltypes.Time)):
            return self.dialect.type_compiler.process(type_)
        elif isinstance(type_, sqltypes.String) \
                and not isinstance(type_, (ENUM, SET)):
            adapted = CHAR._adapt_string_for_cast(type_)
            return self.dialect.type_compiler.process(adapted)
        elif isinstance(type_, sqltypes._Binary):
            return 'BINARY'
        elif isinstance(type_, sqltypes.NUMERIC):
            return self.dialect.type_compiler.process(
                type_).replace('NUMERIC', 'DECIMAL')
        else:
            return None 
Example 3
Project: comport   Author: codeforamerica   File: 33fcc9c4867_.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('citizen_complaint',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('department_id', sa.Integer(), nullable=False),
    sa.Column('opaque_id', sa.String(length=255), nullable=False),
    sa.Column('occured_date', sa.DateTime(), nullable=True),
    sa.Column('division', sa.String(length=255), nullable=True),
    sa.Column('precinct', sa.String(length=255), nullable=True),
    sa.Column('shift', sa.String(length=255), nullable=True),
    sa.Column('beat', sa.String(length=255), nullable=True),
    sa.Column('disposition', sa.String(length=255), nullable=True),
    sa.Column('census_tract', sa.String(length=255), nullable=True),
    sa.Column('resident_race', sa.String(length=255), nullable=True),
    sa.Column('officer_race', sa.String(length=255), nullable=True),
    sa.Column('resident_sex', sa.String(length=255), nullable=True),
    sa.Column('officer_sex', sa.String(length=255), nullable=True),
    sa.Column('officer_identifier', sa.String(length=255), nullable=True),
    sa.Column('officer_years_of_service', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('opaque_id')
    )
    ### end Alembic commands ### 
Example 4
Project: comport   Author: codeforamerica   File: 720df9948a25_.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def upgrade():
    op.create_table(
        'assaults_on_officers',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('department_id', sa.Integer(), nullable=False),
        sa.Column('opaque_id', sa.String(length=255), nullable=False),
        sa.Column('officer_identifier', sa.String(length=255), nullable=True),
        sa.Column('service_type', sa.String(length=255), nullable=True),
        sa.Column('force_type', sa.String(length=255), nullable=True),
        sa.Column('assignment', sa.String(length=255), nullable=True),
        sa.Column('arrest_made', sa.Boolean(), nullable=True),
        sa.Column('officer_injured', sa.Boolean(), nullable=True),
        sa.Column('officer_killed', sa.Boolean(), nullable=True),
        sa.Column('report_filed', sa.Boolean(), nullable=True),
        sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
        sa.PrimaryKeyConstraint('id')
    ) 
Example 5
Project: comport   Author: codeforamerica   File: 52979aa7977_.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=80), nullable=False),
    sa.Column('email', sa.String(length=80), nullable=False),
    sa.Column('password', sa.String(length=128), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('first_name', sa.String(length=30), nullable=True),
    sa.Column('last_name', sa.String(length=30), nullable=True),
    sa.Column('active', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email'),
    sa.UniqueConstraint('username')
    )
    op.create_table('roles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=80), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ### 
Example 6
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 001_cell_mapping.py    Apache License 2.0 6 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    cell_mappings = Table('cell_mappings', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('uuid', String(length=36), nullable=False),
        Column('name', String(length=255)),
        Column('transport_url', Text()),
        Column('database_connection', Text()),
        UniqueConstraint('uuid', name='uniq_cell_mappings0uuid'),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    # NOTE(mriedem): DB2 creates an index when a unique constraint is created
    # so trying to add a second index on the uuid column will fail with
    # error SQL0605W, so omit the index in the case of DB2.
    if migrate_engine.name != 'ibm_db_sa':
        Index('uuid_idx', cell_mappings.c.uuid)

    cell_mappings.create(checkfirst=True) 
Example 7
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 004_add_request_spec.py    Apache License 2.0 6 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    request_specs = Table('request_specs', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('instance_uuid', String(36), nullable=False),
        Column('spec', Text, nullable=False),
        UniqueConstraint('instance_uuid',
            name='uniq_request_specs0instance_uuid'),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    # NOTE(mriedem): DB2 creates an index when a unique constraint is created
    # so trying to add a second index on the host column will fail with error
    # SQL0605W, so omit the index in the case of DB2.
    if migrate_engine.name != 'ibm_db_sa':
        Index('request_spec_instance_uuid_idx', request_specs.c.instance_uuid)

    request_specs.create(checkfirst=True) 
Example 8
Project: call-forwarding-flask   Author: TwilioDevEd   File: 06a8443ce88f_.py    MIT License 6 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('states',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('zipcodes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('zipcode', sa.String(), nullable=False),
    sa.Column('state', sa.String(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('senators',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('state_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('phone', sa.String(), nullable=False),
    sa.ForeignKeyConstraint(['state_id'], ['states.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ### 
Example 9
Project: gnocchi   Author: gnocchixyz   File: sqlalchemy_base.py    Apache License 2.0 6 votes vote down vote up
def revision(cls):
        tablename_compact = cls.__tablename__
        if tablename_compact.endswith("_history"):
            tablename_compact = tablename_compact[:-6]
        return sqlalchemy.Column(
            sqlalchemy.Integer,
            sqlalchemy.ForeignKey(
                'resource_history.revision',
                ondelete="CASCADE",
                name="fk_%s_revision_rh_revision"
                % tablename_compact,
                # NOTE(sileht): We use to ensure that postgresql
                # does not use AccessExclusiveLock on destination table
                use_alter=True),
            primary_key=True
        ) 
Example 10
Project: vk-channelify   Author: reo7sp   File: f5f69376d382_.py    MIT License 6 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('channels',
    sa.Column('channel_id', sa.String(), nullable=False),
    sa.Column('vk_group_id', sa.String(), nullable=False),
    sa.Column('last_vk_post_id', sa.Integer(), server_default='0', nullable=False),
    sa.Column('owner_id', sa.String(), nullable=True),
    sa.Column('owner_username', sa.String(), nullable=True),
    sa.Column('hashtag_filter', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('channel_id')
    )
    op.create_table('disabled_channels',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('vk_group_id', sa.String(), nullable=True),
    sa.Column('last_vk_post_id', sa.Integer(), nullable=True),
    sa.Column('owner_id', sa.String(), nullable=True),
    sa.Column('owner_username', sa.String(), nullable=True),
    sa.Column('hashtag_filter', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ### 
Example 11
Project: telethon-session-sqlalchemy   Author: tulir   File: sqlalchemy.py    MIT License 6 votes vote down vote up
def check_and_upgrade_database(self) -> None:
        row = self.Version.query.all()
        version = row[0].version if row else 1
        if version == LATEST_VERSION:
            return

        self.Version.query.delete()

        if version == 1:
            self.UpdateState.__table__.create(self.db_engine)
            version = 3
        elif version == 2:
            self._add_column(self.UpdateState, Column(type=Integer, name="unread_count"))

        self.db.add(self.Version(version=version))
        self.db.commit() 
Example 12
Project: flasky   Author: RoseOu   File: 1b966e7f4b9e_post_model.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('posts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_posts_timestamp', 'posts', ['timestamp'], unique=False)
    ### end Alembic commands ### 
Example 13
Project: flasky   Author: RoseOu   File: 2356a38169ea_followers.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('follows',
    sa.Column('follower_id', sa.Integer(), nullable=False),
    sa.Column('followed_id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['followed_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['follower_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('follower_id', 'followed_id')
    )
    ### end Alembic commands ### 
Example 14
Project: flasky   Author: RoseOu   File: 38c4e85512a9_initial_migration.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('roles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=64), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_users_username', 'users', ['username'], unique=True)
    ### end Alembic commands ### 
Example 15
Project: flasky   Author: RoseOu   File: test_insert.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('autoinc_pk', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('data', String(50))
              )

        Table('manual_pk', metadata,
              Column('id', Integer, primary_key=True, autoincrement=False),
              Column('data', String(50))
              ) 
Example 16
Project: flasky   Author: RoseOu   File: test_insert.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('autoinc_pk', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('data', String(50))
              )
        Table('manual_pk', metadata,
              Column('id', Integer, primary_key=True, autoincrement=False),
              Column('data', String(50))
              ) 
Example 17
Project: flasky   Author: RoseOu   File: test_insert.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('autoinc_pk', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('data', String(50))
              ) 
Example 18
Project: flasky   Author: RoseOu   File: test_ddl.py    MIT License 5 votes vote down vote up
def _simple_fixture(self):
        return Table('test_table', self.metadata,
                     Column('id', Integer, primary_key=True,
                            autoincrement=False),
                     Column('data', String(50))
                     ) 
Example 19
Project: flasky   Author: RoseOu   File: test_types.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('unicode_table', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('unicode_data', cls.datatype),
              ) 
Example 20
Project: flasky   Author: RoseOu   File: test_types.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('text_table', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('text_data', Text),
              ) 
Example 21
Project: flasky   Author: RoseOu   File: test_types.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('date_table', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('date_data', cls.datatype),
              ) 
Example 22
Project: flasky   Author: RoseOu   File: test_types.py    MIT License 5 votes vote down vote up
def test_literal(self):
        self._literal_round_trip(Integer, [5], [5]) 
Example 23
Project: flasky   Author: RoseOu   File: test_types.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('boolean_table', metadata,
              Column('id', Integer, primary_key=True, autoincrement=False),
              Column('value', Boolean),
              Column('unconstrained_value', Boolean(create_constraint=False)),
              ) 
Example 24
Project: flasky   Author: RoseOu   File: test_results.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('plain_pk', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(50))
              )
        Table('has_dates', metadata,
              Column('id', Integer, primary_key=True),
              Column('today', DateTime)
              ) 
Example 25
Project: flasky   Author: RoseOu   File: test_results.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        cls.tables.percent_table = Table('percent%table', metadata,
                                         Column("percent%", Integer),
                                         Column(
                                             "spaces % more spaces", Integer),
                                         )
        cls.tables.lightweight_percent_table = sql.table(
            'percent%table', sql.column("percent%"),
            sql.column("spaces % more spaces")
        ) 
Example 26
Project: flasky   Author: RoseOu   File: test_reflection.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table('test_table', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(50))
              ) 
Example 27
Project: flasky   Author: RoseOu   File: test_reflection.py    MIT License 5 votes vote down vote up
def _test_get_unique_constraints(self, schema=None):
        uniques = sorted(
            [
                {'name': 'unique_a', 'column_names': ['a']},
                {'name': 'unique_a_b_c', 'column_names': ['a', 'b', 'c']},
                {'name': 'unique_c_a_b', 'column_names': ['c', 'a', 'b']},
                {'name': 'unique_asc_key', 'column_names': ['asc', 'key']},
            ],
            key=operator.itemgetter('name')
        )
        orig_meta = self.metadata
        table = Table(
            'testtbl', orig_meta,
            Column('a', sa.String(20)),
            Column('b', sa.String(30)),
            Column('c', sa.Integer),
            # reserved identifiers
            Column('asc', sa.String(30)),
            Column('key', sa.String(30)),
            schema=schema
        )
        for uc in uniques:
            table.append_constraint(
                sa.UniqueConstraint(*uc['column_names'], name=uc['name'])
            )
        orig_meta.create_all()

        inspector = inspect(orig_meta.bind)
        reflected = sorted(
            inspector.get_unique_constraints('testtbl', schema=schema),
            key=operator.itemgetter('name')
        )

        for orig, refl in zip(uniques, reflected):
            eq_(orig, refl) 
Example 28
Project: flasky   Author: RoseOu   File: test_select.py    MIT License 5 votes vote down vote up
def define_tables(cls, metadata):
        Table("some_table", metadata,
              Column('id', Integer, primary_key=True),
              Column('x', Integer),
              Column('y', Integer),
              Column('q', String(50)),
              Column('p', String(50))
              ) 
Example 29
Project: flasky   Author: RoseOu   File: base.py    MIT License 5 votes vote down vote up
def format_server_default(compiler, default):
    return compiler.get_column_default_string(
                Column("x", Integer, server_default=default)
            ) 
Example 30
Project: flasky   Author: RoseOu   File: operations.py    MIT License 5 votes vote down vote up
def _check_constraint(self, name, source, condition, schema=None, **kw):
        t = sa_schema.Table(source, sa_schema.MetaData(),
                    sa_schema.Column('x', Integer), schema=schema)
        ck = sa_schema.CheckConstraint(condition, name=name, **kw)
        t.append_constraint(ck)
        return ck 
Example 31
Project: comport   Author: codeforamerica   File: 0de6730e3d41_create_wpd_complaints_table.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    op.create_table(
        'citizen_complaints_wpd',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('department_id', sa.Integer(), sa.ForeignKey('departments.id'), nullable=False),
        sa.Column('opaque_id', sa.String(255), unique=False, nullable=True),
        sa.Column('received_date', sa.DateTime, unique=False, nullable=True),
        sa.Column('division', sa.String(255), unique=False, nullable=True),
        sa.Column('bureau', sa.String(255), unique=False, nullable=True),
        sa.Column('shift', sa.String(255), unique=False, nullable=True),
        sa.Column('service_type', sa.String(255), unique=False, nullable=True),
        sa.Column('source', sa.String(255), unique=False, nullable=True),
        sa.Column('incident_type', sa.String(255), unique=False, nullable=True),
        sa.Column('allegation', sa.String(255), unique=False, nullable=True),
        sa.Column('finding', sa.String(255), unique=False, nullable=True),
        sa.Column('disposition', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_id', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_race', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_sex', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_age', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_id', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_race', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_sex', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_age', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_years_of_service', sa.String(255), unique=False, nullable=True),
        sa.ForeignKeyConstraint(['department_id'], ['departments.id']),
        sa.PrimaryKeyConstraint('id')
    ) 
Example 32
Project: comport   Author: codeforamerica   File: 4ffa73ef2b8_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('chart_block_defaults',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('caption', sa.String(length=255), nullable=True),
    sa.Column('slug', sa.String(length=255), nullable=False),
    sa.Column('dataset', sa.String(length=255), nullable=False),
    sa.Column('content', sa.Text(convert_unicode=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('chart_blocks',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('department_id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('caption', sa.String(length=255), nullable=True),
    sa.Column('slug', sa.String(length=255), nullable=False),
    sa.Column('dataset', sa.String(length=255), nullable=False),
    sa.Column('content', sa.Text(), nullable=True),
    sa.Column('date_updated', sa.DateTime(), nullable=True),
    sa.Column('date_edited', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('use_of_force_incidents', sa.Column('received_date', sa.DateTime(), nullable=True))
    ### end Alembic commands ### 
Example 33
Project: comport   Author: codeforamerica   File: 1392585412d_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('departments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=80), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_index(op.f('ix_departments_id'), 'departments', ['id'], unique=False)
    ### end Alembic commands ### 
Example 34
Project: comport   Author: codeforamerica   File: 32d7cc46df4_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('demographic_values',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('department_id', sa.Integer(), nullable=False),
    sa.Column('race', sa.String(length=255), nullable=True),
    sa.Column('gender', sa.String(length=255), nullable=True),
    sa.Column('count', sa.Integer(), nullable=True),
    sa.Column('department_value', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ### 
Example 35
Project: comport   Author: codeforamerica   File: 507f3182b84_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('denominator_values', sa.Column('officers_out_on_service', sa.Integer(), nullable=True))
    op.drop_column('denominator_values', 'arrests')
    ### end Alembic commands ### 
Example 36
Project: comport   Author: codeforamerica   File: 3df24031e72_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('links',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('department_id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=255), nullable=False),
    sa.Column('url', sa.String(length=2083), nullable=False),
    sa.Column('type', sa.String(length=255), nullable=False),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ### 
Example 37
Project: comport   Author: codeforamerica   File: 28296e3a641_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('department_id', sa.Integer(), nullable=True))
    op.create_foreign_key(None, 'users', 'departments', ['department_id'], ['id'])
    ### end Alembic commands ### 
Example 38
Project: comport   Author: codeforamerica   File: 875c52a485_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('use_of_force_incidents',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('opaque_id', sa.String(length=255), nullable=False),
    sa.Column('month', sa.Integer(), nullable=True),
    sa.Column('year', sa.Integer(), nullable=True),
    sa.Column('department_id', sa.Integer(), nullable=True),
    sa.Column('status', sa.String(length=255), nullable=True),
    sa.Column('disposition', sa.String(length=255), nullable=True),
    sa.Column('service_type', sa.String(length=255), nullable=True),
    sa.Column('day_of_week', sa.String(length=255), nullable=True),
    sa.Column('hour', sa.Integer(), nullable=True),
    sa.Column('arrest_made', sa.Boolean(), nullable=True),
    sa.Column('arrest_charges', sa.String(length=255), nullable=True),
    sa.Column('citizen_hospitalized', sa.Boolean(), nullable=True),
    sa.Column('citizen_injured', sa.Boolean(), nullable=True),
    sa.Column('officer_injured', sa.Boolean(), nullable=True),
    sa.Column('officer_hospitalized', sa.Boolean(), nullable=True),
    sa.Column('use_of_force_reason', sa.String(length=255), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('opaque_id')
    )
    op.drop_table('serviceTypes')
    op.drop_table('months')
    ### end Alembic commands ### 
Example 39
Project: comport   Author: codeforamerica   File: fecca96b9d_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('use_of_force_incidents', 'officer_years_of_service')
    op.add_column('use_of_force_incidents', sa.Column('officer_years_of_service', sa.Integer(), nullable=True))
    ### end Alembic commands ### 
Example 40
Project: comport   Author: codeforamerica   File: f0526891fa_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('extractors', sa.Column('next_month', sa.Integer(), nullable=True))
    op.add_column('extractors', sa.Column('next_year', sa.Integer(), nullable=True))
    ### end Alembic commands ### 
Example 41
Project: comport   Author: codeforamerica   File: c21533f2fd07_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    # create the incidents_updated table
    op.create_table(
        'incidents_updated',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('department_id', sa.Integer(), nullable=False),
        sa.Column('opaque_id', sa.String(length=255), nullable=False),
        sa.Column('incident_type', sa.String(length=32), nullable=False),
        sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_incidents_updated_opaque_id'), 'incidents_updated', ['opaque_id'], unique=False) 
Example 42
Project: comport   Author: codeforamerica   File: 17b38c3d5e7_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('serviceTypes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('month_id', sa.Integer(), nullable=True),
    sa.Column('service_type', sa.String(length=36), nullable=False),
    sa.Column('count', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['month_id'], ['months.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ### 
Example 43
Project: comport   Author: codeforamerica   File: 24987646046_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('use_of_force_incidents', sa.Column('officer_years_of_service', sa.Integer(), nullable=True))
    ### end Alembic commands ### 
Example 44
Project: comport   Author: codeforamerica   File: 43bdec0aeb4_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('invite_codes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('department_id', sa.Integer(), nullable=True),
    sa.Column('code', sa.String(length=36), nullable=False),
    sa.Column('used', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('code')
    )
    op.create_index(op.f('ix_invite_codes_id'), 'invite_codes', ['id'], unique=False)
    ### end Alembic commands ### 
Example 45
Project: comport   Author: codeforamerica   File: 52eaf89477f_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_department_relationship_table',
    sa.Column('department_id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('department_id', 'user_id')
    )
    ### end Alembic commands ### 
Example 46
Project: comport   Author: codeforamerica   File: 331c513e8d4_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('months',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('month', sa.Integer(), nullable=True),
    sa.Column('year', sa.Integer(), nullable=True),
    sa.Column('department_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ### 
Example 47
Project: comport   Author: codeforamerica   File: 1a869ac514c_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('interesteds',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=False),
    sa.Column('agency', sa.String(length=255), nullable=False),
    sa.Column('location', sa.String(length=255), nullable=False),
    sa.Column('phone', sa.String(length=255), nullable=False),
    sa.Column('email', sa.String(length=255), nullable=False),
    sa.Column('comments', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ### 
Example 48
Project: comport   Author: codeforamerica   File: 1826863c726a_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    op.create_table(
        'use_of_force_incidents_lmpd',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('department_id', sa.Integer(), nullable=False),
        sa.Column('opaque_id', sa.String(length=255), nullable=False),
        sa.Column('occured_date', sa.DateTime(), nullable=True),
        sa.Column('bureau', sa.String(length=255), nullable=True),
        sa.Column('division', sa.String(length=255), nullable=True),
        sa.Column('unit', sa.String(length=255), nullable=True),
        sa.Column('platoon', sa.String(length=255), nullable=True),
        sa.Column('disposition', sa.String(length=255), nullable=True),
        sa.Column('use_of_force_reason', sa.String(length=255), nullable=True),
        sa.Column('officer_force_type', sa.String(length=255), nullable=True),
        sa.Column('service_type', sa.String(length=255), nullable=True),
        sa.Column('arrest_made', sa.Boolean(), nullable=True),
        sa.Column('arrest_charges', sa.String(length=255), nullable=True),
        sa.Column('resident_injured', sa.Boolean(), nullable=True),
        sa.Column('resident_hospitalized', sa.Boolean(), nullable=True),
        sa.Column('resident_condition', sa.String(length=255), nullable=True),
        sa.Column('officer_injured', sa.Boolean(), nullable=True),
        sa.Column('officer_hospitalized', sa.Boolean(), nullable=True),
        sa.Column('officer_condition', sa.String(length=255), nullable=True),
        sa.Column('resident_identifier', sa.String(length=255), nullable=True),
        sa.Column('resident_weapon_used', sa.String(length=255), nullable=True),
        sa.Column('resident_race', sa.String(length=255), nullable=True),
        sa.Column('resident_sex', sa.String(length=255), nullable=True),
        sa.Column('resident_age', sa.String(length=255), nullable=True),
        sa.Column('officer_race', sa.String(length=255), nullable=True),
        sa.Column('officer_sex', sa.String(length=255), nullable=True),
        sa.Column('officer_age', sa.String(length=255), nullable=True),
        sa.Column('officer_years_of_service', sa.String(length=255), nullable=True),
        sa.Column('officer_identifier', sa.String(length=255), nullable=True),
        sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
        sa.PrimaryKeyConstraint('id')
    ) 
Example 49
Project: comport   Author: codeforamerica   File: 3bc88a29a22_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('citizen_complaints', 'officer_years_of_service')
    op.add_column('citizen_complaints', sa.Column('officer_years_of_service', sa.Integer(), nullable=True))
    ### end Alembic commands ### 
Example 50
Project: comport   Author: codeforamerica   File: 4d1cde26d807_create_wpd_uof_table.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    op.create_table(
        'use_of_force_incidents_wpd',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('department_id', sa.Integer(), sa.ForeignKey('departments.id'), nullable=False),
        sa.Column('opaque_id', sa.String(255), unique=False, nullable=True),
        sa.Column('received_date', sa.DateTime, unique=False, nullable=True),
        sa.Column('division', sa.String(255), unique=False, nullable=True),
        sa.Column('bureau', sa.String(255), unique=False, nullable=True),
        sa.Column('shift', sa.String(255), unique=False, nullable=True),
        sa.Column('use_of_force_reason', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_resist_type', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_resistance', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_force_type', sa.String(255), unique=False, nullable=True),
        sa.Column('arrest_charges', sa.String(255), unique=False, nullable=True),
        sa.Column('disposition', sa.String(255), unique=False, nullable=True),
        sa.Column('service_type', sa.String(255), unique=False, nullable=True),
        sa.Column('arrest_made', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_id', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_injured', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_hospitalized', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_condition', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_race', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_sex', sa.String(255), unique=False, nullable=True),
        sa.Column('citizen_age', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_id', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_injured', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_hospitalized', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_race', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_sex', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_age', sa.String(255), unique=False, nullable=True),
        sa.Column('officer_years_of_service', sa.String(255), unique=False, nullable=True),
        sa.ForeignKeyConstraint(['department_id'], ['departments.id']),
        sa.PrimaryKeyConstraint('id')
    ) 
Example 51
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 003_host_mapping.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    cell_mappings = Table('cell_mappings', meta, autoload=True)
    host_mappings = Table('host_mappings', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('cell_id', Integer, nullable=False),
        Column('host', String(length=255), nullable=False),
        UniqueConstraint('host',
            name='uniq_host_mappings0host'),
        ForeignKeyConstraint(columns=['cell_id'],
            refcolumns=[cell_mappings.c.id]),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    # NOTE(mriedem): DB2 creates an index when a unique constraint is created
    # so trying to add a second index on the host column will fail with error
    # SQL0605W, so omit the index in the case of DB2.
    if migrate_engine.name != 'ibm_db_sa':
        Index('host_idx', host_mappings.c.host)

    host_mappings.create(checkfirst=True) 
Example 52
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 002_instance_mapping.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    cell_mappings = Table('cell_mappings', meta, autoload=True)
    instance_mappings = Table('instance_mappings', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('instance_uuid', String(length=36), nullable=False),
        Column('cell_id', Integer, nullable=False),
        Column('project_id', String(length=255), nullable=False),
        UniqueConstraint('instance_uuid',
            name='uniq_instance_mappings0instance_uuid'),
        Index('project_id_idx', 'project_id'),
        ForeignKeyConstraint(columns=['cell_id'],
            refcolumns=[cell_mappings.c.id]),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    # NOTE(mriedem): DB2 creates an index when a unique constraint is created
    # so trying to add a second index on the instance_uuid column will fail
    # with error SQL0605W, so omit the index in the case of DB2.
    if migrate_engine.name != 'ibm_db_sa':
        Index('instance_uuid_idx', instance_mappings.c.instance_uuid)

    instance_mappings.create(checkfirst=True) 
Example 53
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 006_build_request.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    request_specs = Table('request_specs', meta, autoload=True)
    build_requests = Table('build_requests', meta,
        Column('created_at', DateTime),
        Column('updated_at', DateTime),
        Column('id', Integer, primary_key=True, nullable=False),
        Column('request_spec_id', Integer, nullable=False),
        Column('project_id', String(length=255), nullable=False),
        Column('user_id', String(length=255), nullable=False),
        Column('display_name', String(length=255)),
        Column('instance_metadata', Text),
        Column('progress', Integer),
        Column('vm_state', String(length=255)),
        Column('task_state', String(length=255)),
        Column('image_ref', String(length=255)),
        Column('access_ip_v4', InetSmall()),
        Column('access_ip_v6', InetSmall()),
        Column('info_cache', Text),
        Column('security_groups', Text, nullable=False),
        Column('config_drive', Boolean, default=False, nullable=False),
        Column('key_name', String(length=255)),
        Column('locked_by', Enum('owner', 'admin',
            name='build_requests0locked_by')),
        UniqueConstraint('request_spec_id',
            name='uniq_build_requests0request_spec_id'),
        Index('build_requests_project_id_idx', 'project_id'),
        ForeignKeyConstraint(columns=['request_spec_id'],
            refcolumns=[request_specs.c.id]),
        mysql_engine='InnoDB',
        mysql_charset='utf8'
    )

    build_requests.create(checkfirst=True) 
Example 54
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 299_service_version_number.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    services = Table('services', meta, autoload=True)
    shadow_services = Table('shadow_services', meta, autoload=True)
    services.create_column(Column('version', Integer, default=0))
    shadow_services.create_column(Column('version', Integer,
                                         default=0)) 
Example 55
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 252_add_instance_extra_table.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    columns = [
        (('created_at', DateTime), {}),
        (('updated_at', DateTime), {}),
        (('deleted_at', DateTime), {}),
        (('deleted', Integer), {}),
        (('id', Integer), dict(primary_key=True, nullable=False)),
        (('instance_uuid', String(length=36)), dict(nullable=False)),
        (('numa_topology', Text), dict(nullable=True)),
     ]
    for prefix in ('', 'shadow_'):
        instances = Table(prefix + 'instances', meta, autoload=True)
        basename = prefix + 'instance_extra'
        if migrate_engine.has_table(basename):
            continue
        _columns = tuple([Column(*args, **kwargs)
                          for args, kwargs in columns])
        table = Table(basename, meta, *_columns, mysql_engine='InnoDB',
                      mysql_charset='utf8')
        table.create()

        # Index
        instance_uuid_index = Index(basename + '_idx',
                                    table.c.instance_uuid)
        instance_uuid_index.create(migrate_engine)

        # Foreign key
        # NOTE(mriedem): DB2 won't create the ForeignKey over the
        # instances.uuid column since it doesn't have a UniqueConstraint (added
        # later in the 267 migration). The ForeignKey will be created for DB2
        # in the 296 migration.
        if not prefix and migrate_engine.name != 'ibm_db_sa':
            fkey_columns = [table.c.instance_uuid]
            fkey_refcolumns = [instances.c.uuid]
            instance_fkey = ForeignKeyConstraint(
                columns=fkey_columns, refcolumns=fkey_refcolumns)
            instance_fkey.create() 
Example 56
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 269_add_numa_node_column.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData(bind=migrate_engine)

    # Add a new column to store PCI device numa node
    pci_devices = Table('pci_devices', meta, autoload=True)
    shadow_pci_devices = Table('shadow_pci_devices', meta, autoload=True)

    numa_node = Column('numa_node', Integer, default=None)
    if not hasattr(pci_devices.c, 'numa_node'):
        pci_devices.create_column(numa_node)
    if not hasattr(shadow_pci_devices.c, 'numa_node'):
        shadow_pci_devices.create_column(numa_node.copy()) 
Example 57
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_db_api.py    Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestSqlalchemyTypesRepr, self).setUp()
        meta = MetaData(bind=self.engine)
        self.table = Table(
            'cidr_tbl',
            meta,
            Column('id', Integer, primary_key=True),
            Column('addr', col_types.CIDR())
        )
        self.table.create()
        self.addCleanup(meta.drop_all) 
Example 58
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_migration_utils.py    Apache License 2.0 5 votes vote down vote up
def test_check_shadow_table(self):
        table_name = 'test_check_shadow_table'

        table = Table(table_name, self.meta,
                      Column('id', Integer, primary_key=True),
                      Column('a', Integer),
                      Column('c', String(256)))
        table.create()

        # check missing shadow table
        self.assertRaises(NoSuchTableError,
                          utils.check_shadow_table, self.engine, table_name)

        shadow_table = Table(db._SHADOW_TABLE_PREFIX + table_name, self.meta,
                             Column('id', Integer),
                             Column('a', Integer))
        shadow_table.create()

        # check missing column
        self.assertRaises(exception.NovaException,
                          utils.check_shadow_table, self.engine, table_name)

        # check when all is ok
        c = Column('c', String(256))
        shadow_table.create_column(c)
        self.assertTrue(utils.check_shadow_table(self.engine, table_name))

        # check extra column
        d = Column('d', Integer)
        shadow_table.create_column(d)
        self.assertRaises(exception.NovaException,
                          utils.check_shadow_table, self.engine, table_name) 
Example 59
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_migration_utils.py    Apache License 2.0 5 votes vote down vote up
def test_check_shadow_table_different_types(self):
        table_name = 'test_check_shadow_table_different_types'

        table = Table(table_name, self.meta,
                      Column('id', Integer, primary_key=True),
                      Column('a', Integer))
        table.create()

        shadow_table = Table(db._SHADOW_TABLE_PREFIX + table_name, self.meta,
                             Column('id', Integer, primary_key=True),
                             Column('a', String(256)))
        shadow_table.create()
        self.assertRaises(exception.NovaException,
                          utils.check_shadow_table, self.engine, table_name) 
Example 60
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_migration_utils.py    Apache License 2.0 5 votes vote down vote up
def test_check_shadow_table_with_unsupported_sqlite_type(self):
        table_name = 'test_check_shadow_table_with_unsupported_sqlite_type'

        table = Table(table_name, self.meta,
                      Column('id', Integer, primary_key=True),
                      Column('a', Integer),
                      Column('c', CustomType))
        table.create()

        shadow_table = Table(db._SHADOW_TABLE_PREFIX + table_name, self.meta,
                             Column('id', Integer, primary_key=True),
                             Column('a', Integer),
                             Column('c', CustomType))
        shadow_table.create()
        self.assertTrue(utils.check_shadow_table(self.engine, table_name)) 
Example 61
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_migration_utils.py    Apache License 2.0 5 votes vote down vote up
def test_create_shadow_table_by_table_instance(self):
        table_name = 'test_create_shadow_table_by_table_instance'
        table = Table(table_name, self.meta,
                      Column('id', Integer, primary_key=True),
                      Column('a', Integer),
                      Column('b', String(256)))
        table.create()
        utils.create_shadow_table(self.engine, table=table)
        self.assertTrue(utils.check_shadow_table(self.engine, table_name)) 
Example 62
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_migration_utils.py    Apache License 2.0 5 votes vote down vote up
def test_create_shadow_table_by_name(self):
        table_name = 'test_create_shadow_table_by_name'

        table = Table(table_name, self.meta,
                      Column('id', Integer, primary_key=True),
                      Column('a', Integer),
                      Column('b', String(256)))
        table.create()
        utils.create_shadow_table(self.engine, table_name=table_name)
        self.assertTrue(utils.check_shadow_table(self.engine, table_name)) 
Example 63
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_migration_utils.py    Apache License 2.0 5 votes vote down vote up
def test_create_shadow_both_table_and_table_name_are_specified(self):
        table_name = ('test_create_shadow_both_table_and_table_name_are_'
                      'specified')
        table = Table(table_name, self.meta,
                      Column('id', Integer, primary_key=True),
                      Column('a', Integer))
        table.create()
        self.assertRaises(exception.NovaException,
                          utils.create_shadow_table,
                          self.engine, table=table, table_name=table_name) 
Example 64
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: test_migration_utils.py    Apache License 2.0 5 votes vote down vote up
def test_create_duplicate_shadow_table(self):
        table_name = 'test_create_duplicate_shadow_table'
        table = Table(table_name, self.meta,
                      Column('id', Integer, primary_key=True),
                      Column('a', Integer))
        table.create()
        utils.create_shadow_table(self.engine, table_name=table_name)
        self.assertRaises(exception.ShadowTableExists,
                          utils.create_shadow_table,
                          self.engine, table_name=table_name) 
Example 65
Project: url-shortener   Author: piotr-rusin   File: f819f3f77f30_.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('shortenedURL',
    sa.Column('alias', sa.Integer(), nullable=False),
    sa.Column('target', sa.String(length=2083), nullable=True),
    sa.PrimaryKeyConstraint('alias'),
    sa.UniqueConstraint('target')
    )
    ### end Alembic commands ### 
Example 66
Project: restful-ben   Author: CityOfPhiladelphia   File: auth.py    MIT License 5 votes vote down vote up
def user_id(cls):
        return Column(Integer, ForeignKey('users.id'), index=True) 
Example 67
Project: restful-ben   Author: CityOfPhiladelphia   File: auth.py    MIT License 5 votes vote down vote up
def user_id(cls):
        return Column(Integer, ForeignKey('users.id'), index=True) 
Example 68
Project: pornote   Author: haltode   File: cb9c233eea05_.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('member', sa.Column('nb_public', sa.Integer(), nullable=True))
    ### end Alembic commands ### 
Example 69
Project: pornote   Author: haltode   File: 04ef75b50778_.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('member',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('first_name', sa.String(length=64), nullable=True),
    sa.Column('last_name', sa.String(length=64), nullable=True),
    sa.Column('email', sa.String(length=128), nullable=True),
    sa.Column('password', sa.String(length=64), nullable=True),
    sa.Column('points', sa.Integer(), nullable=True),
    sa.Column('class_nb', sa.Integer(), nullable=True),
    sa.Column('section', sa.String(length=64), nullable=True),
    sa.Column('second_lang', sa.String(length=64), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email')
    )
    op.create_table('homework',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('member_id', sa.Integer(), nullable=False),
    sa.Column('subject', sa.String(length=128), nullable=True),
    sa.Column('section', sa.String(length=64), nullable=True),
    sa.Column('description', sa.String(length=256), nullable=True),
    sa.Column('end_date', sa.Date(), nullable=True),
    sa.Column('filename', sa.String(length=128), nullable=True),
    sa.Column('class_nb', sa.Integer(), nullable=True),
    sa.Column('is_public', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['member_id'], ['member.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('filename')
    )
    ### end Alembic commands ### 
Example 70
Project: restful_model   Author: zeromake   File: view.py    MIT License 5 votes vote down vote up
def get_primary(self):
        """
        获取主键
        """
        for column in self.model.columns:
            if column.primary_key and isinstance(column.type, sa.Integer):
                return column 
Example 71
Project: mtanchor_demo   Author: forest-snow   File: 293c8607996c_.py    MIT License 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('start',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('anchors1', sa.String(), nullable=True),
    sa.Column('topics1', sa.String(), nullable=True),
    sa.Column('Q1', sa.String(), nullable=True),
    sa.Column('vocab1', sa.String(), nullable=True),
    sa.Column('index1', sa.String(), nullable=True),
    sa.Column('dict1', sa.String(), nullable=True),
    sa.Column('anchors2', sa.String(), nullable=True),
    sa.Column('topics2', sa.String(), nullable=True),
    sa.Column('Q2', sa.String(), nullable=True),
    sa.Column('vocab2', sa.String(), nullable=True),
    sa.Column('index2', sa.String(), nullable=True),
    sa.Column('dict2', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('update',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('anchors1', sa.String(), nullable=True),
    sa.Column('anchors2', sa.String(), nullable=True),
    sa.Column('topics1', sa.String(), nullable=True),
    sa.Column('topics2', sa.String(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ### 
Example 72
Project: neutron   Author: kaloom   File: 37b8cbf74943_create_kaloom_tables.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table(
        'kaloom_ml2_knid_mapping',
        sa.Column('kaloom_knid', sa.BigInteger(), nullable=False),
        sa.Column('network_id', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('kaloom_knid')
    )

    op.create_table(
        'kaloom_ml2_vlan_host_mapping',
        sa.Column('vlan_id', sa.Integer(), nullable=False),
        sa.Column('network_id', sa.String(length=255), nullable=False),
        sa.Column('host', sa.String(length=255), nullable=False),
        sa.Column('segment_id', sa.String(length=255), nullable=False),
        sa.Column('network_name', sa.String(length=255), nullable=False),
        sa.Column('state', sa.Enum('CREATING', 'CREATED', 'DELETING'), nullable=False),
        sa.Column('timestamp', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('network_id', 'host')
    )

    
    op.create_table(
        'kaloom_ml2_vlan_reservation',
        sa.Column('host', sa.String(length=255), nullable=False),
        sa.Column('vlan_id', sa.Integer(), nullable=False),
        sa.Column('network_id', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('host', 'vlan_id')
    )

    op.create_table(
        'kaloom_ml2_tp_operation',
        sa.Column('network_id', sa.String(length=255), nullable=False),
        sa.Column('host', sa.String(length=255), nullable=False),
        sa.PrimaryKeyConstraint('network_id', 'host')
    ) 
Example 73
Project: zun   Author: openstack   File: 4bf34495d060_add_container_number_info_to_compute_.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.add_column('compute_node',
                  sa.Column('total_containers', sa.Integer(), nullable=False))
    op.add_column('compute_node',
                  sa.Column('running_containers',
                            sa.Integer(), nullable=False))
    op.add_column('compute_node',
                  sa.Column('paused_containers', sa.Integer(), nullable=False))
    op.add_column('compute_node',
                  sa.Column('stopped_containers',
                            sa.Integer(), nullable=False)) 
Example 74
Project: zun   Author: openstack   File: 37bce72463e3_add_pci_device.py    Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table(
        'pci_device',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('uuid', sa.String(length=36)),
        sa.Column('compute_node_uuid', sa.String(length=36), nullable=False),
        sa.Column('address', sa.String(length=12), nullable=False),
        sa.Column('vendor_id', sa.String(length=4), nullable=False),
        sa.Column('product_id', sa.String(length=4), nullable=False),
        sa.Column('dev_type', sa.String(length=8), nullable=False),
        sa.Column('dev_id', sa.String(255)),
        sa.Column('label', sa.String(255), nullable=False),
        sa.Column('status', sa.String(36), nullable=False),
        sa.Column('request_id', sa.String(36), nullable=False),
        sa.Column('extra_info', sa.Text()),
        sa.Column('container_uuid', sa.String(36)),
        sa.Column('numa_node', sa.Integer(), nullable=True),
        sa.Column('parent_addr', sa.String(12), nullable=True),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('compute_node_uuid', 'address',
                            name='uniq_pci_device0compute_node_uuid0address'),
        sa.Index('ix_pci_device_compute_node_uuid', 'compute_node_uuid'),
        sa.Index('ix_pci_device_container_uuid', 'container_uuid'),
        sa.Index('ix_pci_device_compute_node_uuid_parent_addr',
                 'compute_node_uuid', 'parent_addr'),
    ) 
Example 75
Project: flasky   Author: RoseOu   File: 56ed7d33de8d_user_roles.py    MIT License 4 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('roles', sa.Column('default', sa.Boolean(), nullable=True))
    op.add_column('roles', sa.Column('permissions', sa.Integer(), nullable=True))
    op.create_index('ix_roles_default', 'roles', ['default'], unique=False)
    ### end Alembic commands ### 
Example 76
Project: flasky   Author: RoseOu   File: test_reflection.py    MIT License 4 votes vote down vote up
def define_reflected_tables(cls, metadata, schema):
        if schema:
            schema_prefix = schema + "."
        else:
            schema_prefix = ""

        if testing.requires.self_referential_foreign_keys.enabled:
            users = Table('users', metadata,
                          Column('user_id', sa.INT, primary_key=True),
                          Column('test1', sa.CHAR(5), nullable=False),
                          Column('test2', sa.Float(5), nullable=False),
                          Column('parent_user_id', sa.Integer,
                                 sa.ForeignKey('%susers.user_id' %
                                               schema_prefix)),
                          schema=schema,
                          test_needs_fk=True,
                          )
        else:
            users = Table('users', metadata,
                          Column('user_id', sa.INT, primary_key=True),
                          Column('test1', sa.CHAR(5), nullable=False),
                          Column('test2', sa.Float(5), nullable=False),
                          schema=schema,
                          test_needs_fk=True,
                          )

        Table("dingalings", metadata,
              Column('dingaling_id', sa.Integer, primary_key=True),
              Column('address_id', sa.Integer,
                     sa.ForeignKey('%semail_addresses.address_id' %
                                   schema_prefix)),
              Column('data', sa.String(30)),
              schema=schema,
              test_needs_fk=True,
              )
        Table('email_addresses', metadata,
              Column('address_id', sa.Integer),
              Column('remote_user_id', sa.Integer,
                     sa.ForeignKey(users.c.user_id)),
              Column('email_address', sa.String(20)),
              sa.PrimaryKeyConstraint('address_id', name='email_ad_pk'),
              schema=schema,
              test_needs_fk=True,
              )

        if testing.requires.index_reflection.enabled:
            cls.define_index(metadata, users)
        if testing.requires.view_column_reflection.enabled:
            cls.define_views(metadata, schema) 
Example 77
Project: flasky   Author: RoseOu   File: test_reflection.py    MIT License 4 votes vote down vote up
def _test_get_columns(self, schema=None, table_type='table'):
        meta = MetaData(testing.db)
        users, addresses, dingalings = self.tables.users, \
            self.tables.email_addresses, self.tables.dingalings
        table_names = ['users', 'email_addresses']
        if table_type == 'view':
            table_names = ['users_v', 'email_addresses_v']
        insp = inspect(meta.bind)
        for table_name, table in zip(table_names, (users,
                                                   addresses)):
            schema_name = schema
            cols = insp.get_columns(table_name, schema=schema_name)
            self.assert_(len(cols) > 0, len(cols))

            # should be in order

            for i, col in enumerate(table.columns):
                eq_(col.name, cols[i]['name'])
                ctype = cols[i]['type'].__class__
                ctype_def = col.type
                if isinstance(ctype_def, sa.types.TypeEngine):
                    ctype_def = ctype_def.__class__

                # Oracle returns Date for DateTime.

                if testing.against('oracle') and ctype_def \
                        in (sql_types.Date, sql_types.DateTime):
                    ctype_def = sql_types.Date

                # assert that the desired type and return type share
                # a base within one of the generic types.

                self.assert_(len(set(ctype.__mro__).
                                 intersection(ctype_def.__mro__).
                                 intersection([
                                     sql_types.Integer,
                                     sql_types.Numeric,
                                     sql_types.DateTime,
                                     sql_types.Date,
                                     sql_types.Time,
                                     sql_types.String,
                                     sql_types._Binary,
                                 ])) > 0, '%s(%s), %s(%s)' %
                             (col.name, col.type, cols[i]['name'], ctype))

                if not col.primary_key:
                    assert cols[i]['default'] is None 
Example 78
Project: flasky   Author: RoseOu   File: mutable.py    MIT License 4 votes vote down vote up
def as_mutable(cls, sqltype):
        """Associate a SQL type with this mutable Python type.

        This establishes listeners that will detect ORM mappings against
        the given type, adding mutation event trackers to those mappings.

        The type is returned, unconditionally as an instance, so that
        :meth:`.as_mutable` can be used inline::

            Table('mytable', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', MyMutableType.as_mutable(PickleType))
            )

        Note that the returned type is always an instance, even if a class
        is given, and that only columns which are declared specifically with
        that type instance receive additional instrumentation.

        To associate a particular mutable type with all occurrences of a
        particular type, use the :meth:`.Mutable.associate_with` classmethod
        of the particular :class:`.Mutable` subclass to establish a global
        association.

        .. warning::

           The listeners established by this method are *global*
           to all mappers, and are *not* garbage collected.   Only use
           :meth:`.as_mutable` for types that are permanent to an application,
           not with ad-hoc types else this will cause unbounded growth
           in memory usage.

        """
        sqltype = types.to_instance(sqltype)

        def listen_for_type(mapper, class_):
            for prop in mapper.column_attrs:
                if prop.columns[0].type is sqltype:
                    cls.associate_with_attribute(getattr(class_, prop.key))

        event.listen(mapper, 'mapper_configured', listen_for_type)

        return sqltype 
Example 79
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 314_add_resource_provider_tables.py    Apache License 2.0 4 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    resource_providers = Table(
        'resource_providers', meta,
        Column('id', Integer, primary_key=True, nullable=False),
        Column('uuid', String(36), nullable=False),
        UniqueConstraint('uuid', name='uniq_resource_providers0uuid'),
        mysql_engine='InnoDB',
        mysql_charset='latin1'
    )
    # NOTE(mriedem): DB2 creates an index when a unique constraint is created
    # so trying to add a second index on the name column will fail with error
    # SQL0605W, so omit the index in the case of DB2.
    if migrate_engine.name != 'ibm_db_sa':
        Index('resource_providers_uuid_idx', resource_providers.c.uuid)

    inventories = Table(
        'inventories', meta,
        Column('id', Integer, primary_key=True, nullable=False),
        Column('resource_provider_id', Integer, nullable=False),
        Column('resource_class_id', Integer, nullable=False),
        Column('total', Integer, nullable=False),
        Column('reserved', Integer, nullable=False),
        Column('min_unit', Integer, nullable=False),
        Column('max_unit', Integer, nullable=False),
        Column('step_size', Integer, nullable=False),
        Column('allocation_ratio', Float, nullable=False),
        mysql_engine='InnoDB',
        mysql_charset='latin1'
    )
    Index('inventories_resource_provider_id_idx',
          inventories.c.resource_provider_id)
    Index('inventories_resource_class_id_idx',
          inventories.c.resource_class_id)

    allocations = Table(
        'allocations', meta,
        Column('id', Integer, primary_key=True, nullable=False),
        Column('resource_provider_id', Integer, nullable=False),
        Column('consumer_id', String(36), nullable=False),
        Column('resource_class_id', Integer, nullable=False),
        Column('used', Integer, nullable=False),
        mysql_engine='InnoDB',
        mysql_charset='latin1'
    )
    Index('allocations_resource_provider_class_id_idx',
          allocations.c.resource_provider_id,
          allocations.c.resource_class_id)
    Index('allocations_consumer_id_idx', allocations.c.consumer_id)
    Index('allocations_resource_class_id_idx',
          allocations.c.resource_class_id)

    for table in [resource_providers, inventories, allocations]:
        table.create(checkfirst=True)

    for table_name in ('', 'shadow_'):
        uuid_column = Column('uuid', String(36))
        compute_nodes = Table('%scompute_nodes' % table_name, meta)
        compute_nodes.create_column(uuid_column) 
Example 80
Project: circleci-demo-python-flask   Author: CircleCI-Public   File: 7257da855061_.py    MIT License 4 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('roles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('default', sa.Boolean(), nullable=True),
    sa.Column('permissions', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_index(op.f('ix_roles_default'), 'roles', ['default'], unique=False)
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=64), nullable=True),
    sa.Column('username', sa.String(length=64), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.Column('password_hash', sa.String(length=128), nullable=True),
    sa.Column('confirmed', sa.Boolean(), nullable=True),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('location', sa.String(length=64), nullable=True),
    sa.Column('about_me', sa.Text(), nullable=True),
    sa.Column('member_since', sa.DateTime(), nullable=True),
    sa.Column('last_seen', sa.DateTime(), nullable=True),
    sa.Column('avatar_hash', sa.String(length=32), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('follows',
    sa.Column('follower_id', sa.Integer(), nullable=False),
    sa.Column('followed_id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['followed_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['follower_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('follower_id', 'followed_id')
    )
    op.create_table('posts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('body_html', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_posts_timestamp'), 'posts', ['timestamp'], unique=False)
    op.create_table('comments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('body_html', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('disabled', sa.Boolean(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.Column('post_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_comments_timestamp'), 'comments', ['timestamp'], unique=False)
    # ### end Alembic commands ###