Python sqlalchemy.String() Examples

The following are code examples for showing how to use sqlalchemy.String(). 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: 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 2
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 3
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 4
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 5
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 313_add_parent_id_column.py    Apache License 2.0 6 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData(bind=migrate_engine)

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

    parent_addr = Column('parent_addr', String(12), nullable=True)

    if not hasattr(pci_devices.c, 'parent_addr'):
        pci_devices.create_column(parent_addr)
    if not hasattr(shadow_pci_devices.c, 'parent_addr'):
        shadow_pci_devices.create_column(parent_addr.copy())

    # Create index
    parent_index = Index('ix_pci_devices_compute_node_id_parent_addr_deleted',
                         pci_devices.c.compute_node_id,
                         pci_devices.c.parent_addr,
                         pci_devices.c.deleted)
    parent_index.create(migrate_engine) 
Example 6
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 268_add_host_in_compute_node.py    Apache License 2.0 6 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    # Add a new column host
    compute_nodes = Table('compute_nodes', meta, autoload=True)
    shadow_compute_nodes = Table('shadow_compute_nodes', meta, autoload=True)

    # NOTE(sbauza) : Old compute nodes can report stats without this field, we
    # need to set it as nullable
    host = Column('host', String(255), nullable=True)
    if not hasattr(compute_nodes.c, 'host'):
        compute_nodes.create_column(host)
    if not hasattr(shadow_compute_nodes.c, 'host'):
        shadow_compute_nodes.create_column(host.copy())

    # NOTE(sbauza) : Populate the host field with the value from the services
    # table will be done at the ComputeNode object level when save()

    ukey = UniqueConstraint('host', 'hypervisor_hostname', table=compute_nodes,
                            name="uniq_compute_nodes0host0hypervisor_hostname")
    ukey.create() 
Example 7
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 8
Project: flaskit   Author: elston   File: a2cd143eda28_.py    MIT License 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('username', sa.String(length=80), nullable=False),
    sa.Column('password', sa.Binary(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('is_admin', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('username')
    )
    # ### end Alembic commands ### 
Example 9
Project: flasky   Author: RoseOu   File: 198b0eebcf9_caching_of_avatar_hashes.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('avatar_hash', sa.String(length=32), nullable=True))
    ### end Alembic commands ### 
Example 10
Project: flasky   Author: RoseOu   File: 456a945560f6_login_support.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('email', sa.String(length=64), nullable=True))
    op.add_column('users', sa.Column('password_hash', sa.String(length=128), nullable=True))
    op.create_index('ix_users_email', 'users', ['email'], unique=True)
    ### end Alembic commands ### 
Example 11
Project: flasky   Author: RoseOu   File: d66f086b258_user_information.py    MIT License 5 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users', sa.Column('about_me', sa.Text(), nullable=True))
    op.add_column('users', sa.Column('last_seen', sa.DateTime(), nullable=True))
    op.add_column('users', sa.Column('location', sa.String(length=64), nullable=True))
    op.add_column('users', sa.Column('member_since', sa.DateTime(), nullable=True))
    op.add_column('users', sa.Column('name', sa.String(length=64), nullable=True))
    ### end Alembic commands ### 
Example 12
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 13
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 14
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 15
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 16
Project: flasky   Author: RoseOu   File: test_ddl.py    MIT License 5 votes vote down vote up
def _underscore_fixture(self):
        return Table('_test_table', self.metadata,
                     Column('id', Integer, primary_key=True,
                            autoincrement=False),
                     Column('_data', String(50))
                     ) 
Example 17
Project: flasky   Author: RoseOu   File: test_update_delete.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))
              ) 
Example 18
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 19
Project: flasky   Author: RoseOu   File: test_reflection.py    MIT License 5 votes vote down vote up
def test_varchar_reflection(self):
        typ = self._type_round_trip(sql_types.String(52))[0]
        assert isinstance(typ, sql_types.String)
        eq_(typ.length, 52) 
Example 20
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 21
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 22
Project: flasky   Author: RoseOu   File: operations.py    MIT License 5 votes vote down vote up
def create_primary_key(self, name, table_name, cols, schema=None):
        """Issue a "create primary key" instruction using the current
        migration context.

        e.g.::

            from alembic import op
            op.create_primary_key(
                        "pk_my_table", "my_table",
                        ["id", "version"]
                    )

        This internally generates a :class:`~sqlalchemy.schema.Table` object
        containing the necessary columns, then generates a new
        :class:`~sqlalchemy.schema.PrimaryKeyConstraint`
        object which it then associates with the :class:`~sqlalchemy.schema.Table`.
        Any event listeners associated with this action will be fired
        off normally.   The :class:`~sqlalchemy.schema.AddConstraint`
        construct is ultimately used to generate the ALTER statement.

        .. versionadded:: 0.5.0

        :param name: Name of the primary key constraint.  The name is necessary
         so that an ALTER statement can be emitted.  For setups that
         use an automated naming scheme such as that described at
         `NamingConventions <http://www.sqlalchemy.org/trac/wiki/UsageRecipes/NamingConventions>`_,
         ``name`` here can be ``None``, as the event listener will
         apply the name to the constraint object when it is associated
         with the table.
        :param table_name: String name of the target table.
        :param cols: a list of string column names to be applied to the
         primary key constraint.
        :param schema: Optional schema name of the table.

        """
        self.impl.add_constraint(
                    self._primary_key_constraint(name, table_name, cols,
                                schema)
                ) 
Example 23
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 24
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 25
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 26
Project: comport   Author: codeforamerica   File: ab97630e71ce_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    op.add_column('officer_involved_shootings_bpd', sa.Column('case_number', sa.String(length=255), nullable=True)) 
Example 27
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 28
Project: comport   Author: codeforamerica   File: 2de736b481_.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('citizen_complaints', sa.Column('allegation', sa.String(length=255), nullable=True))
    op.add_column('citizen_complaints', sa.Column('allegation_type', sa.String(length=255), nullable=True))
    op.drop_column('citizen_complaints', 'category')
    ### end Alembic commands ### 
Example 29
Project: comport   Author: codeforamerica   File: 2357b6b3d76_.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('citizen_complaints', sa.Column('service_type', sa.String(length=255), nullable=True))
    op.add_column('citizen_complaints', sa.Column('source', sa.String(length=255), nullable=True))
    ### end Alembic commands ### 
Example 30
Project: comport   Author: codeforamerica   File: 77ad8047becf_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    op.add_column('use_of_force_incidents_bpd', sa.Column('case_number', sa.String(length=128), nullable=True))
    op.add_column('use_of_force_incidents_bpd', sa.Column('completed_date', sa.DateTime(), nullable=True))
    op.add_column('use_of_force_incidents_bpd', sa.Column('received_date', sa.DateTime(), nullable=True))

    op.drop_column('use_of_force_incidents_bpd', 'division')
    op.drop_column('use_of_force_incidents_bpd', 'bureau')
    op.drop_column('use_of_force_incidents_bpd', 'resident_weapon_used') 
Example 31
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 32
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 33
Project: comport   Author: codeforamerica   File: fecca96b9d_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    ### 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.String(length=255), nullable=True))
    ### end Alembic commands ### 
Example 34
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 35
Project: comport   Author: codeforamerica   File: 4e98ea7e43d_.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('password_reset_uuid', sa.String(length=36), nullable=True))
    op.create_unique_constraint(None, 'users', ['password_reset_uuid'])
    ### end Alembic commands ### 
Example 36
Project: comport   Author: codeforamerica   File: 529d8396153_.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_identifier', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('officer_weapon_used', sa.String(length=255), nullable=True))
    op.drop_column('use_of_force_incidents', 'office_weapon_used')
    ### end Alembic commands ### 
Example 37
Project: comport   Author: codeforamerica   File: 471223798fc_.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_sex', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('resident_sex', sa.String(length=255), nullable=True))
    ### end Alembic commands ### 
Example 38
Project: comport   Author: codeforamerica   File: 16b50a2c53b_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    connection = op.get_bind()

    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('departments', sa.Column('short_name', sa.String(length=80), nullable=True))
    op.create_unique_constraint("dept_short_name", 'departments', ['short_name'])
    ### end Alembic commands ### 
Example 39
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 40
Project: comport   Author: codeforamerica   File: 4a7e5abdf57_.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('officer_involved_shootings', sa.Column('officer_weapon_used', sa.String(length=255), nullable=True))
    op.drop_column('officer_involved_shootings', 'officer_force_type')
    ### end Alembic commands ### 
Example 41
Project: comport   Author: codeforamerica   File: 52887f8e06b_.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('citizen_complaint', sa.Column('category', sa.String(length=255), nullable=True))
    ### end Alembic commands ### 
Example 42
Project: comport   Author: codeforamerica   File: 3434f410ad7_.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('extractors',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.add_column('users', sa.Column('type', sa.String(length=50), nullable=True))
    op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
    ### end Alembic commands ### 
Example 43
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 44
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 45
Project: comport   Author: codeforamerica   File: 43fd1bb4848_.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('census_tract', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('citizen_weapon', sa.String(length=255), nullable=True))
    ### end Alembic commands ### 
Example 46
Project: comport   Author: codeforamerica   File: c471472f1a82_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    op.add_column('use_of_force_incidents_srpd', sa.Column('bureau', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents_srpd', sa.Column('division', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents_srpd', sa.Column('officer_force_type_scale', sa.String(length=255), nullable=True)) 
Example 47
Project: comport   Author: codeforamerica   File: 2f13ffb1ce60_.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def upgrade():
    op.add_column('pursuits_srpd', sa.Column('bureau', sa.String(length=255), nullable=True))
    op.add_column('pursuits_srpd', sa.Column('division', sa.String(length=255), nullable=True)) 
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: 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 50
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 51
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 52
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 InetSmall():
    return String(length=39).with_variant(dialects.postgresql.INET(),
                  'postgresql') 
Example 53
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 231_add_ephemeral_key_uuid.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    """Function adds ephemeral storage encryption key uuid field."""
    meta = MetaData(bind=migrate_engine)

    instances = Table('instances', meta, autoload=True)
    shadow_instances = Table('shadow_instances', meta, autoload=True)

    ephemeral_key_uuid = Column('ephemeral_key_uuid', String(36))
    instances.create_column(ephemeral_key_uuid)
    shadow_instances.create_column(ephemeral_key_uuid.copy())

    migrate_engine.execute(instances.update().
                           values(ephemeral_key_uuid=None))
    migrate_engine.execute(shadow_instances.update().
                           values(ephemeral_key_uuid=None)) 
Example 54
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 230_add_details_column_to_instance_actions_events.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    actions_events = utils.get_table(migrate_engine, 'instance_actions_events')
    host = Column('host', String(255))
    details = Column('details', Text)
    actions_events.create_column(host)
    actions_events.create_column(details)
    shadow_actions_events = utils.get_table(migrate_engine,
            api._SHADOW_TABLE_PREFIX + 'instance_actions_events')
    shadow_actions_events.create_column(host.copy())
    shadow_actions_events.create_column(details.copy()) 
Example 55
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 216_havana.py    Apache License 2.0 5 votes vote down vote up
def Inet():
    return String(length=43).with_variant(dialects.postgresql.INET(),
                  'postgresql') 
Example 56
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 216_havana.py    Apache License 2.0 5 votes vote down vote up
def InetSmall():
    return String(length=39).with_variant(dialects.postgresql.INET(),
                  'postgresql') 
Example 57
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 244_increase_user_id_length_volume_usage_cache.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData(bind=migrate_engine)
    table = Table('volume_usage_cache', meta, autoload=True)
    col_resource = getattr(table.c, 'user_id')
    # Match the maximum length of user_id in Keystone here instead of
    # assuming explicitly a single UUID length.
    col_resource.alter(type=String(64)) 
Example 58
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 59
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 254_add_request_id_in_pci_devices.py    Apache License 2.0 5 votes vote down vote up
def upgrade(engine):
    """Function adds request_id field."""
    meta = MetaData(bind=engine)

    pci_devices = Table('pci_devices', meta, autoload=True)
    shadow_pci_devices = Table('shadow_pci_devices', meta, autoload=True)
    request_id = Column('request_id', String(36), nullable=True)

    if not hasattr(pci_devices.c, 'request_id'):
        pci_devices.create_column(request_id)

    if not hasattr(shadow_pci_devices.c, 'request_id'):
        shadow_pci_devices.create_column(request_id.copy()) 
Example 60
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 266_add_instance_tags.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = sa.MetaData(bind=migrate_engine)

    tags = sa.Table('tags', meta,
                    sa.Column('resource_id', sa.String(36), primary_key=True,
                              nullable=False),
                    sa.Column('tag', sa.Unicode(80), primary_key=True,
                              nullable=False),
                    sa.Index('tags_tag_idx', 'tag'),
                    mysql_engine='InnoDB',
                    mysql_charset='utf8')
    tags.create() 
Example 61
Project: Trusted-Platform-Module-nova   Author: BU-NU-CLOUD-SP16   File: 227_fix_project_user_quotas_resource_length.py    Apache License 2.0 5 votes vote down vote up
def upgrade(migrate_engine):
    meta = MetaData(bind=migrate_engine)
    table = Table('project_user_quotas', meta, autoload=True)
    col_resource = getattr(table.c, 'resource')

    if col_resource.type.length == 25:
        # The resource of project_user_quotas table had been changed to
        # invalid length(25) since I56ad98d3702f53fe8cfa94093fea89074f7a5e90.
        # The following code fixes the length for the environments which are
        # deployed after I56ad98d3702f53fe8cfa94093fea89074f7a5e90.
        col_resource.alter(type=String(255))
        table.update().where(table.c.resource == 'injected_file_content_byt')\
            .values(resource='injected_file_content_bytes').execute() 
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_delete_from_select(self):
        table_name = "__test_deletefromselect_table__"
        uuidstrs = []
        for unused in range(10):
            uuidstrs.append(uuid.uuid4().hex)

        conn = self.engine.connect()
        test_table = Table(table_name, self.meta,
                           Column('id', Integer, primary_key=True,
                                  nullable=False, autoincrement=True),
                           Column('uuid', String(36), nullable=False))
        test_table.create()
        # Add 10 rows to table
        for uuidstr in uuidstrs:
            ins_stmt = test_table.insert().values(uuid=uuidstr)
            conn.execute(ins_stmt)

        # Delete 4 rows in one chunk
        column = test_table.c.id
        query_delete = sql.select([column],
                                  test_table.c.id < 5).order_by(column)
        delete_statement = utils.DeleteFromSelect(test_table,
                                                  query_delete, column)
        result_delete = conn.execute(delete_statement)
        # Verify we delete 4 rows
        self.assertEqual(result_delete.rowcount, 4)

        query_all = sql.select([test_table])\
                       .where(test_table.c.uuid.in_(uuidstrs))
        rows = conn.execute(query_all).fetchall()
        # Verify we still have 6 rows in table
        self.assertEqual(len(rows), 6) 
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_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 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_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 65
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 66
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 67
Project: url-shortener   Author: piotr-rusin   File: fd263851b989_.py    MIT License 5 votes vote down vote up
def upgrade():
    op.alter_column(
        'targetURL',
        'value',
        existing_type=sa.String(length=2083),
        nullable=False
    ) 
Example 68
Project: url-shortener   Author: piotr-rusin   File: fd263851b989_.py    MIT License 5 votes vote down vote up
def downgrade():
    op.alter_column(
        'targetURL',
        'value',
        existing_type=sa.String(length=2083),
        nullable=True
    ) 
Example 69
Project: url-shortener   Author: piotr-rusin   File: bbe95d9977da_.py    MIT License 5 votes vote down vote up
def upgrade():
    op.alter_column(
        'targetURL',
        'target',
        new_column_name='value',
        existing_type=sa.String(length=2083),
        existing_nullable=True
    ) 
Example 70
Project: url-shortener   Author: piotr-rusin   File: bbe95d9977da_.py    MIT License 5 votes vote down vote up
def downgrade():
    op.alter_column(
        'targetURL',
        'value',
        new_column_name='target',
        existing_type=sa.String(length=2083),
        existing_nullable=True
    ) 
Example 71
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 72
Project: gnocchi   Author: gnocchixyz   File: sqlalchemy_base.py    Apache License 2.0 5 votes vote down vote up
def type(cls):
        return sqlalchemy.Column(
            sqlalchemy.String(255),
            sqlalchemy.ForeignKey('resource_type.name',
                                  ondelete="RESTRICT",
                                  name="fk_%s_resource_type_name" %
                                  cls.__tablename__),
            nullable=False) 
Example 73
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 74
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 75
Project: flasky   Author: RoseOu   File: operations.py    MIT License 4 votes vote down vote up
def add_column(self, table_name, column, schema=None):
        """Issue an "add column" instruction using the current
        migration context.

        e.g.::

            from alembic import op
            from sqlalchemy import Column, String

            op.add_column('organization',
                Column('name', String())
            )

        The provided :class:`~sqlalchemy.schema.Column` object can also
        specify a :class:`~sqlalchemy.schema.ForeignKey`, referencing
        a remote table name.  Alembic will automatically generate a stub
        "referenced" table and emit a second ALTER statement in order
        to add the constraint separately::

            from alembic import op
            from sqlalchemy import Column, INTEGER, ForeignKey

            op.add_column('organization',
                Column('account_id', INTEGER, ForeignKey('accounts.id'))
            )

        Note that this statement uses the :class:`~sqlalchemy.schema.Column`
        construct as is from the SQLAlchemy library.  In particular,
        default values to be created on the database side are
        specified using the ``server_default`` parameter, and not
        ``default`` which only specifies Python-side defaults::

            from alembic import op
            from sqlalchemy import Column, TIMESTAMP, func

            # specify "DEFAULT NOW" along with the column add
            op.add_column('account',
                Column('timestamp', TIMESTAMP, server_default=func.now())
            )

        :param table_name: String name of the parent table.
        :param column: a :class:`sqlalchemy.schema.Column` object
         representing the new column.
        :param schema: Optional schema name to operate within.

         .. versionadded:: 0.4.0

        """

        t = self._table(table_name, column, schema=schema)
        self.impl.add_column(
            table_name,
            column,
            schema=schema
        )
        for constraint in t.constraints:
            if not isinstance(constraint, sa_schema.PrimaryKeyConstraint):
                self.impl.add_constraint(constraint) 
Example 76
Project: flasky   Author: RoseOu   File: operations.py    MIT License 4 votes vote down vote up
def create_foreign_key(self, name, source, referent, local_cols,
                           remote_cols, onupdate=None, ondelete=None,
                           deferrable=None, source_schema=None,
                           referent_schema=None):
        """Issue a "create foreign key" instruction using the
        current migration context.

        e.g.::

            from alembic import op
            op.create_foreign_key(
                        "fk_user_address", "address",
                        "user", ["user_id"], ["id"])

        This internally generates a :class:`~sqlalchemy.schema.Table` object
        containing the necessary columns, then generates a new
        :class:`~sqlalchemy.schema.ForeignKeyConstraint`
        object which it then associates with the :class:`~sqlalchemy.schema.Table`.
        Any event listeners associated with this action will be fired
        off normally.   The :class:`~sqlalchemy.schema.AddConstraint`
        construct is ultimately used to generate the ALTER statement.

        :param name: Name of the foreign key constraint.  The name is necessary
         so that an ALTER statement can be emitted.  For setups that
         use an automated naming scheme such as that described at
         `NamingConventions <http://www.sqlalchemy.org/trac/wiki/UsageRecipes/NamingConventions>`_,
         ``name`` here can be ``None``, as the event listener will
         apply the name to the constraint object when it is associated
         with the table.
        :param source: String name of the source table.
        :param referent: String name of the destination table.
        :param local_cols: a list of string column names in the
         source table.
        :param remote_cols: a list of string column names in the
         remote table.
        :param onupdate: Optional string. If set, emit ON UPDATE <value> when
         issuing DDL for this constraint. Typical values include CASCADE,
         DELETE and RESTRICT.
        :param ondelete: Optional string. If set, emit ON DELETE <value> when
         issuing DDL for this constraint. Typical values include CASCADE,
         DELETE and RESTRICT.
        :param deferrable: optional bool. If set, emit DEFERRABLE or NOT
         DEFERRABLE when issuing DDL for this constraint.
        :param source_schema: Optional schema name of the source table.
        :param referent_schema: Optional schema name of the destination table.

        """

        self.impl.add_constraint(
                    self._foreign_key_constraint(name, source, referent,
                            local_cols, remote_cols,
                            onupdate=onupdate, ondelete=ondelete,
                            deferrable=deferrable, source_schema=source_schema,
                            referent_schema=referent_schema)
                ) 
Example 77
Project: flasky   Author: RoseOu   File: operations.py    MIT License 4 votes vote down vote up
def create_unique_constraint(self, name, source, local_cols,
                                 schema=None, **kw):
        """Issue a "create unique constraint" instruction using the
        current migration context.

        e.g.::

            from alembic import op
            op.create_unique_constraint("uq_user_name", "user", ["name"])

        This internally generates a :class:`~sqlalchemy.schema.Table` object
        containing the necessary columns, then generates a new
        :class:`~sqlalchemy.schema.UniqueConstraint`
        object which it then associates with the :class:`~sqlalchemy.schema.Table`.
        Any event listeners associated with this action will be fired
        off normally.   The :class:`~sqlalchemy.schema.AddConstraint`
        construct is ultimately used to generate the ALTER statement.

        :param name: Name of the unique constraint.  The name is necessary
         so that an ALTER statement can be emitted.  For setups that
         use an automated naming scheme such as that described at
         `NamingConventions <http://www.sqlalchemy.org/trac/wiki/UsageRecipes/NamingConventions>`_,
         ``name`` here can be ``None``, as the event listener will
         apply the name to the constraint object when it is associated
         with the table.
        :param source: String name of the source table. Dotted schema names are
         supported.
        :param local_cols: a list of string column names in the
         source table.
        :param deferrable: optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
         issuing DDL for this constraint.
        :param initially: optional string. If set, emit INITIALLY <value> when issuing DDL
         for this constraint.
        :param schema: Optional schema name to operate within.

         .. versionadded:: 0.4.0

        """

        self.impl.add_constraint(
                    self._unique_constraint(name, source, local_cols,
                        schema=schema, **kw)
                ) 
Example 78
Project: flasky   Author: RoseOu   File: operations.py    MIT License 4 votes vote down vote up
def create_check_constraint(self, name, source, condition,
                                schema=None, **kw):
        """Issue a "create check constraint" instruction using the
        current migration context.

        e.g.::

            from alembic import op
            from sqlalchemy.sql import column, func

            op.create_check_constraint(
                "ck_user_name_len",
                "user",
                func.len(column('name')) > 5
            )

        CHECK constraints are usually against a SQL expression, so ad-hoc
        table metadata is usually needed.   The function will convert the given
        arguments into a :class:`sqlalchemy.schema.CheckConstraint` bound
        to an anonymous table in order to emit the CREATE statement.

        :param name: Name of the check constraint.  The name is necessary
         so that an ALTER statement can be emitted.  For setups that
         use an automated naming scheme such as that described at
         `NamingConventions <http://www.sqlalchemy.org/trac/wiki/UsageRecipes/NamingConventions>`_,
         ``name`` here can be ``None``, as the event listener will
         apply the name to the constraint object when it is associated
         with the table.
        :param source: String name of the source table.
        :param condition: SQL expression that's the condition of the constraint.
         Can be a string or SQLAlchemy expression language structure.
        :param deferrable: optional bool. If set, emit DEFERRABLE or NOT DEFERRABLE when
         issuing DDL for this constraint.
        :param initially: optional string. If set, emit INITIALLY <value> when issuing DDL
         for this constraint.
        :param schema: Optional schema name to operate within.

         ..versionadded:: 0.4.0

        """
        self.impl.add_constraint(
            self._check_constraint(name, source, condition, schema=schema, **kw)
        ) 
Example 79
Project: comport   Author: codeforamerica   File: 21dd34bbb19_.py    BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('use_of_force_incidents', sa.Column('beat', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('division', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('office_weapon_used', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('officer_force_type', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('officer_race', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('precinct', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('resident_hospitalized', sa.Boolean(), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('resident_injured', sa.Boolean(), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('resident_race', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('resident_resist_type', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('resident_weapon_used', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('shift', sa.String(length=255), nullable=True))
    op.alter_column('use_of_force_incidents', 'department_id',
               existing_type=sa.INTEGER(),
               nullable=False)
    op.drop_column('use_of_force_incidents', 'month')
    op.drop_column('use_of_force_incidents', 'hour')
    op.drop_column('use_of_force_incidents', 'year')
    op.drop_column('use_of_force_incidents', 'citizen_hospitalized')
    op.drop_column('use_of_force_incidents', 'citizen_weapon')
    op.drop_column('use_of_force_incidents', 'citizen_injured')
    op.drop_column('use_of_force_incidents', 'received_date')
    op.drop_column('use_of_force_incidents', 'day_of_week')
    op.drop_column('use_of_force_incidents', 'status')
    ### end Alembic commands ### 
Example 80
Project: comport   Author: codeforamerica   File: 331a821cc4a_.py    BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('officer_involved_shootings',
    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('officer_force_type', sa.String(length=255), nullable=True),
    sa.Column('resident_weapon_used', sa.String(length=255), nullable=True),
    sa.Column('service_type', 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.Column('officer_age', sa.String(length=255), nullable=True),
    sa.Column('resident_age', sa.String(length=255), nullable=True),
    sa.Column('officer_condition', sa.String(length=255), nullable=True),
    sa.Column('resident_condition', sa.String(length=255), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('citizen_complaints',
    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('category', 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.Column('officer_age', sa.String(length=255), nullable=True),
    sa.Column('resident_age', sa.String(length=255), nullable=True),
    sa.ForeignKeyConstraint(['department_id'], ['departments.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.drop_table('citizen_complaint')
    op.add_column('use_of_force_incidents', sa.Column('officer_condition', sa.String(length=255), nullable=True))
    op.add_column('use_of_force_incidents', sa.Column('resident_condition', sa.String(length=255), nullable=True))
    ### end Alembic commands ###