Python sqlalchemy.TIMESTAMP Examples

The following are 30 code examples of sqlalchemy.TIMESTAMP(). 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: 6f7dfb241354_create_opendaylight_preiodic_task_table.py    From networking-odl with Apache License 2.0 7 votes vote down vote up
def upgrade():
    periodic_table = op.create_table(
        'opendaylight_periodic_task',
        sa.Column('state', sa.Enum(odl_const.PENDING, odl_const.PROCESSING,
                                   name='state'),
                  nullable=False),
        sa.Column('processing_operation', sa.String(70)),
        sa.Column('task', sa.String(70), primary_key=True),
        sa.Column('lock_updated', sa.TIMESTAMP, nullable=False,
                  server_default=sa.func.now(),
                  onupdate=sa.func.now())
    )
    op.bulk_insert(periodic_table,
                   [{'task': 'maintenance',
                     'state': odl_const.PENDING},
                    {'task': 'hostconfig',
                     'state': odl_const.PENDING}]) 
Example #2
Source File: test_types.py    From sqlalchemy with MIT License 6 votes vote down vote up
def test_date_coercion(self):
        expr = column("bar", types.NULLTYPE) - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.NullType)

        expr = func.sysdate() - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.Interval)

        expr = func.current_date() - column("foo", types.TIMESTAMP)
        eq_(expr.type._type_affinity, types.Interval) 
Example #3
Source File: 3d560427d776_add_sequence_number_to_journal.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: 703dbf02afde_add_journal_maintenance_table.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def upgrade():
    maint_table = op.create_table(
        'opendaylight_maintenance',
        sa.Column('id', sa.String(36), primary_key=True),
        sa.Column('state', sa.Enum(odl_const.PENDING, odl_const.PROCESSING,
                                   name='state'),
                  nullable=False),
        sa.Column('processing_operation', sa.String(70)),
        sa.Column('lock_updated', sa.TIMESTAMP, nullable=False,
                  server_default=sa.func.now(),
                  onupdate=sa.func.now())
    )

    # Insert the only row here that is used to synchronize the lock between
    # different Neutron processes.
    op.bulk_insert(maint_table,
                   [{'id': uuidutils.generate_uuid(),
                     'state': odl_const.PENDING}]) 
Example #5
Source File: 37e242787ae5_opendaylight_neutron_mechanism_driver_.py    From networking-odl with Apache License 2.0 6 votes vote down vote up
def upgrade():
    op.create_table(
        'opendaylightjournal',
        sa.Column('id', sa.String(36), primary_key=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 #6
Source File: test_codegen.py    From safrs with GNU General Public License v3.0 6 votes vote down vote up
def test_mysql_timestamp(metadata):
    Table("simple", metadata, Column("id", INTEGER, primary_key=True), Column("timestamp", mysql.TIMESTAMP))

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, Integer, TIMESTAMP
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class Simple(Base):
    __tablename__ = 'simple'

    id = Column(Integer, primary_key=True)
    timestamp = Column(TIMESTAMP)
"""
    ) 
Example #7
Source File: 0ddbd8cc99c2_update_group_to_graph_table.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
	# Drop OLD PKey
	op.drop_constraint('group_to_graph_pkey', 'group_to_graph', type_='primary')


	# Replacing group_id, owner_id with group id.
	op.alter_column('group_to_graph', 'group_id', new_column_name='old_group_id')
	op.add_column('group_to_graph', sa.Column('group_id', sa.Integer))
	op.execute('UPDATE group_to_graph SET group_id=g.id FROM "group" AS g WHERE g.group_id = old_group_id AND g.owner_email = group_owner;')
	op.drop_column('group_to_graph', 'old_group_id')
	op.drop_column('group_to_graph', 'group_owner')
	op.alter_column('group_to_graph', 'group_id', nullable=False)

	# Replacing graph_id, user_id. with graph id in group_to_graph table
	op.alter_column('group_to_graph', 'graph_id', new_column_name='old_graph_id')
	op.add_column('group_to_graph', sa.Column('graph_id', sa.Integer))
	op.execute('UPDATE group_to_graph SET graph_id=g.id FROM "graph" AS g WHERE g.name = group_to_graph.old_graph_id AND g.owner_email = group_to_graph.user_id;')
	op.drop_column('group_to_graph', 'old_graph_id')
	op.drop_column('group_to_graph', 'user_id')
	op.alter_column('group_to_graph', 'graph_id', nullable=False)


	# Add date columns
	op.alter_column('group_to_graph', 'modified', new_column_name='updated_at', server_default=sa.func.current_timestamp())
	op.add_column('group_to_graph', sa.Column('created_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))
	op.execute('UPDATE "group_to_graph" SET created_at=updated_at')

	# Add new pkey
	op.execute('ALTER TABLE "group_to_graph" ADD PRIMARY KEY (graph_id, group_id);')

	# Create New Index
	op.create_index('group2graph_idx_graph_id_group_id', 'group_to_graph', ['graph_id', 'group_id'], unique=True)

	# Add new foreign key reference

	op.execute('ALTER TABLE group_to_graph ADD CONSTRAINT group_to_graph_group_id_fkey FOREIGN KEY (group_id) REFERENCES "group" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;')
	op.execute('ALTER TABLE group_to_graph ADD CONSTRAINT group_to_graph_graph_id_fkey FOREIGN KEY (graph_id) REFERENCES "graph" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;') 
Example #8
Source File: 0a2a5b66e19d_add_task_reschedule_table.py    From airflow with Apache License 2.0 5 votes vote down vote up
def sa_timestamp():   # noqa: D103
    return sa.TIMESTAMP(timezone=True) 
Example #9
Source File: a8bd86b031b4_add_testcase_date_created.py    From zeus with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "testcase",
        sa.Column(
            "date_created",
            sa.TIMESTAMP(timezone=True),
            server_default=sa.text("now()"),
            nullable=False,
        ),
    )
    # ### end Alembic commands ### 
Example #10
Source File: 87cbddd5b946_add_artifact_dates.py    From zeus with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "artifact",
        sa.Column("date_finished", sa.TIMESTAMP(timezone=True), nullable=True),
    )
    op.add_column(
        "artifact",
        sa.Column("date_started", sa.TIMESTAMP(timezone=True), nullable=True),
    )
    op.add_column(
        "artifact",
        sa.Column("date_updated", sa.TIMESTAMP(timezone=True), nullable=True),
    )


# ### end Alembic commands ### 
Example #11
Source File: test_reflection.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_time_types(self):
        specs = []

        if testing.requires.mysql_fsp.enabled:
            fsps = [None, 0, 5]
        else:
            fsps = [None]

        for type_ in (mysql.TIMESTAMP, mysql.DATETIME, mysql.TIME):
            # MySQL defaults fsp to 0, and if 0 does not report it.
            # we don't actually render 0 right now in DDL but even if we do,
            # it comes back blank
            for fsp in fsps:
                if fsp:
                    specs.append((type_(fsp=fsp), type_(fsp=fsp)))
                else:
                    specs.append((type_(), type_()))

        specs.extend(
            [(TIMESTAMP(), mysql.TIMESTAMP()), (DateTime(), mysql.DATETIME())]
        )

        # note 'timezone' should always be None on both
        self._run_test(specs, ["fsp", "timezone"]) 
Example #12
Source File: test_types.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_timestamp_nullable(self, type_):
        ts_table = Table(
            "mysql_timestamp",
            self.metadata,
            Column("t1", type_),
            Column("t2", type_, nullable=False),
            mysql_engine="InnoDB",
        )
        self.metadata.create_all()

        # TIMESTAMP without NULL inserts current time when passed
        # NULL.  when not passed, generates 0000-00-00 quite
        # annoyingly.
        # the flag http://dev.mysql.com/doc/refman/5.6/en/\
        # server-system-variables.html#sysvar_explicit_defaults_for_timestamp
        # changes this for 5.6 if set.

        # normalize dates for the amount of time the operation took
        def normalize(dt):
            if dt is None:
                return None
            elif now <= dt <= new_now:
                return now
            else:
                return dt

        with testing.db.begin() as conn:
            now = conn.exec_driver_sql("select now()").scalar()
            conn.execute(ts_table.insert(), {"t1": now, "t2": None})
            conn.execute(ts_table.insert(), {"t1": None, "t2": None})
            conn.execute(ts_table.insert(), {"t2": None})

            new_now = conn.exec_driver_sql("select now()").scalar()

            eq_(
                [
                    tuple([normalize(dt) for dt in row])
                    for row in conn.execute(ts_table.select())
                ],
                [(now, now), (None, now), (None, now)],
            ) 
Example #13
Source File: 1782e8a9f689_scheduled_repo_updates.py    From zeus with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "repository",
        sa.Column("next_update", sa.TIMESTAMP(timezone=True), nullable=True),
    )
    # ### end Alembic commands ### 
Example #14
Source File: 4ff58ac07feb_update_edges_table_add_date_column.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
    # Add date columns
	op.add_column('edge', sa.Column('created_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))
	op.add_column('edge', sa.Column('updated_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp())) 
Example #15
Source File: 5ce0f29c368b_update_graph_to_tag_table.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
	# Drop OLD PKey
	op.drop_constraint('graph_to_tag_pkey', 'graph_to_tag', type_='primary')

	# Replacing graph_id, user_id. with graph id in graph_to_tag table
	op.alter_column('graph_to_tag', 'graph_id', new_column_name='old_graph_id')
	op.add_column('graph_to_tag', sa.Column('graph_id', sa.Integer))
	op.execute('UPDATE graph_to_tag SET graph_id=g.id FROM "graph" AS g WHERE g.name = graph_to_tag.old_graph_id AND g.owner_email = graph_to_tag.user_id;')
	op.drop_column('graph_to_tag', 'old_graph_id')
	op.drop_column('graph_to_tag', 'user_id')
	op.alter_column('graph_to_tag', 'graph_id', nullable=False)

	# Replacing tag_id with tag id in graph_to_tag table
	op.alter_column('graph_to_tag', 'tag_id', new_column_name='old_tag_id')
	op.add_column('graph_to_tag', sa.Column('tag_id', sa.Integer))
	op.execute('UPDATE graph_to_tag SET tag_id=graph_tag.id FROM graph_tag WHERE graph_tag.name = old_tag_id;')
	op.drop_column('graph_to_tag', 'old_tag_id')
	op.alter_column('graph_to_tag', 'tag_id', nullable=False)


	# Add date columns
	op.add_column('graph_to_tag', sa.Column('updated_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))
	op.add_column('graph_to_tag', sa.Column('created_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))

	# Add new pkey
	op.execute('ALTER TABLE "graph_to_tag" ADD PRIMARY KEY (graph_id, tag_id);')

	# Create New Index
	op.create_index('graph2tag_idx_graph_id_tag_id', 'graph_to_tag', ['graph_id', 'tag_id'], unique=True)

	# Add new foreign key reference
	op.execute('ALTER TABLE graph_to_tag ADD CONSTRAINT graph_to_tag_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES "graph_tag" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;')
	op.execute('ALTER TABLE graph_to_tag ADD CONSTRAINT graph_to_tag_graph_id_fkey FOREIGN KEY (graph_id) REFERENCES "graph" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;') 
Example #16
Source File: 636c6db82f8f_update_graph_tag_table.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
	# Update graph_tag table

	# Drop OLD PKey
	op.drop_constraint('graph_tag_pkey', 'graph_tag', type_='primary')

	# Add new ID Column
	op.execute('ALTER TABLE "graph_tag" ADD "id" SERIAL PRIMARY KEY UNIQUE;')

	# Add date columns
	op.add_column('graph_tag', sa.Column('updated_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))
	op.add_column('graph_tag', sa.Column('created_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))

	# Rename tag column
	op.alter_column('graph_tag', 'tag_id', new_column_name='name')

	# Create New Index
	op.create_index('graph_tag_name_key', 'graph_tag', ['name',], unique=True) 
Example #17
Source File: bfe3af4f7eae_job_date_updated.py    From zeus with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "job", sa.Column("date_updated", sa.TIMESTAMP(timezone=True), nullable=True)
    )


# ### end Alembic commands ### 
Example #18
Source File: f23f72f7eba0_update_group_to_user_table.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
	# Drop OLD PKey
	op.drop_constraint('group_to_user_pkey', 'group_to_user', type_='primary')

	# Replacing group id column
	op.alter_column('group_to_user', 'group_id', new_column_name='old_group_id')
	op.add_column('group_to_user', sa.Column('group_id', sa.Integer))
	op.execute('UPDATE group_to_user SET group_id=g.id FROM "group" AS g WHERE g.group_id = group_to_user.old_group_id AND g.owner_email = group_to_user.group_owner;')
	op.drop_column('group_to_user', 'old_group_id')
	op.drop_column('group_to_user', 'group_owner')
	op.alter_column('group_to_user', 'group_id', nullable=False)

	# Replacing user id column
	op.alter_column('group_to_user', 'user_id', new_column_name='old_user_id')
	op.add_column('group_to_user', sa.Column('user_id', sa.Integer))
	op.execute('UPDATE group_to_user SET user_id=u.id FROM "user" AS u WHERE u.email = group_to_user.old_user_id;')
	op.drop_column('group_to_user', 'old_user_id')
	op.alter_column('group_to_user', 'user_id', nullable=False)

	# Add date columns
	op.add_column('group_to_user', sa.Column('updated_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))
	op.add_column('group_to_user', sa.Column('created_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))

	# Add new pkey
	op.execute('ALTER TABLE "group_to_user" ADD PRIMARY KEY (user_id, group_id);')

	# Create New Index
	op.create_index('group2user_idx_user_id_group_id', 'group_to_user', ['user_id', 'group_id'], unique=True)

	# Add new foreign key reference

	op.execute('ALTER TABLE group_to_user ADD CONSTRAINT group_to_user_group_id_fkey FOREIGN KEY (group_id) REFERENCES "group" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;')
	op.execute('ALTER TABLE group_to_user ADD CONSTRAINT group_to_user_user_id_fkey FOREIGN KEY (user_id) REFERENCES "user" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE;') 
Example #19
Source File: 3ab443000c7e_update_password_reset_table.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
	# # password_reset_code
	op.rename_table('password_reset', 'password_reset_code')

	# Add date columns
	op.alter_column('password_reset_code', 'created', new_column_name='created_at', server_default=sa.func.current_timestamp())
	op.add_column('password_reset_code', sa.Column('updated_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))

	# Rename email column
	op.alter_column('password_reset_code', 'user_id', new_column_name='email')

	# Create New Index
	op.create_index('ix_password_reset_code_email_code', 'password_reset_code', ['email', 'code'], unique=True)
	op.create_index('ix_password_reset_code_email', 'password_reset_code', ['email'])

	# Add new foreign key reference
	op.execute('ALTER TABLE "password_reset_code" ADD CONSTRAINT password_reset_code_email_fkey FOREIGN KEY (email) REFERENCES "user" (email) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE') 
Example #20
Source File: ed8a5d6d9b4a_update_layout_table.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
	# Rename layout_id column
	op.alter_column('layout', 'layout_id', new_column_name='id')

	# Rename layout name column
	op.alter_column('layout', 'layout_name', new_column_name='name')

	# Rename email column
	op.alter_column('layout', 'owner_id', new_column_name='owner_email')

	# Rename shared_with_groups column
	op.execute('UPDATE layout SET shared_with_groups=0  WHERE shared_with_groups IS NULL;')
	op.alter_column('layout', 'shared_with_groups', new_column_name='is_shared', nullable=False)

	# Drop times_modified and public column
	op.drop_column('layout', 'times_modified')
	op.drop_column('layout', 'public')

	# Add date columns
	op.add_column('layout', sa.Column('created_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))
	op.add_column('layout', sa.Column('updated_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))

	# Replacing graph_id, user_id. with graph id in layout table
	op.alter_column('layout', 'graph_id', new_column_name='old_graph_id')
	op.add_column('layout', sa.Column('graph_id', sa.Integer))
	op.execute('UPDATE layout SET graph_id=g.id FROM "graph" AS g WHERE g.name = layout.old_graph_id AND g.owner_email = layout.user_id;')
	op.drop_column('layout', 'old_graph_id')
	op.drop_column('layout', 'user_id')
	op.alter_column('layout', 'graph_id', nullable=False)

	# Create New Index
	# It seems there are duplicate layout names for same owner and graph_id. Coz there was no unique constraint on the columns.
	# Solution: Drop one of the duplicate entries.

	op.execute('DELETE FROM layout WHERE ctid NOT IN (SELECT MAX(ctid) FROM layout GROUP BY name, graph_id, owner_email);')
	op.create_index('_layout_uc_name_graph_id_owner_email', 'layout', ['name', 'graph_id', 'owner_email'], unique=True)

	# Add new foreign key reference
	op.execute('ALTER TABLE "layout" ADD CONSTRAINT layout_graph_id_fkey FOREIGN KEY (graph_id) REFERENCES graph (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE') 
Example #21
Source File: 77a2637f243c_update_user_table.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
	# Drop OLD PKey
	op.drop_constraint('user_pkey', 'user', type_='primary')

	# Add new ID Column
	op.execute('ALTER TABLE "user" ADD "id" SERIAL PRIMARY KEY UNIQUE;')

	# Add date columns
	op.add_column('user', sa.Column('created_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))
	op.add_column('user', sa.Column('updated_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))

	# Rename admin column
	op.alter_column('user', 'admin', new_column_name='is_admin')
	op.execute('UPDATE "user" SET is_admin=0 WHERE is_admin is NULL')
	op.alter_column('user', 'is_admin', nullable=False)

	# Rename email column
	op.alter_column('user', 'user_id', new_column_name='email')

	# Create New Index
	op.create_index('ix_user_email', 'user', ['email'], unique=True) 
Example #22
Source File: bb85d8864dfa_update_group_table.py    From GraphSpace with GNU General Public License v2.0 5 votes vote down vote up
def upgrade():
	# Drop OLD PKey
	op.drop_constraint('group_pkey', 'group', type_='primary')

	# Add new ID Column
	op.execute('ALTER TABLE "group" ADD "id" SERIAL PRIMARY KEY UNIQUE;')

	# Add date columns
	op.add_column('group', sa.Column('created_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))
	op.add_column('group', sa.Column('updated_at', sa.TIMESTAMP, server_default=sa.func.current_timestamp()))

	# Rename email column
	op.alter_column('group', 'owner_id', new_column_name='owner_email')

	op.alter_column('group', 'description', nullable=True)

	# Create New Index
	op.create_index('_group_uc_name_owner_email', 'group', ['name', 'owner_email'], unique=True)

	# Add new foreign key reference
	op.execute('ALTER TABLE "group" ADD CONSTRAINT group_owner_email_fkey FOREIGN KEY ("owner_email") REFERENCES "user" (email) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE') 
Example #23
Source File: base.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, timezone=False, fsp=None):
        """Construct a MySQL TIMESTAMP type.

        :param timezone: not used by the MySQL dialect.
        :param fsp: fractional seconds precision value.
         MySQL 5.6.4 supports storage of fractional seconds;
         this parameter will be used when emitting DDL
         for the TIMESTAMP type.

         .. note::

            DBAPI driver support for fractional seconds may
            be limited; current support includes
            MySQL Connector/Python.

        .. versionadded:: 0.8.5 Added MySQL-specific :class:`.mysql.TIMESTAMP`
           with fractional seconds support.

        """
        super(TIMESTAMP, self).__init__(timezone=timezone)
        self.fsp = fsp 
Example #24
Source File: base.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def visit_typeclause(self, typeclause):
        type_ = typeclause.type.dialect_impl(self.dialect)
        if isinstance(type_, sqltypes.Integer):
            if getattr(type_, 'unsigned', False):
                return 'UNSIGNED INTEGER'
            else:
                return 'SIGNED INTEGER'
        elif isinstance(type_, sqltypes.TIMESTAMP):
            return 'DATETIME'
        elif isinstance(type_, (sqltypes.DECIMAL, sqltypes.DateTime,
                                sqltypes.Date, sqltypes.Time)):
            return self.dialect.type_compiler.process(type_)
        elif isinstance(type_, sqltypes.String) \
                and not isinstance(type_, (ENUM, SET)):
            adapted = CHAR._adapt_string_for_cast(type_)
            return self.dialect.type_compiler.process(adapted)
        elif isinstance(type_, sqltypes._Binary):
            return 'BINARY'
        elif isinstance(type_, sqltypes.NUMERIC):
            return self.dialect.type_compiler.process(
                type_).replace('NUMERIC', 'DECIMAL')
        else:
            return None 
Example #25
Source File: base.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def get_column_specification(self, column, **kw):
        """Builds column DDL."""

        colspec = [self.preparer.format_column(column),
                   self.dialect.type_compiler.process(column.type)
                   ]

        default = self.get_column_default_string(column)
        if default is not None:
            colspec.append('DEFAULT ' + default)

        is_timestamp = isinstance(column.type, sqltypes.TIMESTAMP)
        if not column.nullable and not is_timestamp:
            colspec.append('NOT NULL')

        # see: http://docs.sqlalchemy.org/en/latest/dialects/
        #   mysql.html#mysql_timestamp_null
        elif column.nullable and is_timestamp and default is None:
            colspec.append('NULL')

        if column is column.table._autoincrement_column and \
                column.server_default is None:
            colspec.append('AUTO_INCREMENT')

        return ' '.join(colspec) 
Example #26
Source File: base.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def visit_TIMESTAMP(self, type_):
        if getattr(type_, 'fsp', None):
            return "TIMESTAMP(%d)" % type_.fsp
        else:
            return "TIMESTAMP" 
Example #27
Source File: base.py    From sqlalchemy with MIT License 5 votes vote down vote up
def visit_typeclause(self, typeclause, type_=None, **kw):
        if type_ is None:
            type_ = typeclause.type.dialect_impl(self.dialect)
        if isinstance(type_, sqltypes.TypeDecorator):
            return self.visit_typeclause(typeclause, type_.impl, **kw)
        elif isinstance(type_, sqltypes.Integer):
            if getattr(type_, "unsigned", False):
                return "UNSIGNED INTEGER"
            else:
                return "SIGNED INTEGER"
        elif isinstance(type_, sqltypes.TIMESTAMP):
            return "DATETIME"
        elif isinstance(
            type_,
            (
                sqltypes.DECIMAL,
                sqltypes.DateTime,
                sqltypes.Date,
                sqltypes.Time,
            ),
        ):
            return self.dialect.type_compiler.process(type_)
        elif isinstance(type_, sqltypes.String) and not isinstance(
            type_, (ENUM, SET)
        ):
            adapted = CHAR._adapt_string_for_cast(type_)
            return self.dialect.type_compiler.process(adapted)
        elif isinstance(type_, sqltypes._Binary):
            return "BINARY"
        elif isinstance(type_, sqltypes.JSON):
            return "JSON"
        elif isinstance(type_, sqltypes.NUMERIC):
            return self.dialect.type_compiler.process(type_).replace(
                "NUMERIC", "DECIMAL"
            )
        else:
            return None 
Example #28
Source File: test_types.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_timestamp_fsp(self):
        self.assert_compile(mysql.TIMESTAMP(fsp=5), "TIMESTAMP(5)") 
Example #29
Source File: base.py    From sqlalchemy with MIT License 5 votes vote down vote up
def visit_TIMESTAMP(self, type_, **kw):
        if getattr(type_, "fsp", None):
            return "TIMESTAMP(%d)" % type_.fsp
        else:
            return "TIMESTAMP" 
Example #30
Source File: test_types.py    From sqlalchemy with MIT License 5 votes vote down vote up
def test_reflect_dates(self):
        metadata = self.metadata
        Table(
            "date_types",
            metadata,
            Column("d1", sqltypes.DATE),
            Column("d2", oracle.DATE),
            Column("d3", TIMESTAMP),
            Column("d4", TIMESTAMP(timezone=True)),
            Column("d5", oracle.INTERVAL(second_precision=5)),
        )
        metadata.create_all()
        m = MetaData(testing.db)
        t1 = Table("date_types", m, autoload=True)
        assert isinstance(t1.c.d1.type, oracle.DATE)
        assert isinstance(t1.c.d1.type, DateTime)
        assert isinstance(t1.c.d2.type, oracle.DATE)
        assert isinstance(t1.c.d2.type, DateTime)
        assert isinstance(t1.c.d3.type, TIMESTAMP)
        assert not t1.c.d3.type.timezone
        assert isinstance(t1.c.d4.type, TIMESTAMP)
        assert t1.c.d4.type.timezone
        assert isinstance(t1.c.d5.type, oracle.INTERVAL)