sqlalchemy.BigInteger

Here are the examples of the python api sqlalchemy.BigInteger taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

32 Examples 7

Example 1

Project: alembic Source File: test_autogen_diffs.py
    def test_integer(self):
        t1 = Integer()
        t2 = SmallInteger()
        t3 = BIGINT()
        t4 = String()
        t5 = INTEGER()
        t6 = BigInteger()

        impl = self._fixture()
        is_(impl.compare_type(Column('x', t5), Column('x', t1)), False)
        is_(impl.compare_type(Column('x', t3), Column('x', t1)), True)
        is_(impl.compare_type(Column('x', t3), Column('x', t6)), False)
        is_(impl.compare_type(Column('x', t3), Column('x', t2)), True)
        is_(impl.compare_type(Column('x', t5), Column('x', t2)), True)
        is_(impl.compare_type(Column('x', t1), Column('x', t4)), True)

Example 2

Project: gamification-engine Source File: 3fd502c152c9_added_groups.py
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('groups',
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('users_groups',
    sa.Column('user_id', sa.BigInteger(), nullable=False),
    sa.Column('group_id', sa.BigInteger(), nullable=False),
    sa.ForeignKeyConstraint(['group_id'], ['groups.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('user_id', 'group_id')
    )
    op.create_index(op.f('ix_achievements_achievementcategory_id'), 'achievements', ['achievementcategory_id'], unique=False)

Example 3

Project: ReadableWebProxy Source File: d50da91f4e86_.py
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('raw_web_pages_version', 'id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('raw_web_pages', 'id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())

Example 4

Project: kcsrv Source File: 699e07f138d7_add_expedition_cancelled_field.py
def downgrade():
### commands auto generated by Alembic - please adjust! ###
    op.drop_column('fleet', 'expedition_cancelled')
    op.alter_column('expedition', 'time_taken',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER(),
               existing_nullable=True)

Example 5

Project: postgresql-audit Source File: base.py
def transaction_base(Base, schema=None):
    class Transaction(Base):
        __abstract__ = True
        __table_args__ = {'schema': schema}
        id = sa.Column(sa.BigInteger, primary_key=True)
        native_transaction_id = sa.Column(sa.BigInteger, index=True)
        issued_at = sa.Column(sa.DateTime)
        client_addr = sa.Column(INET)

        def __repr__(self):
            return '<{cls} id={id!r} issued_at={issued_at!r}>'.format(
                cls=self.__class__.__name__,
                id=self.id,
                issued_at=self.issued_at
            )

    return Transaction

Example 6

Project: postgresql-audit Source File: base.py
    def activity_model_factory(self, base):
        class Activity(activity_base(base, self.schema_name)):
            __tablename__ = 'activity'

            transaction_id = sa.Column(
                sa.BigInteger, sa.ForeignKey(self.transaction_cls.id)
            )
            transaction = sa.orm.relationship(
                self.transaction_cls,
                backref='activities'
            )

        return Activity

Example 7

Project: sqlalchemy-continuum Source File: table_builder.py
    @property
    def transaction_column(self):
        """
        Returns transaction column. By default the name of this column is
        'transaction_id'.
        """
        return sa.Column(
            self.option('transaction_column_name'),
            sa.BigInteger,
            primary_key=True,
            index=True,
            autoincrement=False  # This is needed for MySQL
        )

Example 8

Project: sqlalchemy-continuum Source File: table_builder.py
    @property
    def end_transaction_column(self):
        """
        Returns end_transaction column. By default the name of this column is
        'end_transaction_id'.
        """
        return sa.Column(
            self.option('end_transaction_column_name'),
            sa.BigInteger,
            index=True
        )

Example 9

Project: wtforms-alchemy Source File: test_select_field.py
    def test_big_integer_coerces_values_to_integers(self):
        choices = [(u'1', '1'), (u'2', '2')]
        self.init(type_=sa.BigInteger, info={'choices': choices})
        self.assert_type('test_column', SelectField)
        form = self.form_class(MultiDict({'test_column': '2'}))
        assert form.test_column.data is 2

Example 10

Project: cassiopeia Source File: team.py
def _sa_bind_team_member_info():
    global TeamMemberInfo

    @cassiopeia.type.core.common.inheritdocs
    class TeamMemberInfo(TeamMemberInfo, cassiopeia.type.dto.common.BaseDB):
        __tablename__ = "TeamMemberInfo"
        inviteDate = sqlalchemy.Column(sqlalchemy.BigInteger)
        joinDate = sqlalchemy.Column(sqlalchemy.BigInteger)
        playerId = sqlalchemy.Column(sqlalchemy.Integer)
        status = sqlalchemy.Column(sqlalchemy.String(30))
        _id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
        _roster_id = sqlalchemy.Column(sqlalchemy.Integer, sqlalchemy.ForeignKey("Roster._id", ondelete="CASCADE"))

Example 11

Project: tokenserver Source File: 6569dd9a060_populate_nodeid_column_and_index.py
def upgrade():
    # Populate nodeid with the proper id for each existing row.
    # XXX NOTE: MySQL-specific!
    op.execute("""
        UPDATE users, nodes
        SET users.nodeid = nodes.id
        WHERE users.node = nodes.node
    """.strip())
    # Set the column non-nullable so it doesn't mask bugs in the future.
    op.alter_column(
        'users', 'nodeid',
        nullable=False,
        existing_type=sa.BigInteger(),
        existing_server_default=None,
    )
    # Index the nodeid column.
    op.create_index('node_idx', 'users', ['nodeid'])

Example 12

Project: tokenserver Source File: 6569dd9a060_populate_nodeid_column_and_index.py
def downgrade():
    op.drop_index('node_idx', 'users')
    op.alter_column(
        'users', 'nodeid',
        nullable=True,
        existing_type=sa.BigInteger(),
        existing_server_default=None,
    )

Example 13

Project: tokenserver Source File: 846f28d1b6f_add_nodeid_column.py
def upgrade():
    # Create the column, making it nullable so that it can be
    # safely inserted in the present of existing data.
    # The next migration will make it non-nullable.
    op.add_column(
        'users',
        sa.Column('nodeid', sa.BigInteger(), nullable=True)
    )

Example 14

Project: sync-engine Source File: 081_move_imapfolder_highestmodseq_to_bigint.py
Function: upgrade
def upgrade():
    op.alter_column('imapfolderinfo', 'highestmodseq',
                    type_=sa.BigInteger, existing_type=sa.Integer,
                    existing_server_default=sa.sql.expression.null(),
                    existing_nullable=True)

    op.alter_column('imapfolderinfo', 'uidvalidity',
                    type_=sa.BigInteger, existing_type=sa.Integer,
                    existing_server_default=sa.sql.expression.null(),
                    existing_nullable=True)

Example 15

Project: networking-odl Source File: 3d560427d776_add_sequence_number_to_journal.py
def upgrade():
    op.create_table(
        'opendaylightjournal_new',
        sa.Column('seqnum', sa.BigInteger(),
                  primary_key=True, autoincrement=True),
        sa.Column('object_type', sa.String(36), nullable=False),
        sa.Column('object_uuid', sa.String(36), nullable=False),
        sa.Column('operation', sa.String(36), nullable=False),
        sa.Column('data', sa.PickleType, nullable=True),
        sa.Column('state',
                  sa.Enum('pending', 'processing', 'failed', 'completed',
                          name='state'),
                  nullable=False, default='pending'),
        sa.Column('retry_count', sa.Integer, default=0),
        sa.Column('created_at', sa.DateTime, default=sa.func.now()),
        sa.Column('last_retried', sa.TIMESTAMP, server_default=sa.func.now(),
                  onupdate=sa.func.now()),
    )

Example 16

Project: cassiopeia Source File: team.py
def _sa_bind_team():
    global Team

    @cassiopeia.type.core.common.inheritdocs
    class Team(Team, cassiopeia.type.dto.common.BaseDB):
        __tablename__ = "Team"
        createDate = sqlalchemy.Column(sqlalchemy.BigInteger)
        fullId = sqlalchemy.Column(sqlalchemy.String(50), primary_key=True)
        lastGameDate = sqlalchemy.Column(sqlalchemy.BigInteger)
        lastJoinDate = sqlalchemy.Column(sqlalchemy.BigInteger)
        lastJoinedRankedTeamQueueDate = sqlalchemy.Column(sqlalchemy.BigInteger)
        matchHistory = sqlalchemy.orm.relationship("cassiopeia.type.dto.team.MatchHistorySummary", cascade="all, delete-orphan", passive_deletes=True)
        modifyDate = sqlalchemy.Column(sqlalchemy.BigInteger)
        name = sqlalchemy.Column(sqlalchemy.String(30))
        roster = sqlalchemy.orm.relationship("cassiopeia.type.dto.team.Roster", uselist=False, cascade="all, delete-orphan", passive_deletes=True)
        secondLastJoinDate = sqlalchemy.Column(sqlalchemy.BigInteger)
        status = sqlalchemy.Column(sqlalchemy.String(30))
        tag = sqlalchemy.Column(sqlalchemy.String(30))
        teamStatDetails = sqlalchemy.orm.relationship("cassiopeia.type.dto.team.TeamStatDetail", cascade="all, delete-orphan", passive_deletes=True)
        thirdLastJoinDate = sqlalchemy.Column(sqlalchemy.BigInteger)

Example 17

Project: pybossa Source File: 25e478de8a63_big_int_for_oauth_id.py
Function: upgrade
def upgrade():
    op.alter_column('user', 'facebook_user_id', type_=sa.BigInteger)
    op.alter_column('user', 'twitter_user_id', type_=sa.BigInteger)

Example 18

Project: u2fval Source File: 11e35a5ccf8f_added_device_transport.py
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('devices', sa.Column('transports', sa.BigInteger(), nullable=True))

Example 19

Project: alembic Source File: test_postgresql.py
    @provide_metadata
    def _expect_default(self, c_expected, col, seq=None):
        Table('t', self.metadata, col)

        if seq:
            seq._set_metadata(self.metadata)
        self.metadata.create_all(config.db)

        insp = Inspector.from_engine(config.db)

        uo = ops.UpgradeOps(ops=[])
        _compare_tables(
            set([(None, 't')]), set([]),
            insp, self.metadata, uo, self.autogen_context)
        diffs = uo.as_diffs()
        tab = diffs[0][1]

        eq_(_render_server_default_for_compare(
            tab.c.x.server_default, tab.c.x, self.autogen_context),
            c_expected)

        insp = Inspector.from_engine(config.db)
        uo = ops.UpgradeOps(ops=[])
        m2 = MetaData()
        Table('t', m2, Column('x', BigInteger()))
        _compare_tables(
            set([(None, 't')]), set([(None, 't')]),
            insp, m2, uo, self.autogen_context)
        diffs = uo.as_diffs()
        server_default = diffs[0][0][4]['existing_server_default']
        eq_(_render_server_default_for_compare(
            server_default, tab.c.x, self.autogen_context),
            c_expected)

Example 20

Project: sqlalchemy Source File: test_dialect.py
    @testing.only_if(
        "postgresql >= 8.2", "requires standard_conforming_strings")
    def test_serial_integer(self):

        class BITD(TypeDecorator):
            impl = Integer

            def load_dialect_impl(self, dialect):
                if dialect.name == 'postgresql':
                    return BigInteger()
                else:
                    return Integer()

        for version, type_, expected in [
            (None, Integer, 'SERIAL'),
            (None, BigInteger, 'BIGSERIAL'),
            ((9, 1), SmallInteger, 'SMALLINT'),
            ((9, 2), SmallInteger, 'SMALLSERIAL'),
            (None, postgresql.INTEGER, 'SERIAL'),
            (None, postgresql.BIGINT, 'BIGSERIAL'),
            (
                None, Integer().with_variant(BigInteger(), 'postgresql'),
                'BIGSERIAL'),
            (
                None, Integer().with_variant(postgresql.BIGINT, 'postgresql'),
                'BIGSERIAL'),
            (
                (9, 2), Integer().with_variant(SmallInteger, 'postgresql'),
                'SMALLSERIAL'),
            (None, BITD(), 'BIGSERIAL')
        ]:
            m = MetaData()

            t = Table('t', m, Column('c', type_, primary_key=True))

            if version:
                dialect = postgresql.dialect()
                dialect._get_server_version_info = Mock(return_value=version)
                dialect.initialize(testing.db.connect())
            else:
                dialect = testing.db.dialect

            ddl_compiler = dialect.ddl_compiler(dialect, schema.CreateTable(t))
            eq_(
                ddl_compiler.get_column_specification(t.c.c),
                "c %s NOT NULL" % expected
            )

Example 21

Project: ReadableWebProxy Source File: 59204390db12_.py
Function: downgrade
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('web_files', 'id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())

Example 22

Project: ReadableWebProxy Source File: 8ae5aae58f62_.py
Function: upgrade
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('nu_release_item',
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('validated', sa.Boolean(), nullable=False),
    sa.Column('actual_target', sa.Text(), nullable=True),
    sa.Column('seriesname', sa.Text(), nullable=False),
    sa.Column('releaseinfo', sa.Text(), nullable=True),
    sa.Column('groupinfo', sa.Text(), nullable=False),
    sa.Column('referrer', sa.Text(), nullable=False),
    sa.Column('outbound_wrapper', sa.Text(), nullable=False),
    sa.Column('first_seen', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('seriesname', 'releaseinfo', 'groupinfo', 'outbound_wrapper', 'actual_target')
    )
    op.create_index(op.f('ix_nu_release_item_groupinfo'), 'nu_release_item', ['groupinfo'], unique=False)
    op.create_index(op.f('ix_nu_release_item_seriesname'), 'nu_release_item', ['seriesname'], unique=False)
    op.create_table('nu_resolved_outbound',
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('parent', sa.BigInteger(), nullable=False),
    sa.Column('client_id', sa.Text(), nullable=False),
    sa.Column('client_key', sa.Text(), nullable=False),
    sa.Column('actual_target', sa.Text(), nullable=False),
    sa.Column('fetched_on', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['parent'], ['nu_release_item.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('client_id', 'client_key', 'actual_target')
    )
    op.create_index(op.f('ix_nu_resolved_outbound_client_id'), 'nu_resolved_outbound', ['client_id'], unique=False)
    op.create_index(op.f('ix_nu_resolved_outbound_client_key'), 'nu_resolved_outbound', ['client_key'], unique=False)
    op.create_index(op.f('ix_nu_resolved_outbound_parent'), 'nu_resolved_outbound', ['parent'], unique=False)

Example 23

Project: ReadableWebProxy Source File: 9abd467440df_.py
Function: downgrade
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('plugin_status', 'id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('nu_outbound_wrappers', 'id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('feed_tags_link', 'tags_id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('feed_tags_link', 'releases_id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('feed_tags', 'id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('feed_pages', 'id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('feed_authors_link', 'releases_id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('feed_authors_link', 'author_id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())
    op.alter_column('feed_author', 'id',
               existing_type=sa.BigInteger(),
               type_=sa.INTEGER())

Example 24

Project: kcsrv Source File: df0fd0bd9bed_shove_expedition_related_things_into_.py
Function: upgrade
def upgrade():
### commands auto generated by Alembic - please adjust! ###
    op.add_column('expedition', sa.Column('time_taken', sa.BigInteger(), nullable=True))
    op.add_column('fleet', sa.Column('expedition_completed', sa.BigInteger(), nullable=True))

Example 25

Project: postgresql-audit Source File: base.py
def activity_base(Base, schema=None):
    class ActivityBase(Base):
        __abstract__ = True
        __table_args__ = {'schema': schema}
        id = sa.Column(sa.BigInteger, primary_key=True)
        schema_name = sa.Column(sa.Text)
        table_name = sa.Column(sa.Text)
        relid = sa.Column(sa.Integer)
        issued_at = sa.Column(sa.DateTime)
        native_transaction_id = sa.Column(sa.BigInteger)
        verb = sa.Column(sa.Text)
        old_data = sa.Column(JSONB)
        changed_data = sa.Column(JSONB)

        @hybrid_property
        def data(self):
            data = self.old_data.copy() if self.old_data else {}
            if self.changed_data:
                data.update(self.changed_data)
            return data

        @data.expression
        def data(cls):
            return jsonb_merge(cls.old_data, cls.changed_data)

        @property
        def object(self):
            table = Base.metadata.tables[self.table_name]
            cls = get_class_by_table(Base, table, self.data)
            return cls(**self.data)

        def __repr__(self):
            return (
                '<{cls} table_name={table_name!r} '
                'id={id!r}>'
            ).format(
                cls=self.__class__.__name__,
                table_name=self.table_name,
                id=self.id
            )
    return ActivityBase

Example 26

Project: sqlalchemy-continuum Source File: activity.py
Function: create_class
    def create_class(self, manager):
        """
        Create Activity class.
        """
        class Activity(
            manager.declarative_base,
            ActivityBase
        ):
            __tablename__ = 'activity'
            manager = self

            transaction_id = sa.Column(
                sa.BigInteger,
                index=True,
                nullable=False
            )

            data = sa.Column(JSONType)

            object_type = sa.Column(sa.String(255))

            object_id = sa.Column(sa.BigInteger)

            object_tx_id = sa.Column(sa.BigInteger)

            target_type = sa.Column(sa.String(255))

            target_id = sa.Column(sa.BigInteger)

            target_tx_id = sa.Column(sa.BigInteger)

            def _calculate_tx_id(self, obj):
                session = sa.orm.object_session(self)
                if obj:
                    object_version = version_obj(session, obj)
                    if object_version:
                        return object_version.transaction_id

                    version_cls = version_class(obj.__class__)
                    return session.query(
                        sa.func.max(version_cls.transaction_id)
                    ).filter(
                        version_cls.id == obj.id
                    ).scalar()

            def calculate_object_tx_id(self):
                self.object_tx_id = self._calculate_tx_id(self.object)

            def calculate_target_tx_id(self):
                self.target_tx_id = self._calculate_tx_id(self.target)

            object = generic_relationship(
                object_type, object_id
            )

            @hybrid_property
            def object_version_type(self):
                return self.object_type + 'Version'

            @object_version_type.expression
            def object_version_type(cls):
                return sa.func.concat(cls.object_type, 'Version')

            object_version = generic_relationship(
                object_version_type, (object_id, object_tx_id)
            )

            target = generic_relationship(
                target_type, target_id
            )

            @hybrid_property
            def target_version_type(self):
                return self.target_type + 'Version'

            @target_version_type.expression
            def target_version_type(cls):
                return sa.func.concat(cls.target_type, 'Version')

            target_version = generic_relationship(
                target_version_type, (target_id, target_tx_id)
            )

        Activity.transaction = sa.orm.relationship(
            manager.transaction_cls,
            backref=sa.orm.backref(
                'activities',
            ),
            primaryjoin=(
                '%s.id == Activity.transaction_id' %
                manager.transaction_cls.__name__
            ),
            foreign_keys=[Activity.transaction_id]
        )
        return Activity

Example 27

Project: security_monkey Source File: 6245d75fa12_exceptions_table.py
Function: upgrade
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('exceptions',
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('source', sa.String(length=256), nullable=False),
    sa.Column('occurred', sa.DateTime(), nullable=False),
    sa.Column('ttl', sa.DateTime(), nullable=False),
    sa.Column('type', sa.String(length=256), nullable=False),
    sa.Column('message', sa.String(length=512), nullable=True),
    sa.Column('stacktrace', sa.Text(), nullable=True),
    sa.Column('region', sa.String(length=32), nullable=True),
    sa.Column('tech_id', sa.Integer(), nullable=True),
    sa.Column('item_id', sa.Integer(), nullable=True),
    sa.Column('account_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['account_id'], ['account.id'], ),
    sa.ForeignKeyConstraint(['item_id'], ['item.id'], ),
    sa.ForeignKeyConstraint(['tech_id'], ['technology.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_exceptions_account_id', 'exceptions', ['account_id'], unique=False)
    op.create_index('ix_exceptions_item_id', 'exceptions', ['item_id'], unique=False)
    op.create_index('ix_exceptions_region', 'exceptions', ['region'], unique=False)
    op.create_index('ix_exceptions_source', 'exceptions', ['source'], unique=False)
    op.create_index('ix_exceptions_tech_id', 'exceptions', ['tech_id'], unique=False)
    op.create_index('ix_exceptions_type', 'exceptions', ['type'], unique=False)

Example 28

Project: pushkin Source File: 866d344d7b5d_ttl.py
Function: upgrade
def upgrade():
    op.add_column('message', sa.Column('expiry_millis', sa.BigInteger))

Example 29

Project: pushkin Source File: e2a42bcd4c02_initial_state.py
def upgrade():
    context = op.get_context()
    connection = op.get_bind()

    op.execute("ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO public;")

    if not context.dialect.has_table(connection.engine, 'login'):
        op.create_table('login',
            sa.Column('id', sa.BigInteger(), server_default=sa.text(u"NULL::BIGINT"), nullable=False),
            sa.Column('language_id', sa.SmallInteger(), nullable=True),
            sa.PrimaryKeyConstraint('id')
        )

    if not context.dialect.has_table(connection.engine, 'message'):
        op.create_table('message',
            sa.Column('id', sa.Integer(), nullable=False),
            sa.Column('name', sa.Text(), nullable=False),
            sa.Column('cooldown_ts', sa.BigInteger(), nullable=True),
            sa.Column('trigger_event_id', sa.Integer(), nullable=True),
            sa.Column('screen', sa.Text(), server_default=sa.text(u"''::text"), nullable=False),
            sa.PrimaryKeyConstraint('id'),
            sa.UniqueConstraint('name', name="c_message_unique_name")
        )

    if not context.dialect.has_table(connection.engine, 'device'):
        op.create_table('device',
            sa.Column('id', sa.Integer(), nullable=False),
            sa.Column('login_id', sa.BigInteger(), nullable=False),
            sa.Column('platform_id', sa.SmallInteger(), nullable=False),
            sa.Column('device_id', sa.Text(), nullable=False),
            sa.Column('device_token', sa.Text(), nullable=False),
            sa.Column('device_token_new', sa.Text(), nullable=True),
            sa.Column('application_version', sa.Integer(), nullable=True),
            sa.Column('unregistered_ts', sa.DateTime(), nullable=True),
            sa.ForeignKeyConstraint(['login_id'], ['login.id'], ondelete='CASCADE', name="Ref_device_to_login"),
            sa.PrimaryKeyConstraint('id'),
            sa.UniqueConstraint('login_id', 'platform_id', 'device_id', name="c_device_unique_user_device")
        )
        op.create_index(op.f('idx_device_login_id'), 'device', ['login_id'], unique=False)

    if not context.dialect.has_table(connection.engine, 'message_localization'):
        op.create_table('message_localization',
            sa.Column('id', sa.Integer(), nullable=False),
            sa.Column('message_id', sa.Integer(), nullable=False),
            sa.Column('language_id', sa.SmallInteger(), nullable=False),
            sa.Column('message_title', sa.Text(), nullable=False),
            sa.Column('message_text', sa.Text(), nullable=False),
            sa.ForeignKeyConstraint(['message_id'], ['message.id'], ondelete='CASCADE', name="ref_message_id_to_message"),
            sa.PrimaryKeyConstraint('id'),
            sa.UniqueConstraint('message_id', 'language_id', name="c_message_loc_unique_message_language")
        )

    if not context.dialect.has_table(connection.engine, 'user_message_last_time_sent'):
        op.create_table('user_message_last_time_sent',
            sa.Column('id', sa.Integer(), nullable=False),
            sa.Column('login_id', sa.BigInteger(), nullable=False),
            sa.Column('message_id', sa.Integer(), nullable=False),
            sa.Column('last_time_sent_ts_bigint', sa.BigInteger(), nullable=False),
            sa.ForeignKeyConstraint(['login_id'], ['login.id'], ondelete='CASCADE', name="ref_login_id_to_login"),
            sa.ForeignKeyConstraint(['message_id'], ['message.id'], ondelete='CASCADE', name="ref_message_id_to_message"),
            sa.PrimaryKeyConstraint('id'),
            sa.UniqueConstraint('login_id', 'message_id', name="c_user_unique_message")
        )

    op.execute(func_process_user_login)
    op.execute(func_get_elligible_user_message_pairs)
    op.execute(func_update_user_message_last_time_sent)
    op.execute(func_get_and_update_messages_to_send)
    op.execute(func_get_localized_message)
    op.execute(func_add_message)

Example 30

Project: sync-engine Source File: 007_per_provider_table_split.py
def downgrade_imapthread():
    from inbox.models.session import session_scope
    from inbox.ignition import main_engine
    engine = main_engine(pool_size=1, max_overflow=0)
    Base = declarative_base()
    Base.metadata.reflect(engine)

    class ImapThread_(Base):
        __table__ = Base.metadata.tables['imapthread']

    # Get data from table-to-be-dropped
    with session_scope() as db_session:
        results = db_session.query(ImapThread_.id, ImapThread_.g_thrid).all()
    to_insert = [dict(id=r[0], g_thrid=r[1]) for r in results]

    # Drop columns, add new columns + insert data
    op.drop_column('thread', 'type')
    op.add_column('thread', sa.Column('g_thrid', sa.BigInteger(),
                                      nullable=True, index=True))
    table_ = table('thread',
                   column('g_thrid', sa.BigInteger),
                   column('id', sa.Integer))

    for r in to_insert:
        op.execute(
            table_.update().
            where(table_.c.id == r['id']).
            values({'g_thrid': r['g_thrid']})
        )

    # Drop table
    op.drop_table('imapthread')

Example 31

Project: sync-engine Source File: 226_add_queryable_value_column_to_metadata.py
Function: upgrade
def upgrade():
    op.add_column('metadata', sa.Column('queryable_value', sa.BigInteger(),
                                        nullable=True))
    op.create_index(op.f('ix_metadata_queryable_value'), 'metadata',
                    ['queryable_value'], unique=False)

Example 32

Project: octavia Source File: c11292016060_add_request_errors_for_stats.py
Function: upgrade
def upgrade():
    op.add_column('listener_statistics',
                  sa.Column('request_errors', sa.BigInteger(),
                            nullable=False, default=0))