Python sqlalchemy.SmallInteger() Examples

The following are 22 code examples of sqlalchemy.SmallInteger(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlalchemy , or try the search function .
Example #1
Source File: sqlite.py    From boxball with Apache License 2.0 6 votes vote down vote up
def make_copy_ddl(self, metadata: MetaData) -> DdlString:
        copy_ddl_template = ".import {csv_file} {table_name}"
        ddl = [".mode csv"]
        for table_obj in metadata.tables.values():
            table_name: str = table_obj.fullname
            namespace = table_name[:table_name.index("_")]
            model_name = table_name[table_name.index("_") + 1:]
            csv_dir = self.data_path_prefix.joinpath(namespace)
            csv_file = csv_dir.joinpath(model_name).with_suffix(".csv")
            copy_ddl = copy_ddl_template.format(table_name=table_name, csv_file=csv_file)
            ddl.append(copy_ddl)

            ddl.append(f"UPDATE {table_name} SET")
            set_statements = []
            for col in table_obj.columns.values():
                col_name = col.name
                null_case = f"{col_name}=NULLIF({col_name}, '')"
                set_statements.append(null_case)
                if isinstance(col.type, SmallInteger):
                    bool_case = f"{col_name}=CASE {col_name} WHEN 'T' THEN 1 WHEN 'F' THEN 0 ELSE {col_name} END"
                    set_statements.append(bool_case)
            set_statement = ",\n".join(set_statements) + ";"
            ddl.append(set_statement)
        return "\n".join(ddl) 
Example #2
Source File: test_utils.py    From oslo.db with Apache License 2.0 6 votes vote down vote up
def test_change_deleted_column_type_to_boolean_with_fc(self):
        expected_types = {'mysql': mysql.TINYINT,
                          'ibm_db_sa': SmallInteger}
        table_name_1 = 'abc'
        table_name_2 = 'bcd'

        table_1 = Table(table_name_1, self.meta,
                        Column('id', Integer, primary_key=True),
                        Column('deleted', Integer))
        table_1.create()

        table_2 = Table(table_name_2, self.meta,
                        Column('id', Integer, primary_key=True),
                        Column('foreign_id', Integer,
                               ForeignKey('%s.id' % table_name_1)),
                        Column('deleted', Integer))
        table_2.create()

        utils.change_deleted_column_type_to_boolean(self.engine, table_name_2)

        table = utils.get_table(self.engine, table_name_2)
        self.assertIsInstance(table.c.deleted.type,
                              expected_types.get(self.engine.name, Boolean)) 
Example #3
Source File: fb42f7a67a6b_add_receiver_field_to_portals.py    From mautrix-hangouts with GNU Affero General Public License v3.0 6 votes vote down vote up
def upgrade():
    op.create_table("_portal_temp",
                    sa.Column("gid", sa.String(length=255), nullable=False),
                    sa.Column("receiver", sa.String(length=255), nullable=False, server_default=""),
                    sa.Column("conv_type", sa.SmallInteger(), nullable=False),
                    sa.Column("other_user_id", sa.String(length=255), nullable=True),
                    sa.Column("mxid", sa.String(length=255), nullable=True),
                    sa.Column("name", sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint("gid", "receiver"),
                    sa.UniqueConstraint("mxid"))
    c = op.get_bind()
    c.execute("INSERT INTO _portal_temp (gid, receiver, conv_type, other_user_id, mxid, name) "
              "SELECT portal.gid, (CASE WHEN portal.conv_type = 2 THEN portal.gid ELSE '' END), "
              "       portal.conv_type, portal.other_user_id, portal.mxid, portal.name "
              "FROM portal")
    c.execute("DROP TABLE portal")
    c.execute("ALTER TABLE _portal_temp RENAME TO portal") 
Example #4
Source File: 63ea9db2aa00_add_receiver_and_index_fields_to_.py    From mautrix-hangouts with GNU Affero General Public License v3.0 5 votes vote down vote up
def upgrade():
    op.drop_table("message")
    op.create_table("message",
                    sa.Column("mxid", sa.String(length=255), nullable=True),
                    sa.Column("mx_room", sa.String(length=255), nullable=True),
                    sa.Column("gid", sa.String(length=255), nullable=False),
                    sa.Column("receiver", sa.String(length=255), nullable=False),
                    sa.Column("index", sa.SmallInteger(), nullable=False),
                    sa.PrimaryKeyConstraint("gid", "receiver", "index"),
                    sa.UniqueConstraint("mxid", "mx_room", name="_mx_id_room")) 
Example #5
Source File: sqlite.py    From boxball with Apache License 2.0 5 votes vote down vote up
def metadata_transform(metadata: MetaData) -> MetaData:
        new_metadata = MetaData()
        for table in metadata.tables.values():
            # Need to namespace in the tablename because no schemas in sqlite
            table_name = "{}_{}".format(metadata.schema, table.name)
            # Remove dummy cols as no need for PKs (and we can't autoincrement anyway)
            # and change booleans to int to stop checks from generating in the ddl
            old_cols = [c for c in table.columns.values() if c.autoincrement is not True]
            new_cols = []
            for col in old_cols:
                typ = col.type if not isinstance(col.type, Boolean) else SmallInteger
                new_cols.append(Column(col.name, typ))

            Table(table_name, new_metadata, *new_cols)
        return new_metadata 
Example #6
Source File: 20170223015222_add_future_trade.py    From okcoin-socket-crawler with MIT License 5 votes vote down vote up
def upgrade():
    op.create_table(
        'future_trade',
        sa.Column('trade_id', sa.BigInteger, primary_key=True),
        sa.Column('price', sa.Float, nullable=False),
        sa.Column('amount', sa.Integer, nullable=False),
        sa.Column('timestamp', sa.Integer, nullable=False),
        sa.Column('trade_type', sa.SmallInteger, nullable=False),
        sa.Column('contract_type', sa.SmallInteger, nullable=False),
    )

    op.create_index('future_trade_timestamp_index', 'future_trade', ['timestamp']) 
Example #7
Source File: 1afd444fda6b_change_property_order_column_to_.py    From open-raadsinformatie with MIT License 5 votes vote down vote up
def upgrade():
    op.alter_column('property', 'order', type_=sa.SmallInteger)
    # ### commands auto generated by Alembic - please adjust! ###
    # ### end Alembic commands ### 
Example #8
Source File: 3c5af010538a_add_fb_receiver_to_message.py    From mautrix-facebook with GNU Affero General Public License v3.0 5 votes vote down vote up
def downgrade():
    op.drop_table('message')
    op.create_table('message',
                    sa.Column('mxid', sa.String(length=255), nullable=True),
                    sa.Column('mx_room', sa.String(length=255), nullable=True),
                    sa.Column('fbid', sa.String(length=127), nullable=False),
                    sa.Column('index', sa.SmallInteger(), nullable=False),
                    sa.PrimaryKeyConstraint('fbid', 'index'),
                    sa.UniqueConstraint('mxid', 'mx_room', name='_mx_id_room')) 
Example #9
Source File: 3c5af010538a_add_fb_receiver_to_message.py    From mautrix-facebook with GNU Affero General Public License v3.0 5 votes vote down vote up
def upgrade():
    op.drop_table('message')
    op.create_table('message',
                    sa.Column('mxid', sa.String(length=255), nullable=True),
                    sa.Column('mx_room', sa.String(length=255), nullable=True),
                    sa.Column('fbid', sa.String(length=127), nullable=False),
                    sa.Column('fb_receiver', sa.String(length=127), nullable=False),
                    sa.Column('index', sa.SmallInteger(), nullable=False),
                    sa.PrimaryKeyConstraint('fbid', 'fb_receiver', 'index'),
                    sa.UniqueConstraint('mxid', 'mx_room', name='_mx_id_room')) 
Example #10
Source File: fb42f7a67a6b_add_receiver_field_to_portals.py    From mautrix-hangouts with GNU Affero General Public License v3.0 5 votes vote down vote up
def downgrade():
    op.create_table("_portal_temp",
                    sa.Column("gid", sa.String(length=255), nullable=False),
                    sa.Column("conv_type", sa.SmallInteger(), nullable=False),
                    sa.Column("other_user_id", sa.String(length=255), nullable=True),
                    sa.Column("mxid", sa.String(length=255), nullable=True),
                    sa.Column("name", sa.String(), nullable=True),
                    sa.PrimaryKeyConstraint("gid"),
                    sa.UniqueConstraint("mxid"))
    c = op.get_bind()
    c.execute("INSERT INTO _portal_temp (gid, conv_type, other_user_id, mxid, name) "
              "SELECT portal.gid, portal.conv_type, portal.other_user_id, portal.mxid, portal.name "
              "FROM portal")
    c.execute("DROP TABLE portal")
    c.execute("ALTER TABLE _portal_temp RENAME TO portal") 
Example #11
Source File: test_utils.py    From oslo.db with Apache License 2.0 5 votes vote down vote up
def test_change_deleted_column_type_to_boolean(self):
        expected_types = {'mysql': mysql.TINYINT,
                          'ibm_db_sa': SmallInteger}
        table_name = 'abc'
        table = Table(table_name, self.meta,
                      Column('id', Integer, primary_key=True),
                      Column('deleted', Integer))
        table.create()

        utils.change_deleted_column_type_to_boolean(self.engine, table_name)

        table = utils.get_table(self.engine, table_name)
        self.assertIsInstance(table.c.deleted.type,
                              expected_types.get(self.engine.name, Boolean)) 
Example #12
Source File: sqlastorage.py    From Flask-Blogging with MIT License 5 votes vote down vote up
def _create_post_table(self):
        """
        Creates the table to store the blog posts.
        :return:
        """
        with self._engine.begin() as conn:
            post_table_name = self._table_name("post")
            if not conn.dialect.has_table(conn, post_table_name):

                self._post_table = sqla.Table(
                    post_table_name, self._metadata,
                    sqla.Column("id", sqla.Integer, primary_key=True),
                    sqla.Column("title", sqla.String(256)),
                    sqla.Column("text", sqla.Text),
                    sqla.Column("post_date", sqla.DateTime),
                    sqla.Column("last_modified_date", sqla.DateTime),
                    # if 1 then make it a draft
                    sqla.Column("draft", sqla.SmallInteger, default=0),
                    info=self._info

                )
                self._logger.debug("Created table with table name %s" %
                                   post_table_name)
            else:
                self._post_table = self._metadata.tables[post_table_name]
                self._logger.debug("Reflecting to table with table name %s" %
                                   post_table_name) 
Example #13
Source File: 7f447c94347a_.py    From website with MIT License 5 votes vote down vote up
def upgrade():
    op.add_column(
        "projects", sa.Column("uploads_count", sa.SmallInteger(), nullable=True)
    ) 
Example #14
Source File: table_builder.py    From ReadableWebProxy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def operation_type_column(self):
        """
        Return the operation type column. By default the name of this column
        is 'operation_type'.
        """
        return sa.Column(
            self.option('operation_type_column_name'),
            sa.SmallInteger,
            nullable=False,
            index=True
        ) 
Example #15
Source File: test_reflection.py    From sqlalchemy with MIT License 4 votes vote down vote up
def test_integer_types(self):
        specs = []
        for type_ in [
            mysql.TINYINT,
            mysql.SMALLINT,
            mysql.MEDIUMINT,
            mysql.INTEGER,
            mysql.BIGINT,
        ]:
            for display_width in [None, 4, 7]:
                for unsigned in [False, True]:
                    for zerofill in [None, True]:
                        kw = {}
                        if display_width:
                            kw["display_width"] = display_width
                        if unsigned is not None:
                            kw["unsigned"] = unsigned
                        if zerofill is not None:
                            kw["zerofill"] = zerofill

                        zerofill = bool(zerofill)
                        source_type = type_(**kw)

                        if display_width is None:
                            display_width = {
                                mysql.MEDIUMINT: 9,
                                mysql.SMALLINT: 6,
                                mysql.TINYINT: 4,
                                mysql.INTEGER: 11,
                                mysql.BIGINT: 20,
                            }[type_]

                        if zerofill:
                            unsigned = True

                        expected_type = type_(
                            display_width=display_width,
                            unsigned=unsigned,
                            zerofill=zerofill,
                        )
                        specs.append((source_type, expected_type))

        specs.extend(
            [
                (SmallInteger(), mysql.SMALLINT(display_width=6)),
                (Integer(), mysql.INTEGER(display_width=11)),
                (BigInteger, mysql.BIGINT(display_width=20)),
            ]
        )
        self._run_test(specs, ["display_width", "unsigned", "zerofill"]) 
Example #16
Source File: test_dialect.py    From sqlalchemy with MIT License 4 votes vote down vote up
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.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 #17
Source File: 00026_34f427187628_add_rss_bits.py    From ReadableWebProxy with 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('rss_parser_feed_name_lut_version',
    sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('feed_netloc', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('feed_name', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
    sa.Column('operation_type', sa.SmallInteger(), nullable=False),
    sa.PrimaryKeyConstraint('id', 'transaction_id')
    )
    op.create_index(op.f('ix_rss_parser_feed_name_lut_version_end_transaction_id'), 'rss_parser_feed_name_lut_version', ['end_transaction_id'], unique=False)
    op.create_index(op.f('ix_rss_parser_feed_name_lut_version_feed_name'), 'rss_parser_feed_name_lut_version', ['feed_name'], unique=False)
    op.create_index(op.f('ix_rss_parser_feed_name_lut_version_feed_netloc'), 'rss_parser_feed_name_lut_version', ['feed_netloc'], unique=False)
    op.create_index(op.f('ix_rss_parser_feed_name_lut_version_id'), 'rss_parser_feed_name_lut_version', ['id'], unique=False)
    op.create_index(op.f('ix_rss_parser_feed_name_lut_version_operation_type'), 'rss_parser_feed_name_lut_version', ['operation_type'], unique=False)
    op.create_index(op.f('ix_rss_parser_feed_name_lut_version_transaction_id'), 'rss_parser_feed_name_lut_version', ['transaction_id'], unique=False)
    op.create_table('rss_parser_funcs',
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('version', sa.Integer(), nullable=True),
    sa.Column('feed_name', sa.Text(), nullable=False),
    sa.Column('enabled', sa.Boolean(), nullable=True),
    sa.Column('func', sa.Text(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_rss_parser_funcs_feed_name'), 'rss_parser_funcs', ['feed_name'], unique=True)
    op.create_index(op.f('ix_rss_parser_funcs_id'), 'rss_parser_funcs', ['id'], unique=False)
    op.create_table('rss_parser_funcs_version',
    sa.Column('id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('version', sa.Integer(), autoincrement=False, nullable=True),
    sa.Column('feed_name', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('enabled', sa.Boolean(), autoincrement=False, nullable=True),
    sa.Column('func', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
    sa.Column('operation_type', sa.SmallInteger(), nullable=False),
    sa.PrimaryKeyConstraint('id', 'transaction_id')
    )
    op.create_index(op.f('ix_rss_parser_funcs_version_end_transaction_id'), 'rss_parser_funcs_version', ['end_transaction_id'], unique=False)
    op.create_index(op.f('ix_rss_parser_funcs_version_feed_name'), 'rss_parser_funcs_version', ['feed_name'], unique=False)
    op.create_index(op.f('ix_rss_parser_funcs_version_id'), 'rss_parser_funcs_version', ['id'], unique=False)
    op.create_index(op.f('ix_rss_parser_funcs_version_operation_type'), 'rss_parser_funcs_version', ['operation_type'], unique=False)
    op.create_index(op.f('ix_rss_parser_funcs_version_transaction_id'), 'rss_parser_funcs_version', ['transaction_id'], unique=False)
    op.create_table('rss_parser_feed_name_lut',
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('feed_netloc', sa.Text(), nullable=False),
    sa.Column('feed_name', sa.Text(), nullable=False),
    sa.ForeignKeyConstraint(['feed_name'], ['rss_parser_funcs.feed_name'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('feed_netloc', 'feed_name')
    )
    op.create_index(op.f('ix_rss_parser_feed_name_lut_feed_name'), 'rss_parser_feed_name_lut', ['feed_name'], unique=False)
    op.create_index(op.f('ix_rss_parser_feed_name_lut_feed_netloc'), 'rss_parser_feed_name_lut', ['feed_netloc'], unique=False)
    op.create_index(op.f('ix_rss_parser_feed_name_lut_id'), 'rss_parser_feed_name_lut', ['id'], unique=False)


    ### end Alembic commands ### 
Example #18
Source File: c36b294b1f5f_initial_revision.py    From mautrix-facebook with GNU Affero General Public License v3.0 4 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('message',
    sa.Column('mxid', sa.String(length=255), nullable=True),
    sa.Column('mx_room', sa.String(length=255), nullable=True),
    sa.Column('fbid', sa.String(length=127), nullable=False),
    sa.Column('index', sa.SmallInteger(), nullable=False),
    sa.PrimaryKeyConstraint('fbid', 'index'),
    sa.UniqueConstraint('mxid', 'mx_room', name='_mx_id_room')
    )
    op.create_table('mx_room_state',
    sa.Column('room_id', sa.String(length=255), nullable=False),
    sa.Column('power_levels', PowerLevelType(), nullable=True),
    sa.PrimaryKeyConstraint('room_id')
    )
    op.create_table('mx_user_profile',
    sa.Column('room_id', sa.String(length=255), nullable=False),
    sa.Column('user_id', sa.String(length=255), nullable=False),
    sa.Column('membership', sa.Enum('JOIN', 'LEAVE', 'INVITE', 'BAN', 'KNOCK', name='membership'), nullable=False),
    sa.Column('displayname', sa.String(), nullable=True),
    sa.Column('avatar_url', sa.String(length=255), nullable=True),
    sa.PrimaryKeyConstraint('room_id', 'user_id')
    )
    op.create_table('portal',
    sa.Column('fbid', sa.String(length=127), nullable=False),
    sa.Column('fb_receiver', sa.String(length=127), nullable=False),
    sa.Column('fb_type', sa.Enum('USER', 'GROUP', 'ROOM', 'PAGE', name='threadtype'), nullable=False),
    sa.Column('mxid', sa.String(length=255), nullable=True),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('photo_id', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('fbid', 'fb_receiver'),
    sa.UniqueConstraint('mxid')
    )
    op.create_table('puppet',
    sa.Column('fbid', sa.String(), nullable=False),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('photo_id', sa.String(), nullable=True),
    sa.Column('matrix_registered', sa.Boolean(), server_default=sa.text('false'), nullable=False),
    sa.PrimaryKeyConstraint('fbid')
    )
    op.create_table('user',
    sa.Column('mxid', sa.String(length=255), nullable=False),
    sa.Column('session', sa.PickleType(), nullable=True),
    sa.Column('fbid', sa.String(length=255), nullable=True),
    sa.PrimaryKeyConstraint('mxid')
    )
    # ### end Alembic commands ### 
Example #19
Source File: bfb775ce2cee_initial_revision.py    From mautrix-hangouts with GNU Affero General Public License v3.0 4 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('message',
    sa.Column('mxid', sa.String(length=255), nullable=True),
    sa.Column('mx_room', sa.String(length=255), nullable=True),
    sa.Column('gid', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('gid'),
    sa.UniqueConstraint('mxid', 'mx_room', name='_mx_id_room')
    )
    op.create_table('mx_room_state',
    sa.Column('room_id', sa.String(length=255), nullable=False),
    sa.Column('power_levels', PowerLevelType(), nullable=True),
    sa.PrimaryKeyConstraint('room_id')
    )
    op.create_table('mx_user_profile',
    sa.Column('room_id', sa.String(length=255), nullable=False),
    sa.Column('user_id', sa.String(length=255), nullable=False),
    sa.Column('membership', sa.Enum('JOIN', 'LEAVE', 'INVITE', 'BAN', 'KNOCK', name='membership'), nullable=False),
    sa.Column('displayname', sa.String(), nullable=True),
    sa.Column('avatar_url', sa.String(length=255), nullable=True),
    sa.PrimaryKeyConstraint('room_id', 'user_id')
    )
    op.create_table('portal',
    sa.Column('gid', sa.String(length=255), nullable=False),
    sa.Column('conv_type', sa.SmallInteger(), nullable=False),
    sa.Column('other_user_id', sa.String(length=255), nullable=True),
    sa.Column('mxid', sa.String(length=255), nullable=True),
    sa.Column('name', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('gid'),
    sa.UniqueConstraint('mxid')
    )
    op.create_table('puppet',
    sa.Column('gid', sa.String(length=255), nullable=False),
    sa.Column('name', sa.String(length=255), nullable=True),
    sa.Column('photo_url', sa.String(length=255), nullable=True),
    sa.Column('matrix_registered', sa.Boolean(), server_default=sa.text('false'), nullable=False),
    sa.Column('custom_mxid', sa.String(length=255), nullable=True),
    sa.Column('access_token', sa.Text(), nullable=True),
    sa.PrimaryKeyConstraint('gid')
    )
    op.create_table('user',
    sa.Column('mxid', sa.String(length=255), nullable=False),
    sa.Column('gid', sa.String(length=255), nullable=True),
    sa.Column('refresh_token', sa.String(length=255), nullable=True),
    sa.PrimaryKeyConstraint('mxid')
    )
    # ### end Alembic commands ### 
Example #20
Source File: 8627a80874a6_add_vehicle_and_fuellog_models.py    From biweeklybudget with GNU Affero General Public License v3.0 4 votes vote down vote up
def upgrade():
    op.create_table(
        'vehicles',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=254), nullable=True),
        sa.Column('is_active', sa.Boolean(), nullable=True),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_vehicles')),
        mysql_engine='InnoDB'
    )
    op.create_table(
        'fuellog',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('date', sa.Date(), nullable=True),
        sa.Column('vehicle_id', sa.Integer(), nullable=True),
        sa.Column('odometer_miles', sa.Integer(), nullable=True),
        sa.Column('reported_miles', sa.SmallInteger(), nullable=True),
        sa.Column('calculated_miles', sa.SmallInteger(), nullable=True),
        sa.Column('level_before', sa.SmallInteger(), nullable=True),
        sa.Column('level_after', sa.SmallInteger(), nullable=True),
        sa.Column('fill_location', sa.String(length=254), nullable=True),
        sa.Column(
            'cost_per_gallon',
            sa.Numeric(precision=10, scale=4),
            nullable=True
        ),
        sa.Column(
            'total_cost',
            sa.Numeric(precision=10, scale=4),
            nullable=True
        ),
        sa.Column(
            'gallons',
            sa.Numeric(precision=10, scale=4),
            nullable=True
        ),
        sa.Column(
            'reported_mpg',
            sa.Numeric(precision=10, scale=4),
            nullable=True
        ),
        sa.Column(
            'calculated_mpg',
            sa.Numeric(precision=10, scale=4),
            nullable=True
        ),
        sa.Column('notes', sa.String(length=254), nullable=True),
        sa.ForeignKeyConstraint(
            ['vehicle_id'],
            ['vehicles.id'],
            name=op.f('fk_fuellog_vehicle_id_vehicles')
        ),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_fuellog')),
        mysql_engine='InnoDB'
    ) 
Example #21
Source File: 00005_f6cfe0a6836c_new_versioning_thing.py    From ReadableWebProxy with 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('transaction',
    sa.Column('issued_at', sa.DateTime(), nullable=True),
    sa.Column('id', sa.BigInteger(), nullable=False),
    sa.Column('remote_addr', sa.String(length=50), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('web_pages_version',
    sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
    sa.Column('state', postgresql.ENUM('new', 'fetching', 'processing', 'complete', 'error', 'removed', name='dlstate_enum', create_type=False), autoincrement=False, nullable=True),
    sa.Column('errno', sa.Integer(), autoincrement=False, nullable=True),
    sa.Column('url', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('starturl', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('netloc', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('file', sa.Integer(), autoincrement=False, nullable=True),
    sa.Column('priority', sa.Integer(), autoincrement=False, nullable=True),
    sa.Column('distance', sa.Integer(), autoincrement=False, nullable=True),
    sa.Column('is_text', sa.Boolean(), autoincrement=False, nullable=True),
    sa.Column('limit_netloc', sa.Boolean(), autoincrement=False, nullable=True),
    sa.Column('title', citext.CIText(), autoincrement=False, nullable=True),
    sa.Column('mimetype', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('type', postgresql.ENUM('western', 'eastern', 'unknown', name='itemtype_enum', create_type=False), autoincrement=False, nullable=True),
    sa.Column('content', sa.Text(), autoincrement=False, nullable=True),
    sa.Column('fetchtime', sa.DateTime(), autoincrement=False, nullable=True),
    sa.Column('addtime', sa.DateTime(), autoincrement=False, nullable=True),
    sa.Column('ignoreuntiltime', sa.DateTime(), autoincrement=False, nullable=True),
    sa.Column('normal_fetch_mode', sa.Boolean(), autoincrement=False, nullable=True),
    sa.Column('tsv_content', sqlalchemy_utils.types.ts_vector.TSVectorType(), autoincrement=False, nullable=True),
    sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
    sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
    sa.Column('operation_type', sa.SmallInteger(), nullable=False),
    sa.PrimaryKeyConstraint('id', 'transaction_id')
    )
    # op.create_index(op.f('ix_web_pages_version_distance'), 'web_pages_version', ['distance'], unique=False)
    # op.create_index(op.f('ix_web_pages_version_ignoreuntiltime'), 'web_pages_version', ['ignoreuntiltime'], unique=False)
    # op.create_index(op.f('ix_web_pages_version_netloc'), 'web_pages_version', ['netloc'], unique=False)
    # op.create_index(op.f('ix_web_pages_version_priority'), 'web_pages_version', ['priority'], unique=False)
    # op.create_index(op.f('ix_web_pages_version_state'), 'web_pages_version', ['state'], unique=False)
    # op.create_index('ix_web_pages_version_tsv_content', 'web_pages_version', ['tsv_content'], unique=False, postgresql_using='gin')
    # op.create_index(op.f('ix_web_pages_version_type'), 'web_pages_version', ['type'], unique=False)

    op.create_index(op.f('ix_web_pages_version_id'), 'web_pages_version', ['id'], unique=False)
    op.create_index(op.f('ix_web_pages_version_operation_type'), 'web_pages_version', ['operation_type'], unique=False)
    op.create_index(op.f('ix_web_pages_version_transaction_id'), 'web_pages_version', ['transaction_id'], unique=False)
    op.create_index(op.f('ix_web_pages_version_end_transaction_id'), 'web_pages_version', ['end_transaction_id'], unique=False)
    op.create_index(op.f('ix_web_pages_version_url'), 'web_pages_version', ['url'], unique=False)
    ### end Alembic commands ### 
Example #22
Source File: 00040_7f63439f1380_.py    From ReadableWebProxy with 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('raw_web_pages',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('state', postgresql.ENUM('new', 'fetching', 'processing', 'complete', 'error', 'removed', 'disabled', 'specialty_deferred', 'specialty_ready', name='dlstate_enum', create_type=False), nullable=False),
        sa.Column('errno', sa.Integer(), nullable=True),
        sa.Column('url', sa.Text(), nullable=False),
        sa.Column('starturl', sa.Text(), nullable=False),
        sa.Column('netloc', sa.Text(), nullable=False),
        sa.Column('priority', sa.Integer(), nullable=False),
        sa.Column('distance', sa.Integer(), nullable=False),
        sa.Column('is_text', sa.Boolean(), nullable=True),
        sa.Column('mimetype', sa.Text(), nullable=True),
        sa.Column('filename', sa.Text(), nullable=True),
        sa.Column('fspath', sa.Text(), nullable=False),
        sa.Column('fetchtime', sa.DateTime(), nullable=True),
        sa.Column('addtime', sa.DateTime(), nullable=True),
        sa.Column('ignoreuntiltime', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_raw_web_pages_distance'), 'raw_web_pages', ['distance'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_id'), 'raw_web_pages', ['id'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_netloc'), 'raw_web_pages', ['netloc'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_priority'), 'raw_web_pages', ['priority'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_state'), 'raw_web_pages', ['state'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_url'), 'raw_web_pages', ['url'], unique=True)
    op.create_table('raw_web_pages_version',
        sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
        sa.Column('state', postgresql.ENUM('new', 'fetching', 'processing', 'complete', 'error', 'removed', 'disabled', 'specialty_deferred', 'specialty_ready', name='dlstate_enum', create_type=False), autoincrement=False, nullable=True),
        sa.Column('errno', sa.Integer(), autoincrement=False, nullable=True),
        sa.Column('url', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('starturl', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('netloc', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('priority', sa.Integer(), autoincrement=False, nullable=True),
        sa.Column('distance', sa.Integer(), autoincrement=False, nullable=True),
        sa.Column('is_text', sa.Boolean(), autoincrement=False, nullable=True),
        sa.Column('mimetype', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('filename', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('fspath', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('fetchtime', sa.DateTime(), autoincrement=False, nullable=True),
        sa.Column('addtime', sa.DateTime(), autoincrement=False, nullable=True),
        sa.Column('ignoreuntiltime', sa.DateTime(), autoincrement=False, nullable=True),
        sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False),
        sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
        sa.Column('operation_type', sa.SmallInteger(), nullable=False),
        sa.PrimaryKeyConstraint('id', 'transaction_id')
    )
    op.create_index(op.f('ix_raw_web_pages_version_distance'), 'raw_web_pages_version', ['distance'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_version_end_transaction_id'), 'raw_web_pages_version', ['end_transaction_id'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_version_id'), 'raw_web_pages_version', ['id'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_version_netloc'), 'raw_web_pages_version', ['netloc'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_version_operation_type'), 'raw_web_pages_version', ['operation_type'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_version_priority'), 'raw_web_pages_version', ['priority'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_version_state'), 'raw_web_pages_version', ['state'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_version_transaction_id'), 'raw_web_pages_version', ['transaction_id'], unique=False)
    op.create_index(op.f('ix_raw_web_pages_version_url'), 'raw_web_pages_version', ['url'], unique=False)
    ### end Alembic commands ###