Python sqlalchemy.dialects.mysql.DATETIME Examples

The following are 20 code examples of sqlalchemy.dialects.mysql.DATETIME(). 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.dialects.mysql , or try the search function .
Example #1
Source File: end_to_end_test.py    From mysql_streamer with Apache License 2.0 7 votes vote down vote up
def actual_complex_data(self, complex_table_schema):
        res = {'id': 1}
        for indx, complex_column_schema in enumerate(complex_table_schema):
            if isinstance(complex_column_schema.sqla_obj, mysql.DATE):
                data = complex_column_schema.data.strftime('%Y-%m-%d')
            elif isinstance(complex_column_schema.sqla_obj, mysql.DATETIME):
                data = complex_column_schema.data.strftime('%Y-%m-%d %H:%M:%S.%f')
            elif isinstance(complex_column_schema.sqla_obj, mysql.TIMESTAMP):
                data = complex_column_schema.data.strftime('%Y-%m-%d %H:%M:%S.%f')
            elif isinstance(complex_column_schema.sqla_obj, mysql.TIME):
                time = datetime.time(
                    complex_column_schema.data.seconds / 3600,
                    (complex_column_schema.data.seconds / 60) % 60,
                    complex_column_schema.data.seconds % 60,
                    complex_column_schema.data.microseconds
                )
                data = time.strftime('%H:%M:%S.%f')
            else:
                data = complex_column_schema.data
            res.update({self._build_sql_column_name(indx): data})
        return res 
Example #2
Source File: end_to_end_test.py    From mysql_streamer with Apache License 2.0 6 votes vote down vote up
def expected_complex_data(self, actual_complex_data, complex_table_schema):
        expected_complex_data_dict = {'id': 1}
        for indx, complex_column_schema in enumerate(complex_table_schema):
            column_name = self._build_sql_column_name(indx)
            if isinstance(complex_column_schema.sqla_obj, mysql.SET):
                expected_complex_data_dict[column_name] = \
                    sorted(actual_complex_data[column_name])
            elif isinstance(complex_column_schema.sqla_obj, mysql.DATETIME):
                date_time_obj = \
                    complex_column_schema.data.isoformat()
                expected_complex_data_dict[column_name] = date_time_obj
            elif isinstance(complex_column_schema.sqla_obj, mysql.TIMESTAMP):
                date_time_obj = \
                    complex_column_schema.data.replace(tzinfo=pytz.utc)
                expected_complex_data_dict[column_name] = date_time_obj
            elif isinstance(complex_column_schema.sqla_obj, mysql.TIME):
                number_of_micros = transform_timedelta_to_number_of_microseconds(
                    complex_column_schema.data
                )
                expected_complex_data_dict[column_name] = number_of_micros
            else:
                expected_complex_data_dict[column_name] = \
                    complex_column_schema.data
        return expected_complex_data_dict 
Example #3
Source File: 95a62f05f603_create_schedules.py    From crmint with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('schedules',
    sa.Column('created_at', mysql.DATETIME(), nullable=False),
    sa.Column('updated_at', mysql.DATETIME(), nullable=False),
    sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
    sa.Column('cron', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('pipeline_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['pipeline_id'], [u'pipelines.id'], name=u'schedules_ibfk_1'),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset=u'utf8',
    mysql_engine=u'InnoDB'
    )
    # ### end Alembic commands ### 
Example #4
Source File: 207_add_contact_search_index_service_cursor_.py    From sync-engine with GNU Affero General Public License v3.0 5 votes vote down vote up
def downgrade():
    op.create_table('searchindexcursor',
                    sa.Column('created_at', mysql.DATETIME(), nullable=False),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=False),
                    sa.Column('deleted_at', mysql.DATETIME(), nullable=True),
                    sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
                    sa.Column('transaction_id', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True),
                    sa.ForeignKeyConstraint(['transaction_id'], [u'transaction.id'], name=u'searchindexcursor_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8mb4',
                    mysql_engine=u'InnoDB'
                    )
    op.drop_table('contactsearchindexcursor') 
Example #5
Source File: 030_add_is_read_attribute_to_messages.py    From sync-engine with GNU Affero General Public License v3.0 5 votes vote down vote up
def upgrade():
    op.add_column('message',
                  sa.Column('is_read', sa.Boolean(),
                            server_default=sa.sql.expression.false(),
                            nullable=False))

    op.alter_column('usertagitem', 'created_at',
                    existing_type=mysql.DATETIME(), nullable=False)
    op.alter_column('usertagitem', 'updated_at',
                    existing_type=mysql.DATETIME(), nullable=False)

    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 Message(Base):
        __table__ = Base.metadata.tables['message']

    class ImapUid(Base):
        __table__ = Base.metadata.tables['imapuid']
        message = relationship('Message',
                               backref=backref('imapuids',
                                               primaryjoin='and_('
                                               'Message.id == ImapUid.message_id, '
                                               'ImapUid.deleted_at == None)'),
                               primaryjoin='and_('
                               'ImapUid.message_id == Message.id,'
                               'Message.deleted_at == None)')

    with session_scope(versioned=False) as db_session:
        for uid in db_session.query(ImapUid).yield_per(500):
            if uid.is_seen:
                uid.message.is_read = True

        db_session.commit() 
Example #6
Source File: 223_time_mixins_fix.py    From sync-engine with GNU Affero General Public License v3.0 5 votes vote down vote up
def upgrade():
    conn = op.get_bind()
    conn.execute(text("ALTER TABLE accounttransaction "
                      " MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
    conn.execute(text("ALTER TABLE messagecategory"
                      " MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
    conn.execute(text("ALTER TABLE messagecontactassociation"
                      " MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
    conn.execute(text("ALTER TABLE transaction"
                      " MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))

    conn.execute(text("ALTER TABLE accounttransaction DROP updated_at,"
                      "DROP deleted_at"))
    conn.execute(text("ALTER TABLE messagecategory DROP updated_at,"
                      "DROP deleted_at"))
    conn.execute(text("ALTER TABLE messagecontactassociation DROP updated_at,"
                      "DROP deleted_at"))
    conn.execute(text("ALTER TABLE thread DROP deleted_at, DROP INDEX"
                      " ix_thread_namespace_id_recentdate_deleted_at"))
    conn.execute(text("ALTER TABLE transaction DROP deleted_at,"
                      "DROP updated_at"))
    if conn.engine.has_table('easdevice'):
        # Run EAS specific migrations
        conn.execute(text("ALTER TABLE easdevice"
                          " MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'"))
        conn.execute(text("ALTER TABLE easdevice DROP deleted_at,"
                          "DROP updated_at")) 
Example #7
Source File: 044_update_drafts_schema.py    From sync-engine with GNU Affero General Public License v3.0 5 votes vote down vote up
def downgrade():
    op.add_column('spoolmessage', sa.Column(u'replyto_thread_id',
                                            mysql.INTEGER(display_width=11),
                                            nullable=True))
    op.add_column('spoolmessage', sa.Column(u'draft_copied_from',
                                            mysql.INTEGER(display_width=11),
                                            nullable=True))
    op.drop_column('spoolmessage', 'is_reply')
    op.create_table(
        u'draftthread',
        sa.Column(u'created_at', mysql.DATETIME(), nullable=False),
        sa.Column(u'updated_at', mysql.DATETIME(), nullable=False),
        sa.Column(u'deleted_at', mysql.DATETIME(), nullable=True),
        sa.Column(u'public_id', sa.BINARY(length=16), nullable=False),
        sa.Column(u'id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column(u'master_public_id', sa.BINARY(length=16), nullable=False),
        sa.Column(u'thread_id', mysql.INTEGER(display_width=11),
                  autoincrement=False, nullable=False),
        sa.Column(u'message_id', mysql.INTEGER(display_width=11),
                  autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(['message_id'], [u'message.id'],
                                name=u'draftthread_ibfk_2'),
        sa.ForeignKeyConstraint(['thread_id'], [u'thread.id'],
                                name=u'draftthread_ibfk_1'),
        sa.PrimaryKeyConstraint(u'id'),
        mysql_default_charset=u'utf8mb4',
        mysql_engine=u'InnoDB'
    ) 
Example #8
Source File: sqlutil.py    From clgen with GNU General Public License v3.0 5 votes vote down vote up
def MillisecondDatetime(
    nullable: bool = False, default=labdate.GetUtcMillisecondsNow,
  ):
    """Return a datetime column with millisecond precision.

    Returns:
      A column which defaults to UTC now.
    """
    return sql.Column(
      sql.DateTime().with_variant(mysql.DATETIME(fsp=3), "mysql",),
      nullable=nullable,
      default=default,
    ) 
Example #9
Source File: sqlutil.py    From clgen with GNU General Public License v3.0 5 votes vote down vote up
def MillisecondDatetime():
    """Return a datetime type with millisecond precision.

    Returns:
      A column type.
    """
    return sql.DateTime().with_variant(mysql.DATETIME(fsp=3), "mysql") 
Example #10
Source File: models.py    From aodh with Apache License 2.0 5 votes vote down vote up
def load_dialect_impl(self, dialect):
        if dialect.name == 'mysql':
            return dialect.type_descriptor(mysql.DATETIME(fsp=6))
        return self.impl 
Example #11
Source File: sqlalchemy_types.py    From gnocchi with Apache License 2.0 5 votes vote down vote up
def load_dialect_impl(self, dialect):
        if dialect.name == 'mysql':
            return dialect.type_descriptor(mysql.DATETIME(fsp=6))
        return self.impl 
Example #12
Source File: 60f68ec8a068_create_general_settings.py    From crmint with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('general_settings',
                    sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=255), nullable=True),
                    sa.Column('value', sa.Text(), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=False),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB'
                    )
    # ### end Alembic commands ### 
Example #13
Source File: e34417c82307_new_model_to_track_.py    From crmint with Apache License 2.0 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('enqueued_tasks',
    sa.Column('created_at', mysql.DATETIME(), nullable=False),
    sa.Column('updated_at', mysql.DATETIME(), nullable=False),
    sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
    sa.Column('task_namespace', mysql.VARCHAR(length=100), nullable=True),
    sa.Column('task_name', mysql.VARCHAR(length=255), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    )
    # ### end Alembic commands ### 
Example #14
Source File: 3fca8951cd76_new_enforcements_table.py    From cloud-inquisitor with Apache License 2.0 5 votes vote down vote up
def upgrade():
    op.create_table('enforcements',
      sa.Column('enforcement_id', mysql.INTEGER(unsigned=True), nullable=False, autoincrement=True),
      sa.Column('account_id', mysql.INTEGER(unsigned=True)),
      sa.Column('resource_id', sa.String(length=256), nullable=False),
      sa.Column('action', sa.String(length=64), nullable=False),
      sa.Column('timestamp', mysql.DATETIME(timezone=False), default=func.now()),
      sa.Column('metrics', mysql.JSON()),
      sa.PrimaryKeyConstraint('enforcement_id')) 
Example #15
Source File: coin.py    From data_integration_celery with GNU General Public License v3.0 4 votes vote down vote up
def merge_latest(chain_param=None, ):
    """
    将 cmc_coin_v1_daily 历史数据 以及 cmc_coin_pro_latest 最新价格数据 合并到 cmc_coin_merged_latest
    :return:
    """
    table_name = 'cmc_coin_merged_latest'
    logger.info("开始合并数据到 %s 表", table_name)
    has_table = engine_md.has_table(table_name)
    create_sql_str = """CREATE TABLE {table_name} (
      `id` VARCHAR(60) NOT NULL,
      `date` DATE NOT NULL,
      `datetime` DATETIME NULL,
      `name` VARCHAR(60) NULL,
      `symbol` VARCHAR(20) NULL,
      `close` DOUBLE NULL,
      `volume` DOUBLE NULL,
      `market_cap` DOUBLE NULL,
      PRIMARY KEY (`id`, `date`))
    ENGINE = MyISAM""".format(table_name=table_name)
    with with_db_session(engine_md) as session:
        if not has_table:
            session.execute(create_sql_str)
            logger.info("创建 %s 表", table_name)
        session.execute('truncate table {table_name}'.format(table_name=table_name))
        insert_sql_str = """INSERT INTO `{table_name}` 
            (`id`, `date`, `datetime`, `name`, `symbol`, `close`, `volume`, `market_cap`) 
            select daily.id, `date`, `date`, `name`, `symbol`, `close`, `volume`, `market_cap` 
            from cmc_coin_v1_daily daily
            left join cmc_coin_v1_info info
            on daily.id = info.id""".format(table_name=table_name)
        session.execute(insert_sql_str)
        session.commit()
        insert_latest_sql_str = """INSERT INTO `{table_name}` 
            (`id`, `date`, `datetime`, `name`, `symbol`, `close`, `volume`, `market_cap`) 
            select info.id, date(latest.last_updated), latest.last_updated, 
                latest.name, latest.symbol, price, volume_24h, market_cap
            from cmc_coin_pro_latest latest
            left join
            (
                select latest.name, latest.symbol, max(latest.last_updated) last_updated
                from cmc_coin_pro_latest latest
                group by latest.name, latest.symbol
            ) g
            on latest.name = g.name
            and latest.symbol = g.symbol
            and latest.last_updated = g.last_updated
            left outer join cmc_coin_v1_info info
            on latest.name = info.name
            and latest.symbol = info.symbol
            on duplicate key update
                `datetime`=values(`datetime`), 
                `name`=values(`name`), 
                `symbol`=values(`symbol`), 
                `close`=values(`close`), 
                `volume`=values(`volume`), 
                `market_cap`=values(`market_cap`)""".format(table_name=table_name)
        session.execute(insert_latest_sql_str)
        session.commit()
        data_count = session.execute("select count(*) from {table_name}".format(table_name=table_name)).scalar()
        logger.info("%d 条记录插入到 %s", data_count, table_name) 
Example #16
Source File: coin.py    From data_integration_celery with GNU General Public License v3.0 4 votes vote down vote up
def import_coin_info(chain_param=None, ):
    """插入基础信息数据到 cmc_coin_v1_info"""
    table_name = "cmc_coin_v1_info"
    logging.info("更新 %s 开始", table_name)
    has_table = engine_md.has_table(table_name)
    # url = 'https://api.coinmarketcap.com/v2/listings/'
    # dtype = {
    #     'id': String(60),
    #     'name': String(60),
    #     'symbol': String(20),
    #     'website_slug': String(60),
    # }

    url = 'https://api.coinmarketcap.com/v1/ticker/?limit=0'
    dtype = {
        'id': String(60),
        'name': String(60),
        'symbol': String(20),
        'rank': Integer,
        'price_usd': DOUBLE,
        'price_btc': DOUBLE,
        '24h_volume_usd': DOUBLE,
        'market_cap_usd': DOUBLE,
        'available_supply': DOUBLE,
        'total_supply': DOUBLE,
        'max_supply': DOUBLE,
        'percent_change_1h': DOUBLE,
        'percent_change_24h': DOUBLE,
        'percent_change_7d': DOUBLE,
        'last_updated': DATETIME,
    }
    rsp = requests.get(url)
    if rsp.status_code != 200:
        raise ValueError('请求 listings 相应失败')
    json = rsp.json()
    data_df = pd.DataFrame(json)
    data_df['last_updated'] = data_df['last_updated'].apply(
        lambda x: None if x is None else datetime.datetime.fromtimestamp(float(x)))
    data_count = bunch_insert_on_duplicate_update(data_df, table_name, engine_md, dtype=dtype)
    logging.info("更新 %s 完成 存量数据 %d 条", table_name, data_count)
    if not has_table and engine_md.has_table(table_name):
        alter_table_2_myisam(engine_md, [table_name])
        # build_primary_key([table_name])
        create_pk_str = """ALTER TABLE {table_name}
        CHANGE COLUMN `id` `id` VARCHAR(60) NOT NULL FIRST ,
        ADD PRIMARY KEY (`id`)""".format(table_name=table_name)
        with with_db_session(engine_md) as session:
            session.execute(create_pk_str)

    # 更新 code_mapping 表
    # update_from_info_table(table_name) 
Example #17
Source File: 091_remove_webhooks.py    From sync-engine with GNU Affero General Public License v3.0 4 votes vote down vote up
def downgrade():
    op.create_table(
        'lens',
        sa.Column('public_id', sa.BINARY(length=16), nullable=False),
        sa.Column('created_at', mysql.DATETIME(), nullable=False),
        sa.Column('updated_at', mysql.DATETIME(), nullable=False),
        sa.Column('deleted_at', mysql.DATETIME(), nullable=True),
        sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column('namespace_id', mysql.INTEGER(display_width=11),
                  autoincrement=False, nullable=False),
        sa.Column('subject', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('thread_public_id', sa.BINARY(length=16), nullable=True),
        sa.Column('started_before', mysql.DATETIME(), nullable=True),
        sa.Column('started_after', mysql.DATETIME(), nullable=True),
        sa.Column('last_message_before', mysql.DATETIME(), nullable=True),
        sa.Column('last_message_after', mysql.DATETIME(), nullable=True),
        sa.Column('any_email', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('to_addr', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('from_addr', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('cc_addr', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('bcc_addr', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('filename', mysql.VARCHAR(length=255), nullable=True),
        sa.Column('tag', mysql.VARCHAR(length=255), nullable=True),
        sa.ForeignKeyConstraint(['namespace_id'], [u'namespace.id'],
                                name=u'lens_ibfk_1', ondelete=u'CASCADE'),
        sa.PrimaryKeyConstraint('id'),
        mysql_default_charset=u'utf8mb4',
        mysql_engine=u'InnoDB'
    )
    op.create_table(
        'webhook',
        sa.Column('public_id', sa.BINARY(length=16), nullable=False),
        sa.Column('created_at', mysql.DATETIME(), nullable=False),
        sa.Column('updated_at', mysql.DATETIME(), nullable=False),
        sa.Column('deleted_at', mysql.DATETIME(), nullable=True),
        sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column('namespace_id', mysql.INTEGER(display_width=11),
                  autoincrement=False, nullable=False),
        sa.Column('lens_id', mysql.INTEGER(display_width=11),
                  autoincrement=False, nullable=False),
        sa.Column('callback_url', mysql.TEXT(), nullable=False),
        sa.Column('failure_notify_url', mysql.TEXT(), nullable=True),
        sa.Column('include_body', mysql.TINYINT(display_width=1),
                  autoincrement=False, nullable=False),
        sa.Column('max_retries', mysql.INTEGER(display_width=11),
                  server_default='3', autoincrement=False, nullable=False),
        sa.Column('retry_interval', mysql.INTEGER(display_width=11),
                  server_default='60', autoincrement=False, nullable=False),
        sa.Column('active', mysql.TINYINT(display_width=1), server_default='1',
                  autoincrement=False, nullable=False),
        sa.Column('min_processed_id', mysql.INTEGER(display_width=11),
                  server_default='0', autoincrement=False, nullable=False),
        sa.ForeignKeyConstraint(['lens_id'], [u'lens.id'],
                                name=u'webhook_ibfk_2', ondelete=u'CASCADE'),
        sa.ForeignKeyConstraint(['namespace_id'], [u'namespace.id'],
                                name=u'webhook_ibfk_1', ondelete=u'CASCADE'),
        sa.PrimaryKeyConstraint('id'),
        mysql_default_charset=u'utf8mb4',
        mysql_engine=u'InnoDB'
    ) 
Example #18
Source File: 4addfa1236f1_add_fractional_seconds_to_mysql_tables.py    From airflow with Apache License 2.0 4 votes vote down vote up
def downgrade():   # noqa: D103
    if context.config.get_main_option('sqlalchemy.url').startswith('mysql'):
        op.alter_column(table_name='dag', column_name='last_scheduler_run',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='dag', column_name='last_pickled',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='dag', column_name='last_expired',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='dag_pickle', column_name='created_dttm',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='dag_run', column_name='execution_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='dag_run', column_name='start_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='dag_run', column_name='end_date',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='import_error', column_name='timestamp',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='job', column_name='start_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='job', column_name='end_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='job', column_name='latest_heartbeat',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='log', column_name='dttm',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='log', column_name='execution_date',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='sla_miss', column_name='execution_date',
                        type_=mysql.DATETIME(), nullable=False)
        op.alter_column(table_name='sla_miss', column_name='timestamp',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='task_fail', column_name='execution_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='task_fail', column_name='start_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='task_fail', column_name='end_date',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='task_instance', column_name='execution_date',
                        type_=mysql.DATETIME(),
                        nullable=False)
        op.alter_column(table_name='task_instance', column_name='start_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='task_instance', column_name='end_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='task_instance', column_name='queued_dttm',
                        type_=mysql.DATETIME())

        op.alter_column(table_name='xcom', column_name='timestamp',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='xcom', column_name='execution_date',
                        type_=mysql.DATETIME()) 
Example #19
Source File: 223_time_mixins_fix.py    From sync-engine with GNU Affero General Public License v3.0 4 votes vote down vote up
def downgrade():
    conn = op.get_bind()
    op.add_column('transaction', sa.Column('updated_at', mysql.DATETIME(),
                                           nullable=False))
    op.add_column('transaction', sa.Column('deleted_at', mysql.DATETIME(),
                                           nullable=True))
    op.create_index('ix_transaction_updated_at', 'transaction', ['updated_at'],
                    unique=False)
    op.create_index('ix_transaction_deleted_at', 'transaction', ['deleted_at'],
                    unique=False)

    op.add_column('thread', sa.Column('deleted_at', mysql.DATETIME(),
                                      nullable=True))
    op.create_index('ix_thread_deleted_at', 'thread', ['deleted_at'],
                    unique=False)
    op.create_index('ix_thread_namespace_id_recentdate_deleted_at', 'thread',
                    ['namespace_id', 'recentdate', 'deleted_at'], unique=False)

    op.add_column('messagecontactassociation', sa.Column('updated_at',
                                                         mysql.DATETIME(), nullable=False))
    op.add_column('messagecontactassociation', sa.Column('deleted_at',
                                                         mysql.DATETIME(), nullable=True))
    op.create_index('ix_messagecontactassociation_updated_at',
                    'messagecontactassociation', ['updated_at'], unique=False)
    op.create_index('ix_messagecontactassociation_deleted_at',
                    'messagecontactassociation', ['deleted_at'], unique=False)

    op.add_column('messagecategory', sa.Column('updated_at', mysql.DATETIME(),
                                               nullable=False))
    op.add_column('messagecategory', sa.Column('deleted_at', mysql.DATETIME(),
                                               nullable=True))
    op.create_index('ix_messagecategory_updated_at', 'messagecategory',
                    ['updated_at'], unique=False)
    op.create_index('ix_messagecategory_deleted_at', 'messagecategory',
                    ['deleted_at'], unique=False)

    op.add_column('accounttransaction', sa.Column('updated_at', mysql.DATETIME(), nullable=False))
    op.add_column('accounttransaction', sa.Column('deleted_at', mysql.DATETIME(), nullable=True))
    op.create_index('ix_accounttransaction_updated_at', 'accounttransaction', ['updated_at'], unique=False)
    op.create_index('ix_accounttransaction_deleted_at', 'accounttransaction', ['deleted_at'], unique=False)

    if conn.engine.has_table('easdevice'):
        op.add_column('easdevice', sa.Column('updated_at', mysql.DATETIME(), nullable=False))
        op.add_column('easdevice', sa.Column('deleted_at', mysql.DATETIME(), nullable=True))
        op.create_index('ix_easdevice_updated_at', 'easdevice', ['updated_at'], unique=False)
        op.create_index('ix_easdevice_deleted_at', 'easdevice', ['deleted_at'], unique=False) 
Example #20
Source File: 4addfa1236f1_add_fractional_seconds_to_mysql_tables.py    From airflow with Apache License 2.0 4 votes vote down vote up
def upgrade():   # noqa: D103
    if context.config.get_main_option('sqlalchemy.url').startswith('mysql'):
        op.alter_column(table_name='dag', column_name='last_scheduler_run',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='dag', column_name='last_pickled',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='dag', column_name='last_expired',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='dag_pickle', column_name='created_dttm',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='dag_run', column_name='execution_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='dag_run', column_name='start_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='dag_run', column_name='end_date',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='import_error', column_name='timestamp',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='job', column_name='start_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='job', column_name='end_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='job', column_name='latest_heartbeat',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='log', column_name='dttm',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='log', column_name='execution_date',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='sla_miss', column_name='execution_date',
                        type_=mysql.DATETIME(fsp=6),
                        nullable=False)
        op.alter_column(table_name='sla_miss', column_name='timestamp',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='task_fail', column_name='execution_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='task_fail', column_name='start_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='task_fail', column_name='end_date',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='task_instance', column_name='execution_date',
                        type_=mysql.DATETIME(fsp=6),
                        nullable=False)
        op.alter_column(table_name='task_instance', column_name='start_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='task_instance', column_name='end_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='task_instance', column_name='queued_dttm',
                        type_=mysql.DATETIME(fsp=6))

        op.alter_column(table_name='xcom', column_name='timestamp',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='xcom', column_name='execution_date',
                        type_=mysql.DATETIME(fsp=6))