예제 #1
0
 def load_dialect_impl(self, dialect):
     if dialect.name == 'mysql':
         return dialect.type_descriptor(mysql.DATETIME(fsp=6))
     return self.impl
예제 #2
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'lead_requests', type_='foreignkey')
    op.drop_column('lead_requests', 'user_id')
    op.create_table('subscriptions',
                    sa.Column('plan_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('yearly',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('subscription_date',
                              mysql.DATETIME(),
                              nullable=True),
                    sa.Column('next_payment', mysql.DATETIME(), nullable=True),
                    sa.ForeignKeyConstraint(['plan_id'], ['plans.id'],
                                            name='subscriptions_ibfk_1'),
                    sa.ForeignKeyConstraint(['user_id'], ['users.id'],
                                            name='subscriptions_ibfk_2'),
                    sa.PrimaryKeyConstraint('plan_id', 'user_id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_table('leads',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=True,
                              nullable=False),
                    sa.Column('creation_date', mysql.DATETIME(),
                              nullable=True),
                    sa.Column('company_name',
                              mysql.VARCHAR(length=120),
                              nullable=True),
                    sa.Column('company_address',
                              mysql.VARCHAR(length=120),
                              nullable=True),
                    sa.Column('company_postal_code',
                              mysql.VARCHAR(length=30),
                              nullable=True),
                    sa.Column('company_city',
                              mysql.VARCHAR(length=60),
                              nullable=True),
                    sa.Column('company_email',
                              mysql.VARCHAR(length=120),
                              nullable=True),
                    sa.Column('company_email_bcc',
                              mysql.VARCHAR(length=120),
                              nullable=True),
                    sa.Column('company_phone',
                              mysql.VARCHAR(length=60),
                              nullable=True),
                    sa.Column('company_activity_field',
                              mysql.VARCHAR(length=60),
                              nullable=False),
                    sa.Column('owner_firstname',
                              mysql.VARCHAR(length=60),
                              nullable=True),
                    sa.Column('owner_lastname',
                              mysql.VARCHAR(length=60),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
예제 #3
0
def upgrade():
    """Upgrade database."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'oarepo_references_classname',
        sa.Column('created',
                  sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
                  nullable=False),
        sa.Column('updated',
                  sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
                  nullable=False), sa.Column('id',
                                             sa.Integer(),
                                             nullable=False),
        sa.Column('name', sa.String(), nullable=True),
        sa.PrimaryKeyConstraint('id',
                                name=op.f('pk_oarepo_references_classname')))
    op.create_index(op.f('ix_oarepo_references_classname_name'),
                    'oarepo_references_classname', ['name'],
                    unique=True)
    op.create_table(
        'oarepo_references_version',
        sa.Column('created',
                  sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
                  autoincrement=False,
                  nullable=True),
        sa.Column('updated',
                  sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
                  autoincrement=False,
                  nullable=True),
        sa.Column('id',
                  sqlalchemy_utils.types.uuid.UUIDType(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('record_id',
                  sa.Integer(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('reference',
                  sa.String(length=255),
                  autoincrement=False,
                  nullable=True),
        sa.Column('reference_uuid',
                  sqlalchemy_utils.types.uuid.UUIDType(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('inline',
                  sa.Boolean(name='ck_oarepo_references_inline'),
                  autoincrement=False,
                  nullable=True),
        sa.Column('version_id',
                  sa.Integer(),
                  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',
                                name=op.f('pk_oarepo_references_version')))
    op.create_index(op.f('ix_oarepo_references_version_end_transaction_id'),
                    'oarepo_references_version', ['end_transaction_id'],
                    unique=False)
    op.create_index(op.f('ix_oarepo_references_version_operation_type'),
                    'oarepo_references_version', ['operation_type'],
                    unique=False)
    op.create_index(op.f('ix_oarepo_references_version_reference'),
                    'oarepo_references_version', ['reference'],
                    unique=False)
    op.create_index(op.f('ix_oarepo_references_version_reference_uuid'),
                    'oarepo_references_version', ['reference_uuid'],
                    unique=False)
    op.create_index(op.f('ix_oarepo_references_version_transaction_id'),
                    'oarepo_references_version', ['transaction_id'],
                    unique=False)
    op.create_table(
        'oarepo_references_referencing_record',
        sa.Column('created',
                  sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
                  nullable=False),
        sa.Column('updated',
                  sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
                  nullable=False), sa.Column('id',
                                             sa.Integer(),
                                             nullable=False),
        sa.Column('record_uuid',
                  sqlalchemy_utils.types.uuid.UUIDType(),
                  nullable=True),
        sa.Column('class_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['class_id'],
                                ['oarepo_references_classname.id'],
                                name='fk_oarepo_references_class_id_classname',
                                ondelete='CASCADE'),
        sa.PrimaryKeyConstraint(
            'id', name=op.f('pk_oarepo_references_referencing_record')))
    op.create_index(
        op.f('ix_oarepo_references_referencing_record_record_uuid'),
        'oarepo_references_referencing_record', ['record_uuid'],
        unique=True)
    op.create_table(
        'oarepo_references',
        sa.Column('created',
                  sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
                  nullable=False),
        sa.Column('updated',
                  sa.DateTime().with_variant(mysql.DATETIME(fsp=6), 'mysql'),
                  nullable=False),
        sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(),
                  nullable=False),
        sa.Column('record_id', sa.Integer(), nullable=True),
        sa.Column('reference', sa.String(length=255), nullable=False),
        sa.Column('reference_uuid',
                  sqlalchemy_utils.types.uuid.UUIDType(),
                  nullable=True),
        sa.Column('inline',
                  sa.Boolean(name='ck_oarepo_references_inline'),
                  nullable=True),
        sa.Column('version_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['record_id'],
                                ['oarepo_references_referencing_record.id'],
                                name='fk_oarepo_references_record_id_record',
                                ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_oarepo_references')),
        sa.UniqueConstraint('record_id',
                            'reference',
                            name='uq_oarepo_references_record_id_reference'))
    op.create_index(op.f('ix_oarepo_references_reference'),
                    'oarepo_references', ['reference'],
                    unique=False)
    op.create_index(op.f('ix_oarepo_references_reference_uuid'),
                    'oarepo_references', ['reference_uuid'],
                    unique=False)
예제 #4
0
def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    # create all tables
    # Take care on create order for those with FK dependencies
    tables = define_tables(meta)

    for table in tables:
        table.create()

    if migrate_engine.name == "mysql":
        tables = [
            "consistencygroups", "cgsnapshots", "snapshots",
            "snapshot_metadata", "quality_of_service_specs", "volume_types",
            "volume_type_projects", "volumes", "volume_attachment",
            "migrate_version", "quotas", "services", "volume_metadata",
            "volume_type_extra_specs", "quota_classes", "quota_usages",
            "reservations", "volume_glance_metadata", "backups", "transfers",
            "encryption", "volume_admin_metadata", "driver_initiator_data",
            "image_volume_cache_entries"
        ]

        migrate_engine.execute("SET foreign_key_checks = 0")
        for table in tables:
            migrate_engine.execute(
                "ALTER TABLE %s CONVERT TO CHARACTER SET utf8" % table)
        migrate_engine.execute("SET foreign_key_checks = 1")
        migrate_engine.execute("ALTER DATABASE %s DEFAULT CHARACTER SET utf8" %
                               migrate_engine.url.database)
        migrate_engine.execute("ALTER TABLE %s Engine=InnoDB" % table)

    # Set default quota class values
    quota_classes = Table('quota_classes', meta, autoload=True)
    qci = quota_classes.insert()
    qci.execute({
        'created_at': CREATED_AT,
        'class_name': CLASS_NAME,
        'resource': 'volumes',
        'hard_limit': CONF.quota_volumes,
        'deleted': False,
    })
    # Set default snapshots
    qci.execute({
        'created_at': CREATED_AT,
        'class_name': CLASS_NAME,
        'resource': 'snapshots',
        'hard_limit': CONF.quota_snapshots,
        'deleted': False,
    })
    # Set default gigabytes
    qci.execute({
        'created_at': CREATED_AT,
        'class_name': CLASS_NAME,
        'resource': 'gigabytes',
        'hard_limit': CONF.quota_gigabytes,
        'deleted': False,
    })
    qci.execute({
        'created_at': CREATED_AT,
        'class_name': CLASS_NAME,
        'resource': 'consistencygroups',
        'hard_limit': CONF.quota_consistencygroups,
        'deleted': False,
    })
    qci.execute({
        'created_at': CREATED_AT,
        'class_name': CLASS_NAME,
        'resource': 'per_volume_gigabytes',
        'hard_limit': -1,
        'deleted': False,
    })
    qci.execute({
        'created_at': CREATED_AT,
        'class_name': CLASS_NAME,
        'resource': 'groups',
        'hard_limit': CONF.quota_groups,
        'deleted': False,
    })

    workers = Table('workers', meta, autoload=True)

    # This is only necessary for mysql, and since the table is not in use this
    # will only be a schema update.
    if migrate_engine.name.startswith('mysql'):
        try:
            workers.c.updated_at.alter(mysql.DATETIME(fsp=6))
        except Exception:
            # MySQL v5.5 or earlier don't support sub-second resolution so we
            # may have cleanup races in Active-Active configurations, that's
            # why upgrading is recommended in that case.
            # Code in Cinder is capable of working with 5.5, so for 5.5 there's
            # no problem
            pass

    # TODO(geguileo): Once we remove support for MySQL 5.5 we have to create
    # an upgrade migration to remove this row.
    # Set workers table sub-second support sentinel
    wi = workers.insert()
    now = timeutils.utcnow().replace(microsecond=123)
    wi.execute({
        'created_at': now,
        'updated_at': now,
        'deleted': False,
        'resource_type': 'SENTINEL',
        'resource_id': 'SUB-SECOND',
        'status': 'OK'
    })

    # Create default group type
    group_types = Table('group_types', meta, autoload=True)
    group_type_specs = Table('group_type_specs', meta, autoload=True)

    now = timeutils.utcnow()
    grp_type_id = "%s" % uuid.uuid4()
    group_type_dicts = {
        'id': grp_type_id,
        'name': volume_group_types.DEFAULT_CGSNAPSHOT_TYPE,
        'description': 'Default group type for migrating cgsnapshot',
        'created_at': now,
        'updated_at': now,
        'deleted': False,
        'is_public': True,
    }
    grp_type = group_types.insert()
    grp_type.execute(group_type_dicts)

    group_spec_dicts = {
        'key': 'consistent_group_snapshot_enabled',
        'value': '<is> True',
        'group_type_id': grp_type_id,
        'created_at': now,
        'updated_at': now,
        'deleted': False,
    }
    grp_spec = group_type_specs.insert()
    grp_spec.execute(group_spec_dicts)
예제 #5
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('openned',
                  sa.Column('modified_time', mysql.DATETIME(), nullable=True))
예제 #6
0
class ResultOutputValue(db.Table):
    id_t = _ResultOutputValueId
    __tablename__ = "result_output_values"

    # Store up to this many characters of output text.
    max_len = 128000

    # Columns.
    id: int = sql.Column(id_t, primary_key=True)
    date_added: datetime.datetime = sql.Column(
        sql.DateTime().with_variant(mysql.DATETIME(fsp=3), "mysql"),
        nullable=False,
        default=labdate.GetUtcMillisecondsNow,
    )
    original_md5: bytes = sql.Column(
        sql.Binary(16).with_variant(mysql.BINARY(16), "mysql"),
        nullable=False,
        index=True,
        unique=True,
    )
    original_linecount = sql.Column(sql.Integer, nullable=False)
    original_charcount = sql.Column(sql.Integer, nullable=False)
    truncated_value: str = sql.Column(
        sql.UnicodeText().with_variant(sql.UnicodeText(max_len), "mysql"),
        nullable=False,
    )
    truncated: bool = sql.Column(sql.Boolean, nullable=False)
    truncated_md5: bytes = sql.Column(sql.Binary(16).with_variant(
        mysql.BINARY(16), "mysql"),
                                      nullable=False)
    truncated_linecount = sql.Column(sql.Integer, nullable=False)
    truncated_charcount = sql.Column(sql.Integer, nullable=False)

    # Relationships.
    outputs: typing.List[ResultOutput] = orm.relationship(
        ResultOutput, back_populates="value")

    @classmethod
    def GetOrAdd(cls, session: db.session_t,
                 string: str) -> "ResultOutputValue":
        """Instantiate a ResultOutputValue entry from a string.

    Args:
      session: A database session.
      string: The string.

    Returns:
      A ResultOutputValue instance.
    """
        original_charcount = len(string)
        original_linecount = string.count("\n")
        md5_ = hashlib.md5()
        md5_.update(string.encode("utf-8"))
        original_md5 = md5_.digest()
        # Truncate the text, if required. Note that we use the MD5 of the text
        # *after* truncation.
        if original_charcount > cls.max_len:
            truncated = string[:cls.max_len]
            md5_ = hashlib.md5()
            md5_.update(truncated.encode("utf-8"))
            truncated_md5 = md5_.digest()
            truncated_linecount = truncated.count("\n")
            truncated_charcount = cls.max_len
        else:
            truncated = string
            truncated_md5 = original_md5
            truncated_linecount = original_linecount
            truncated_charcount = original_charcount
        return labm8.py.sqlutil.GetOrAdd(
            session,
            cls,
            original_md5=original_md5,
            original_linecount=original_linecount,
            original_charcount=original_charcount,
            truncated=True if original_charcount > cls.max_len else False,
            truncated_value=truncated,
            truncated_md5=truncated_md5,
            truncated_linecount=truncated_linecount,
            truncated_charcount=truncated_charcount,
        )

    def __repr__(self):
        return self.truncated_value[:50] or ""
예제 #7
0
def downgrade_account():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('fitter_usage_entry',
                    sa.Column('service',
                              mysql.VARCHAR(length=100),
                              nullable=False),
                    sa.Column('unit', mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('volume',
                              mysql.DECIMAL(precision=20, scale=2),
                              nullable=False),
                    sa.Column('resource_id',
                              mysql.VARCHAR(length=100),
                              nullable=False),
                    sa.Column('tenant_id',
                              mysql.VARCHAR(length=100),
                              nullable=False),
                    sa.Column('start', mysql.DATETIME(), nullable=False),
                    sa.Column('end', mysql.DATETIME(), nullable=False),
                    sa.Column('created', mysql.DATETIME(), nullable=False),
                    sa.ForeignKeyConstraint(
                        ['resource_id', 'tenant_id'],
                        ['fitter_resources.id', 'fitter_resources.tenant_id'],
                        name='fk_resource_constraint'),
                    sa.PrimaryKeyConstraint('service', 'resource_id',
                                            'tenant_id', 'start', 'end'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_table('fitter_sales_orders',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('tenant_id',
                              mysql.VARCHAR(length=100),
                              nullable=False),
                    sa.Column('start', mysql.DATETIME(), nullable=False),
                    sa.Column('end', mysql.DATETIME(), nullable=False),
                    sa.ForeignKeyConstraint(['tenant_id'],
                                            ['fitter_tenants.id'],
                                            name='fitter_sales_orders_ibfk_1'),
                    sa.PrimaryKeyConstraint('id', 'tenant_id', 'start', 'end'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_table('fitter_resources',
                    sa.Column('id', mysql.VARCHAR(length=100), nullable=False),
                    sa.Column('tenant_id',
                              mysql.VARCHAR(length=100),
                              nullable=False),
                    sa.Column('info', mysql.TEXT(), nullable=True),
                    sa.Column('created', mysql.DATETIME(), nullable=False),
                    sa.ForeignKeyConstraint(['tenant_id'],
                                            ['fitter_tenants.id'],
                                            name='fitter_resources_ibfk_1'),
                    sa.PrimaryKeyConstraint('id', 'tenant_id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_table('fitter_tenants',
                    sa.Column('id', mysql.VARCHAR(length=100), nullable=False),
                    sa.Column('name', mysql.TEXT(), nullable=False),
                    sa.Column('info', mysql.TEXT(), nullable=True),
                    sa.Column('created', mysql.DATETIME(), nullable=False),
                    sa.Column('last_collected',
                              mysql.DATETIME(),
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_table('fitter_last_run',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('last_run', mysql.DATETIME(), nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.drop_index(op.f('ix_service_usage_time_label'),
                  table_name='service_usage')
    op.drop_table('service_usage')
    op.drop_table('sales_order')
    op.drop_table('tenant')
예제 #8
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('Coupon',
                  sa.Column('COvalidEndTime', mysql.DATETIME(), nullable=True))
    op.drop_column('Coupon', 'COvalidEndTime')
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('vital_statistics', 'record_mode')
    op.add_column('history', sa.Column('timestamp', mysql.DATETIME(), nullable=False))
    op.add_column('history', sa.Column('record_mode', mysql.VARCHAR(length=25), nullable=True))
    op.drop_column('history', 'date')
예제 #10
0
def downgrade():
    op.alter_column('worksheet', 'date_created', existing_type=mysql.DATETIME(), nullable=False)
예제 #11
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'alarm',
        sa.Column('ServerOffline',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('DomainName', mysql.VARCHAR(length=1024), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('MonitoredPoint', mysql.VARCHAR(length=1024), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AdvancedEvaluationState',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('Hidden',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('Priority',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('Silence',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('SystemEventId',
                  mysql.BIGINT(display_width=20),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('SystemAlarmId',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AudibleAlert',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AlarmState',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('Count',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm', sa.Column('AcknowledgeTime', mysql.DATETIME(), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AlarmText', mysql.VARCHAR(length=1024), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AcknowledgedBy', mysql.VARCHAR(length=80), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('SeqNo',
                  mysql.BIGINT(display_width=20),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('HasAttachment',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('UniqueAlarmId', mysql.VARCHAR(length=50), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('MonitoredValue', mysql.VARCHAR(length=50), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('Logging',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm', sa.Column('Command', mysql.VARCHAR(length=128),
                           nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AssignedTo', mysql.VARCHAR(length=80), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AssignState',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column('alarm',
                  sa.Column('DateTimeStamp', mysql.DATETIME(), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('FlashingAlert',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('BasicEvaluationState',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('PendingState',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('TriggeredTimestamp', mysql.DATETIME(), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('CheckedSteps', mysql.VARCHAR(length=512), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('PendingCommand',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm', sa.Column('Category',
                           mysql.VARCHAR(length=128),
                           nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AlarmStateSeqNo',
                  mysql.BIGINT(display_width=20),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('Module',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('AlarmType', mysql.VARCHAR(length=1024), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('OriginatedGUID', mysql.VARCHAR(length=50), nullable=True))
    op.add_column(
        'alarm',
        sa.Column('PreviousAlarmState',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'alarm',
        sa.Column('DisabledBy',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True))
def downgrade():
  """Downgrade database schema and/or data back to the previous revision."""
  op.alter_column('vendors', 'start_date', type_=mysql.DATETIME(),
                  existing_type=mysql.DATE(), nullable=True)
  op.alter_column('vendors', 'end_date', type_=mysql.DATETIME(),
                  existing_type=mysql.DATE(), nullable=True)
def upgrade():
  """Upgrade database schema and/or data, creating a new revision."""
  op.alter_column('vendors', 'start_date', type_=mysql.DATE(),
                  existing_type=mysql.DATETIME(), nullable=True)
  op.alter_column('vendors', 'end_date', type_=mysql.DATE(),
                  existing_type=mysql.DATETIME(), nullable=True)
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('item_price', sa.Column('update_at', mysql.DATETIME(), server_default=sa.text(u'CURRENT_TIMESTAMP'), nullable=True))
    op.drop_column('item_price', 'updated_at')
예제 #15
0
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(u'physical_memory',
                    'is_speed_in_mhz',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.add_column(u'Switch',
                  sa.Column('cpu', mysql.VARCHAR(length=100), nullable=True))
    op.add_column(
        u'Switch', sa.Column('memory',
                             mysql.VARCHAR(length=100),
                             nullable=True))
    op.add_column(
        u'Switch',
        sa.Column('serialNum', mysql.VARCHAR(length=100), nullable=True))
    op.add_column(u'Switch',
                  sa.Column('osVer', mysql.VARCHAR(length=100), nullable=True))
    op.add_column(u'Switch',
                  sa.Column('mac', mysql.VARCHAR(length=100), nullable=True))
    op.add_column(
        u'Switch',
        sa.Column('account_verified',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        u'Switch',
        sa.Column('hostname', mysql.VARCHAR(length=100), nullable=True))
    op.add_column(
        u'Switch', sa.Column('last_visit_date',
                             mysql.DATETIME(),
                             nullable=True))
    op.add_column(
        u'Switch', sa.Column('status',
                             mysql.VARCHAR(length=100),
                             nullable=True))
    op.drop_constraint(None, 'Switch', type_='unique')
    op.alter_column(u'Switch',
                    'ip',
                    existing_type=sa.String(length=20),
                    type_=mysql.VARCHAR(length=100),
                    existing_nullable=True)
    op.drop_column(u'Switch', 'os_era')
    op.drop_column(u'Switch', 'last_updated_date')
    op.drop_column(u'Switch', 'hardware_type')
    op.drop_column(u'Switch', 'error_message')
    op.drop_column(u'Switch', 'content_source')
    op.alter_column(u'RaidStorageVolume',
                    'PrimaryPartition',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column(u'RaidStorageVolume',
                    'Bootable',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column(u'RaidStoragePool',
                    'Primordial',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column(u'RAS_template',
                    'editable',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column(u'IMM',
                    'substribe_imm',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column(u'IMM',
                    'enable_power_poll',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column(u'IMM',
                    'cim_https_enabled',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column(u'IMM',
                    'cim_http_enabled',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column(u'IMM',
                    'account_verified',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.drop_table('SwitchData')
    op.drop_table('SwitchOID')
    op.drop_table('UpgradeStatus')
class MorphemeLanguageModel(LanguageModel, Base):
    """The OLD currently uses the MITLM toolkit to build its language models.
    Support for CMU-Cambridge, SRILM, KenLM, etc. may be forthcoming...
    """
    # pylint: disable=too-many-branches,too-many-locals,too-many-nested-blocks

    __tablename__ = 'morphemelanguagemodel'

    def __repr__(self):
        return '<MorphemeLanguageModel (%s)>' % self.id

    id = Column(Integer,
                Sequence('morphemelanguagemodel_seq_id', optional=True),
                primary_key=True)
    UUID = Column(Unicode(36))
    name = Column(Unicode(255))
    description = Column(UnicodeText)
    corpus_id = Column(Integer, ForeignKey('corpus.id', ondelete='SET NULL'))
    corpus = relation(
        'Corpus')  # whence we extract the morpheme sequences and their counts
    enterer_id = Column(Integer, ForeignKey('user.id', ondelete='SET NULL'))
    enterer = relation('User',
                       primaryjoin='MorphemeLanguageModel.enterer_id==User.id')
    modifier_id = Column(Integer, ForeignKey('user.id', ondelete='SET NULL'))
    modifier = relation(
        'User', primaryjoin='MorphemeLanguageModel.modifier_id==User.id')
    datetime_entered = Column(mysql.DATETIME(fsp=6))
    datetime_modified = Column(mysql.DATETIME(fsp=6), default=now)
    generate_succeeded = Column(Boolean, default=False)
    generate_message = Column(Unicode(255))
    generate_attempt = Column(Unicode(36))  # a UUID
    perplexity = Column(Float, default=0.0)
    perplexity_attempt = Column(Unicode(36))  # a UUID
    perplexity_computed = Column(Boolean, default=False)
    toolkit = Column(Unicode(10))
    order = Column(Integer)
    smoothing = Column(Unicode(30))
    vocabulary_morphology_id = Column(
        Integer, ForeignKey('morphology.id', ondelete='SET NULL'))
    # if specified, LM will use the lexicon of the morphology as the fixed
    # vocabulary
    vocabulary_morphology = relation('Morphology')
    restricted = Column(Boolean, default=False)
    # if True, the model will be built over sequences of categories, not
    # morphemes
    categorial = Column(Boolean, default=False)
    morpheme_delimiters = Column(Unicode(255))

    # These incidental attributes are initialized by the constructor.
    parent_directory = Column(Unicode(255))
    rare_delimiter = Column(Unicode(10))
    start_symbol = Column(Unicode(10))
    end_symbol = Column(Unicode(10))

    def get_dict(self):
        return {
            'id':
            self.id,
            'UUID':
            self.UUID,
            'name':
            self.name,
            'corpus':
            self.get_mini_dict_for(self.corpus),
            'description':
            self.description,
            'enterer':
            self.get_mini_user_dict(self.enterer),
            'modifier':
            self.get_mini_user_dict(self.modifier),
            'datetime_entered':
            self.datetime_entered,
            'datetime_modified':
            self.datetime_modified,
            'generate_succeeded':
            self.generate_succeeded,
            'generate_message':
            self.generate_message,
            'generate_attempt':
            self.generate_attempt,
            'perplexity':
            self.perplexity,
            'perplexity_attempt':
            self.perplexity_attempt,
            'perplexity_computed':
            self.perplexity_computed,
            'toolkit':
            self.toolkit,
            'order':
            self.order,
            'smoothing':
            self.smoothing,
            'vocabulary_morphology':
            self.get_mini_dict_for(self.vocabulary_morphology),
            'restricted':
            self.restricted,
            'categorial':
            self.categorial,
            'rare_delimiter':
            self.rare_delimiter
        }

    def write_corpus(self):
        """Write a word corpus text file using the LM's corpus where each line
        is a word.

        If the LM is categorial, the word is represented as a space-delimited
        list of category names corresponding to the categories of the morphemes
        of the word; otherwise, it is represented as a space-delimited list of
        morphemes in form|gloss|category format.

        :returns: the path to the LM corpus file just written.
        :side effects: if the LM's corpus contains restricted forms, set the
            ``restricted`` attribute to ``True``.  This will prevent restricted
            users from accessing the source files.
        """
        corpus_path = self.get_file_path('corpus')
        corpus = self.corpus
        forms = corpus.forms
        restricted = False
        with codecs.open(corpus_path, mode='w', encoding='utf8') as f:
            if corpus.form_search:
                for form in forms:
                    if form.syntactic_category_string:
                        if not restricted and "restricted" in [
                                t.name for t in form.tags
                        ]:
                            restricted = True
                        if self.categorial:
                            for category_word in (
                                    form.syntactic_category_string.split()):
                                f.write(
                                    self._get_categorial_corpus_entry(
                                        category_word))
                        else:
                            for morpheme_word, gloss_word, category_word in zip(
                                    form.morpheme_break.split(),
                                    form.morpheme_gloss.split(),
                                    form.syntactic_category_string.split()):
                                f.write(
                                    self._get_morphemic_corpus_entry(
                                        morpheme_word, gloss_word,
                                        category_word))
            else:
                form_references = corpus.get_form_references(corpus.content)
                forms = dict((f.id, f) for f in forms)
                for id_ in form_references:
                    form = forms[id_]
                    if form.syntactic_category_string:
                        if not restricted and "restricted" in [
                                t.name for t in form.tags
                        ]:
                            restricted = True
                        if self.categorial:
                            for category_word in form.syntactic_category_string.split(
                            ):
                                f.write(
                                    self._get_categorial_corpus_entry(
                                        category_word))
                        else:
                            for morpheme_word, gloss_word, category_word in zip(
                                    form.morpheme_break.split(),
                                    form.morpheme_gloss.split(),
                                    form.syntactic_category_string.split()):
                                f.write(
                                    self._get_morphemic_corpus_entry(
                                        morpheme_word, gloss_word,
                                        category_word))
        if restricted:
            self.restricted = True
        return corpus_path

    def write_vocabulary(self):
        """Write the vocabulary file, if appropriate.

        If the LM has a vocabulary morphology, use its lexicon to write a
        vocabulary file and return the path.  The format of the vocabulary file
        written is the same as the output of MITLM's ``estimate-ngram -t corpus
        -write-vocab vocab``, i.e., one word/morpheme per line.

        :returns: the path to the newly written vocabulary file or ``None`` if
            it could not be written.
        """

        vocabulary_morphology = self.vocabulary_morphology
        if not vocabulary_morphology:
            return None
        vocabulary_path = self.get_file_path('vocabulary')
        lexicon_path = vocabulary_morphology.get_file_path('lexicon')
        if not os.path.isfile(lexicon_path):
            return None
        # A pickled morphology lexicon is a dict with categories as keys and lists of
        # (morpheme_form, morpheme_gloss) 2-tuples as values.
        lexicon = pickle.load(open(lexicon_path, 'rb'))
        with codecs.open(vocabulary_path, mode='w', encoding='utf8') as f:
            f.write(u'%s\n' %
                    self.start_symbol)  # write <s> as a vocabulary item
            if self.categorial:
                for category in lexicon:
                    f.write(u'%s\n' % category)
            else:
                for category, morpheme_list in lexicon.items():
                    for morpheme_form, morpheme_gloss in morpheme_list:
                        f.write(u'%s\n' % self.rare_delimiter.join(
                            [morpheme_form, morpheme_gloss, category]))
            f.write(u'\n')
        return vocabulary_path

    def compute_perplexity(self, timeout, iterations):
        """Compute the perplexity of a the language model.

        The method used is to create ``iterations`` training/test set pairs, compute the perplexity
        of each test set based on an LM generated from its training set and return the average
        perplexity value.

        """

        perplexities = []
        temp_paths = [
        ]  # will hold the paths to all the temporary files that we delete below.
        if self.toolkit == 'mitlm':
            for index in range(1, iterations + 1):
                training_set_path, test_set_path, training_set_lm_path = (
                    self.write_training_test_sets(index))
                temp_paths += [
                    training_set_path, test_set_path, training_set_lm_path
                ]
                order = str(self.order)
                smoothing = self.smoothing or 'ModKN'
                cmd = [
                    self.executable, '-o', order, '-s', smoothing, '-t',
                    training_set_path, '-wl', training_set_lm_path,
                    '-eval-perp', test_set_path
                ]
                if self.vocabulary_morphology:
                    vocabulary_path = self.get_file_path('vocabulary')
                    if not os.path.isfile(vocabulary_path):
                        return None
                    cmd += ['-v', vocabulary_path]
                try:
                    returncode, output = self.run(cmd, timeout)
                    if returncode == 0 and os.path.isfile(
                            training_set_lm_path):
                        perplexities.append(self.extract_perplexity(output))
                except Exception:
                    pass
        else:
            return None
        for path in temp_paths:
            try:
                os.remove(path)
            except Exception:
                pass
        perplexities = list(filter(None, perplexities))
        if perplexities:
            return sum(perplexities) / len(perplexities)
        return None

    @staticmethod
    def extract_perplexity(output):
        """Extract the perplexity value from the output of MITLM."""
        try:
            last_line = output.splitlines()[-1]
            return float(last_line.split()[-1])
        except Exception:
            return None

    def _get_morphemic_corpus_entry(self, morpheme_word, gloss_word,
                                    category_word):
        """Return a string of morphemes, space-delimited in m|g|c format where
        "|" is ``self.rare_delimiter``.
        """
        # pylint: disable=not-callable
        return '%s\n' % u' '.join(
            self.rare_delimiter.join([morpheme, gloss, category])
            for morpheme, gloss, category in zip(
                self.morpheme_only_splitter(morpheme_word),
                self.morpheme_only_splitter(gloss_word),
                self.morpheme_only_splitter(category_word)))

    def _get_categorial_corpus_entry(self, category_word):
        """Return a string of morpheme category names, space-delimited.
        """
        # pylint: disable=not-callable
        return u'%s\n' % u' '.join(self.morpheme_only_splitter(category_word))

    def write_training_test_sets(self, index):
        """Divide the words implicit in the LM's corpus into randomly sampled
        training and test sets and write them to disk with the suffix ``i``.
        Use the toolkit of the morpheme language model to generate an
        ARPA-formatted LM for the training set.

        :param instance morpheme_language_model: a LM model object.
        :param str morpheme_language_model_path: absolute path to the LM's
            directory.
        :param int i: index used in naming the test and training sets.
        :returns: a triple of strings: the absolute paths to the training and
            test sets and the path to the training set's ARPA-formatted LM.
        """
        directory = self.directory
        test_set_path = '%s_test_%s.txt' % (directory, index)
        training_set_path = '%s_training_%s.txt' % (directory, index)
        training_set_lm_path = '%s_training_%s.lm' % (directory, index)
        corpus = self.corpus
        forms = corpus.forms
        population = range(1, 11)
        test_index = random.choice(population)
        with codecs.open(training_set_path, mode='w',
                         encoding='utf8') as f_training:
            with codecs.open(test_set_path, mode='w',
                             encoding='utf8') as f_test:
                if corpus.form_search:
                    for form in forms:
                        if form.syntactic_category_string:
                            if self.categorial:
                                for category_word in form.syntactic_category_string.split(
                                ):
                                    r = random.choice(population)
                                    if r == test_index:
                                        f_test.write(
                                            self._get_categorial_corpus_entry(
                                                category_word))
                                    else:
                                        f_training.write(
                                            self._get_categorial_corpus_entry(
                                                category_word))
                            else:
                                for mword, gword, cword in zip(
                                        form.morpheme_break.split(),
                                        form.morpheme_gloss.split(),
                                        form.syntactic_category_string.split()
                                ):
                                    r = random.choice(population)
                                    if r == test_index:
                                        f_test.write(
                                            self._get_morphemic_corpus_entry(
                                                mword, gword, cword))
                                    else:
                                        f_training.write(
                                            self._get_morphemic_corpus_entry(
                                                mword, gword, cword))
                else:
                    form_references = corpus.get_form_references(
                        corpus.content)
                    forms = dict((f.id, f) for f in forms)
                    for id_ in form_references:
                        form = forms[id_]
                        if form.syntactic_category_string:
                            if self.categorial:
                                for cword in (form.syntactic_category_string.
                                              split()):
                                    r = random.choice(population)
                                    if r == test_index:
                                        f_test.write(
                                            self._get_categorial_corpus_entry(
                                                cword))
                                    else:
                                        f_training.write(
                                            self._get_categorial_corpus_entry(
                                                cword))
                            else:
                                for mword, gword, cword in zip(
                                        form.morpheme_break.split(),
                                        form.morpheme_gloss.split(),
                                        form.syntactic_category_string.split()
                                ):
                                    r = random.choice(population)
                                    if r == test_index:
                                        f_test.write(
                                            self._get_morphemic_corpus_entry(
                                                mword, gword, cword))
                                    else:
                                        f_training.write(
                                            self._get_morphemic_corpus_entry(
                                                mword, gword, cword))
        return training_set_path, test_set_path, training_set_lm_path
예제 #17
0
def downgrade():
    op.create_table('tag',
                    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('name',
                              mysql.VARCHAR(collation=u'utf8_unicode_ci',
                                            length=64),
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate=u'utf8_unicode_ci',
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('entry_tag',
                    sa.Column('entry_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('tag_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.ForeignKeyConstraint(['entry_id'], [u'entry.id'],
                                            name=u'entry_tag_ibfk_1'),
                    sa.ForeignKeyConstraint(['tag_id'], [u'tag.id'],
                                            name=u'entry_tag_ibfk_2'),
                    mysql_collate=u'utf8_unicode_ci',
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('entry',
                    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('account_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('title',
                              mysql.VARCHAR(collation=u'utf8_unicode_ci',
                                            length=128),
                              nullable=False),
                    sa.Column('link',
                              mysql.VARCHAR(collation=u'utf8_unicode_ci',
                                            length=256),
                              nullable=False),
                    sa.Column('description',
                              mysql.TEXT(collation=u'utf8_unicode_ci'),
                              nullable=False),
                    sa.Column('publish_time', mysql.DATETIME(),
                              nullable=False),
                    sa.Column('source_name',
                              mysql.VARCHAR(collation=u'utf8_unicode_ci',
                                            length=64),
                              nullable=False),
                    sa.Column('image_url',
                              mysql.VARCHAR(collation=u'utf8_unicode_ci',
                                            length=256),
                              nullable=False),
                    sa.Column('author',
                              mysql.VARCHAR(collation=u'utf8_unicode_ci',
                                            length=64),
                              nullable=False),
                    sa.Column('content',
                              mysql.TEXT(collation=u'utf8_unicode_ci'),
                              nullable=False),
                    sa.ForeignKeyConstraint(['account_id'], [u'account.id'],
                                            name=u'entry_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate=u'utf8_unicode_ci',
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
예제 #18
0
def upgrade():
    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='known_event',
                        column_name='start_date',
                        type_=mysql.DATETIME(fsp=6))
        op.alter_column(table_name='known_event',
                        column_name='end_date',
                        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))
예제 #19
0
class Result(db.Table):
    id_t = _ResultId
    __tablename__ = "results"

    # Columns.
    id: int = sql.Column(id_t, primary_key=True)
    date_added: datetime.datetime = sql.Column(
        sql.DateTime().with_variant(mysql.DATETIME(fsp=3), "mysql"),
        nullable=False,
        default=labdate.GetUtcMillisecondsNow,
    )
    testcase_id: int = sql.Column(
        deeplearning.deepsmith.testcase.Testcase.id_t,
        sql.ForeignKey("testcases.id"),
        nullable=False,
    )
    testbed_id: int = sql.Column(
        deeplearning.deepsmith.testbed.Testbed.id_t,
        sql.ForeignKey("testbeds.id"),
        nullable=False,
    )
    returncode: int = sql.Column(sql.SmallInteger, nullable=False)
    outputset_id: bytes = sql.Column(_ResultOutputSetId, nullable=False)
    outcome_num: int = sql.Column(sql.Integer, nullable=False)

    # Relationships.
    testcase: deeplearning.deepsmith.testcase.Testcase = orm.relationship(
        "Testcase", back_populates="results")
    testbed: deeplearning.deepsmith.testbed.Testbed = orm.relationship(
        "Testbed", back_populates="results")
    outputset: typing.List["ResultOutput"] = orm.relationship(
        "ResultOutput",
        secondary="result_outputsets",
        primaryjoin="ResultOutputSet.id == Result.outputset_id",
        secondaryjoin="ResultOutputSet.output_id == ResultOutput.id",
    )
    profiling_events: typing.List["ResultProfilingEvent"] = orm.relationship(
        "ResultProfilingEvent", back_populates="result")

    # Constraints.
    __table_args__ = (sql.UniqueConstraint("testcase_id",
                                           "testbed_id",
                                           name="unique_result"), )

    @property
    def outcome(self) -> deepsmith_pb2.Result.Outcome:
        """Get the symbolic outcome.

    Returns:
       An Outcome enum instance.
    """
        return deepsmith_pb2.Result.Outcome(self.outcome_num)

    @property
    def outputs(self) -> typing.Dict[str, str]:
        """Get the generator inputs.

    Returns:
      A map of result outputs.
    """
        return {
            output.name.string: output.value.truncated_value
            for output in self.outputset
        }

    def SetProto(self, proto: deepsmith_pb2.Result) -> deepsmith_pb2.Result:
        """Set a protocol buffer representation.

    Args:
      proto: A protocol buffer message.

    Returns:
      A Result message.
    """
        self.testcase.SetProto(proto.testcase)
        self.testbed.SetProto(proto.testbed)
        proto.returncode = self.returncode
        for output in self.outputset:
            proto.outputs[output.name.string] = output.value.truncated_value
        for event in self.profiling_events:
            event_proto = proto.profiling_events.add()
            event.SetProto(event_proto)
        proto.outcome = self.outcome_num
        return proto

    def ToProto(self) -> deepsmith_pb2.Result:
        """Create protocol buffer representation.

    Returns:
      A Result message.
    """
        proto = deepsmith_pb2.Result()
        return self.SetProto(proto)

    @classmethod
    def GetOrAdd(cls, session: db.session_t,
                 proto: deepsmith_pb2.Result) -> "Result":
        testcase = deeplearning.deepsmith.testcase.Testcase.GetOrAdd(
            session, proto.testcase)
        testbed = deeplearning.deepsmith.testbed.Testbed.GetOrAdd(
            session, proto.testbed)

        # Only add the result if the the <testcase, testbed> tuple is unique. This
        # is to prevent duplicate results where only the output differs.
        result = (session.query(Result).filter(
            Result.testcase == testcase, Result.testbed == testbed).first())
        if result:
            return result

        # Build the list of outputs, and md5sum the key value strings.
        outputs = []
        md5 = hashlib.md5()
        for proto_output_name in sorted(proto.outputs):
            proto_output_value = proto.outputs[proto_output_name]
            md5.update(
                (proto_output_name + proto_output_value).encode("utf-8"))
            output = labm8.py.sqlutil.GetOrAdd(
                session,
                ResultOutput,
                name=ResultOutputName.GetOrAdd(session,
                                               string=proto_output_name),
                value=ResultOutputValue.GetOrAdd(session,
                                                 string=proto_output_value),
            )
            outputs.append(output)

        # Create output set table entries.
        outputset_id = md5.digest()
        for output in outputs:
            labm8.py.sqlutil.GetOrAdd(session,
                                      ResultOutputSet,
                                      id=outputset_id,
                                      output=output)

        # Create a new result only if everything *except* the profiling events
        # are unique. This means that if a generator produced the same testcase
        # twice (on separate occasions), only the first is added to the datastore.
        result = labm8.py.sqlutil.Get(
            session,
            cls,
            testcase=testcase,
            testbed=testbed,
            returncode=proto.returncode,
            outputset_id=outputset_id,
            outcome_num=proto.outcome,
        )
        if not result:
            result = cls(
                testcase=testcase,
                testbed=testbed,
                returncode=proto.returncode,
                outputset_id=outputset_id,
                outcome_num=proto.outcome,
            )
            session.add(result)
            # Add profiling events.
            for event in proto.profiling_events:
                deeplearning.deepsmith.profiling_event.ResultProfilingEvent.GetOrAdd(
                    session, event, result)

        return result

    @classmethod
    def ProtoFromFile(cls, path: pathlib.Path) -> deepsmith_pb2.Result:
        """Instantiate a protocol buffer result from file.

    Args:
      path: Path to the result proto file.

    Returns:
      Result message instance.
    """
        return pbutil.FromFile(path, deepsmith_pb2.Result())

    @classmethod
    def FromFile(cls, session: db.session_t, path: pathlib.Path) -> "Result":
        """Instantiate a Result from a serialized protocol buffer on file.

    Args:
      session: A database session.
      path: Path to the result proto file.

    Returns:
      A Result instance.
    """
        return cls.GetOrAdd(session, cls.ProtoFromFile(path))
def downgrade():
    op.create_table('directive_sections',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('directive_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('section_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('program_directives',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('program_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('directive_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('section_objectives',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('section_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('objective_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('object_controls',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('start_date', sa.DATE(), nullable=True),
                    sa.Column('end_date', sa.DATE(), nullable=True),
                    sa.Column('role', mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.Column('notes', mysql.TEXT(), nullable=True),
                    sa.Column('control_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('controllable_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('controllable_type',
                              mysql.VARCHAR(length=250),
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('object_objectives',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('start_date', sa.DATE(), nullable=True),
                    sa.Column('end_date', sa.DATE(), nullable=True),
                    sa.Column('role', mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.Column('notes', mysql.TEXT(), nullable=True),
                    sa.Column('objective_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('objectiveable_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('objectiveable_type',
                              mysql.VARCHAR(length=250),
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('calendar_entries',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.Column('calendar_id',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('owner_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['context_id'], [u'contexts.id'],
                                            name=u'calendar_entries_ibfk_1'),
                    sa.ForeignKeyConstraint(['owner_id'], [u'people.id'],
                                            name=u'calendar_entries_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('control_controls',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('control_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('implemented_control_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('directive_controls',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('directive_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('control_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('program_controls',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('program_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('control_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('objective_controls',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('objective_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('control_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('control_sections',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('control_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('section_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('object_sections',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('modified_by_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
                    sa.Column('start_date', sa.DATE(), nullable=True),
                    sa.Column('end_date', sa.DATE(), nullable=True),
                    sa.Column('role', mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.Column('notes', mysql.TEXT(), nullable=True),
                    sa.Column('section_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('sectionable_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('sectionable_type',
                              mysql.VARCHAR(length=250),
                              nullable=False),
                    sa.Column('context_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=250),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
예제 #21
0
class File(Base):
    """There are 3 types of file:

    1. Standard files: their content is a file in /files/filename.  These files
       have a filename attribute.
    2. Subinterval-referring A/V files: these refer to another OLD file for
       their content.  These files have a parent_file attribute (as well as
       start and end attributes.)
    3. Externally hosted files: these refer to a file hosted on another server.
       They have a url attribute (and optionally a password attribute as well.)
    """

    __tablename__ = 'file'

    def __repr__(self):
        return "<File (%s)>" % self.id

    id = Column(Integer, Sequence('file_seq_id', optional=True), primary_key=True)
    # filename is the name of the file as written to disk
    filename = Column(Unicode(255), unique=True)
    # just a name; useful for subinterval-referencing files; need not be unique
    name = Column(Unicode(255))
    MIME_type = Column(Unicode(255))
    size = Column(Integer)
    description = Column(UnicodeText)
    date_elicited = Column(Date)
    datetime_entered = Column(mysql.DATETIME(fsp=6))
    datetime_modified = Column(mysql.DATETIME(fsp=6), default=now)
    enterer_id = Column(Integer, ForeignKey('user.id', ondelete='SET NULL'))
    enterer = relation('User', primaryjoin='File.enterer_id==User.id')
    elicitor_id = Column(Integer, ForeignKey('user.id', ondelete='SET NULL'))
    elicitor = relation('User', primaryjoin='File.elicitor_id==User.id')
    speaker_id = Column(Integer, ForeignKey('speaker.id', ondelete='SET NULL'))
    speaker = relation('Speaker')
    utterance_type = Column(Unicode(255))
    # pylint: disable=no-member
    tags = relation('Tag', secondary=FileTag.__table__, backref='files')

    # Attributes germane to externally hosted files.
    url = Column(Unicode(255))          # for external files
    password = Column(Unicode(255))     # for external files requiring authentication

    # Attributes germane to subinterval-referencing a/v files.
    parent_file_id = Column(Integer, ForeignKey('file.id', ondelete='SET NULL'))
    parent_file = relation('File', remote_side=[id])
    start = Column(Float)
    end = Column(Float)

    lossy_filename = Column(Unicode(255))        # .ogg generated from .wav or resized images

    def get_dict(self):
        """Return a Python dictionary representation of the File.  This
        facilitates JSON-stringification, cf. utils.JSONOLDEncoder.  Relational
        data are truncated.
        """
        return {
            'id': self.id,
            'date_elicited': self.date_elicited,
            'datetime_entered': self.datetime_entered,
            'datetime_modified': self.datetime_modified,
            'filename': self.filename,
            'name': self.name,
            'lossy_filename': self.lossy_filename,
            'MIME_type': self.MIME_type,
            'size': self.size,
            'description': self.description,
            'utterance_type': self.utterance_type,
            'url': self.url,
            'password': self.password,
            'enterer': self.get_mini_user_dict(self.enterer),
            'elicitor': self.get_mini_user_dict(self.elicitor),
            'speaker': self.get_mini_speaker_dict(self.speaker),
            'tags': self.get_tags_list(self.tags),
            'forms': self.get_forms_list(self.forms),
            'parent_file': self.get_mini_file_dict(self.parent_file),
            'start': self.start,
            'end': self.end
        }
예제 #22
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('board', sa.Column('creat_time', mysql.DATETIME(), nullable=True))
    op.drop_column('board', 'create_time')
예제 #23
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('items', sa.Column('expiration_period', mysql.DATETIME(), nullable=True))
예제 #24
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_index('username', 'user', ['username'], unique=True)
    op.create_index('phone', 'user', ['phone'], unique=True)
    op.alter_column('user',
                    'phone',
                    existing_type=mysql.CHAR(length=11),
                    nullable=False)
    op.drop_column('user', 'authority')
    op.create_table('django_content_type',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('app_label',
                              mysql.VARCHAR(length=100),
                              nullable=False),
                    sa.Column('model',
                              mysql.VARCHAR(length=100),
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index('django_content_type_app_label_model_76bd3d3b_uniq',
                    'django_content_type', ['app_label', 'model'],
                    unique=True)
    op.create_table('auth_user_user_permissions',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('permission_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index(
        'auth_user_user_permissions_user_id_permission_id_14a6b632_uniq',
        'auth_user_user_permissions', ['user_id', 'permission_id'],
        unique=True)
    op.create_index('auth_user_user_permissions_user_id_a95ead1b',
                    'auth_user_user_permissions', ['user_id'],
                    unique=False)
    op.create_index('auth_user_user_permissions_permission_id_1fbb5f2c',
                    'auth_user_user_permissions', ['permission_id'],
                    unique=False)
    op.create_table('django_admin_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('action_time',
                              mysql.DATETIME(fsp=6),
                              nullable=False),
                    sa.Column('object_id', mysql.LONGTEXT(), nullable=True),
                    sa.Column('object_repr',
                              mysql.VARCHAR(length=200),
                              nullable=False),
                    sa.Column('action_flag',
                              mysql.SMALLINT(display_width=5, unsigned=True),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('change_message',
                              mysql.LONGTEXT(),
                              nullable=False),
                    sa.Column('content_type_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index('django_admin_log_user_id_c564eba6',
                    'django_admin_log', ['user_id'],
                    unique=False)
    op.create_index('django_admin_log_content_type_id_c4bce8eb',
                    'django_admin_log', ['content_type_id'],
                    unique=False)
    op.create_table('auth_group',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=80),
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index('name', 'auth_group', ['name'], unique=True)
    op.create_table('django_migrations',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('app', mysql.VARCHAR(length=255),
                              nullable=False),
                    sa.Column('name',
                              mysql.VARCHAR(length=255),
                              nullable=False),
                    sa.Column('applied', mysql.DATETIME(fsp=6),
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_table('django_session',
                    sa.Column('session_key',
                              mysql.VARCHAR(length=40),
                              nullable=False),
                    sa.Column('session_data', mysql.LONGTEXT(),
                              nullable=False),
                    sa.Column('expire_date',
                              mysql.DATETIME(fsp=6),
                              nullable=False),
                    sa.PrimaryKeyConstraint('session_key'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index('django_session_expire_date_a5c62663',
                    'django_session', ['expire_date'],
                    unique=False)
    op.create_table('user_user',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('username',
                              mysql.VARCHAR(length=20),
                              nullable=False),
                    sa.Column('phone',
                              mysql.VARCHAR(length=11),
                              nullable=False),
                    sa.Column('password',
                              mysql.VARCHAR(length=32),
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_table('auth_user',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('password',
                              mysql.VARCHAR(length=128),
                              nullable=False),
                    sa.Column('last_login',
                              mysql.DATETIME(fsp=6),
                              nullable=True),
                    sa.Column('is_superuser',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('username',
                              mysql.VARCHAR(length=150),
                              nullable=False),
                    sa.Column('first_name',
                              mysql.VARCHAR(length=30),
                              nullable=False),
                    sa.Column('last_name',
                              mysql.VARCHAR(length=150),
                              nullable=False),
                    sa.Column('email',
                              mysql.VARCHAR(length=254),
                              nullable=False),
                    sa.Column('is_staff',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('is_active',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('date_joined',
                              mysql.DATETIME(fsp=6),
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index('username', 'auth_user', ['username'], unique=True)
    op.create_table('auth_user_groups',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('group_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index('auth_user_groups_user_id_group_id_94350c0c_uniq',
                    'auth_user_groups', ['user_id', 'group_id'],
                    unique=True)
    op.create_index('auth_user_groups_user_id_6a12ed8b',
                    'auth_user_groups', ['user_id'],
                    unique=False)
    op.create_index('auth_user_groups_group_id_97559544',
                    'auth_user_groups', ['group_id'],
                    unique=False)
    op.create_table('auth_permission',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('name',
                              mysql.VARCHAR(length=255),
                              nullable=False),
                    sa.Column('content_type_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('codename',
                              mysql.VARCHAR(length=100),
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index('auth_permission_content_type_id_codename_01ab375a_uniq',
                    'auth_permission', ['content_type_id', 'codename'],
                    unique=True)
    op.create_index('auth_permission_content_type_id_2f476e4b',
                    'auth_permission', ['content_type_id'],
                    unique=False)
    op.create_table('auth_group_permissions',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('group_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('permission_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='latin1',
                    mysql_engine='MyISAM')
    op.create_index('auth_group_permissions_permission_id_84c5c92e',
                    'auth_group_permissions', ['permission_id'],
                    unique=False)
    op.create_index(
        'auth_group_permissions_group_id_permission_id_0cd325b0_uniq',
        'auth_group_permissions', ['group_id', 'permission_id'],
        unique=True)
    op.create_index('auth_group_permissions_group_id_b120cbf9',
                    'auth_group_permissions', ['group_id'],
                    unique=False)
def downgrade():
    conn = op.get_bind()
    if conn.dialect.name == "mysql":
        conn.execute("SET time_zone = '+00:00'")
        op.alter_column(table_name="chart",
                        column_name="last_modified",
                        type_=mysql.DATETIME())

        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="DATETIME",
            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="DATETIME",
                        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="DATETIME",
                        type_=mysql.DATETIME())
        op.alter_column(table_name="xcom",
                        column_name="execution_date",
                        type_=mysql.DATETIME())
    else:
        if conn.dialect.name in ("sqlite", "mssql"):
            return

        # we try to be database agnostic, but not every db (e.g. sqlserver)
        # supports per session time zones
        if conn.dialect.name == "postgresql":
            conn.execute("set timezone=UTC")

        op.alter_column(table_name="chart",
                        column_name="last_modified",
                        type_=sa.DateTime())

        op.alter_column(table_name="dag",
                        column_name="last_scheduler_run",
                        type_=sa.DateTime())
        op.alter_column(table_name="dag",
                        column_name="last_pickled",
                        type_=sa.DateTime())
        op.alter_column(table_name="dag",
                        column_name="last_expired",
                        type_=sa.DateTime())

        op.alter_column(table_name="dag_pickle",
                        column_name="created_dttm",
                        type_=sa.DateTime())

        op.alter_column(table_name="dag_run",
                        column_name="execution_date",
                        type_=sa.DateTime())
        op.alter_column(table_name="dag_run",
                        column_name="start_date",
                        type_=sa.DateTime())
        op.alter_column(table_name="dag_run",
                        column_name="end_date",
                        type_=sa.DateTime())

        op.alter_column(table_name="import_error",
                        column_name="timestamp",
                        type_=sa.DateTime())

        op.alter_column(table_name="job",
                        column_name="start_date",
                        type_=sa.DateTime())
        op.alter_column(table_name="job",
                        column_name="end_date",
                        type_=sa.DateTime())
        op.alter_column(table_name="job",
                        column_name="latest_heartbeat",
                        type_=sa.DateTime())

        op.alter_column(table_name="log",
                        column_name="dttm",
                        type_=sa.DateTime())
        op.alter_column(table_name="log",
                        column_name="execution_date",
                        type_=sa.DateTime())

        op.alter_column(
            table_name="sla_miss",
            column_name="execution_date",
            type_=sa.DateTime(),
            nullable=False,
        )
        op.alter_column(table_name="sla_miss",
                        column_name="timestamp",
                        type_=sa.DateTime())

        op.alter_column(table_name="task_fail",
                        column_name="execution_date",
                        type_=sa.DateTime())
        op.alter_column(table_name="task_fail",
                        column_name="start_date",
                        type_=sa.DateTime())
        op.alter_column(table_name="task_fail",
                        column_name="end_date",
                        type_=sa.DateTime())

        op.alter_column(
            table_name="task_instance",
            column_name="execution_date",
            type_=sa.DateTime(),
            nullable=False,
        )
        op.alter_column(table_name="task_instance",
                        column_name="start_date",
                        type_=sa.DateTime())
        op.alter_column(table_name="task_instance",
                        column_name="end_date",
                        type_=sa.DateTime())
        op.alter_column(table_name="task_instance",
                        column_name="queued_dttm",
                        type_=sa.DateTime())

        op.alter_column(table_name="xcom",
                        column_name="timestamp",
                        type_=sa.DateTime())
        op.alter_column(table_name="xcom",
                        column_name="execution_date",
                        type_=sa.DateTime())
def upgrade():
    op.create_table('logs_idpe_connect',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('idutilisateur_peconnect',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('dateheure', mysql.DATETIME()),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8mb4_unicode_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')

    op.create_table('logs_activity',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('dateheure', mysql.DATETIME()),
                    sa.Column('nom',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('idutilisateur_peconnect',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('siret',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('utm_medium',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('utm_source',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('utm_campaign',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8mb4_unicode_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')

    op.create_table('logs_activity_recherche',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('dateheure', mysql.DATETIME()),
                    sa.Column('idutilisateur_peconnect',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('ville',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('code_postal',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('emploi',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8mb4_unicode_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')

    op.create_table('logs_activity_dpae_clean',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('idutilisateur_peconnect',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('siret',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('date_activite', mysql.DATETIME()),
                    sa.Column('date_embauche', mysql.DATETIME()),
                    sa.Column('type_contrat',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('duree_activite_cdd_mois', mysql.INTEGER()),
                    sa.Column('duree_activite_cdd_jours', mysql.INTEGER()),
                    sa.Column('diff_activite_embauche_jrs', mysql.INTEGER()),
                    sa.Column('dc_lblprioritede',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('tranche_age',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('dc_prive_public',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.Column('duree_prise_en_charge', mysql.INTEGER()),
                    sa.Column('dn_tailleetablissement', mysql.INTEGER()),
                    sa.Column('code_postal',
                              mysql.TEXT(collation='utf8mb4_unicode_ci')),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8mb4_unicode_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'collection_edit_log',
        sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column('created_at', mysql.DATETIME(), nullable=True),
        sa.Column('kind',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=False),
        sa.Column('before', mysql.VARCHAR(length=200), nullable=True),
        sa.Column('before_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('after', mysql.VARCHAR(length=200), nullable=True),
        sa.Column('after_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('compare', mysql.VARCHAR(length=500), nullable=True),
        sa.Column('user_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('collection_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.ForeignKeyConstraint(['collection_id'], [u'collection.id'],
                                name=u'collection_edit_log_ibfk_1'),
        sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                name=u'collection_edit_log_ibfk_2'),
        sa.PrimaryKeyConstraint('id'),
        mysql_default_charset=u'utf8',
        mysql_engine=u'InnoDB')
    op.create_table('collection_kind',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('name', mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('show_order',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('invitation_code',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('code', mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('email',
                              mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('used',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('sended_at', mysql.DATETIME(), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('sender_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['sender_id'], [u'user.id'],
                                            name=u'invitation_code_ibfk_2'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'invitation_code_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('collection_like',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('collection_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['collection_id'],
                                            [u'collection.id'],
                                            name=u'collection_like_ibfk_1'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'collection_like_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('piece_edit_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('piece_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('kind',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('after',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('after_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('before',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('before_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('compare',
                              mysql.VARCHAR(length=500),
                              nullable=True),
                    sa.ForeignKeyConstraint(['piece_id'], [u'piece.id'],
                                            name=u'piece_edit_log_ibfk_2'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'piece_edit_log_ibfk_3'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('piece_source',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('count',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('mail_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('email',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('message', mysql.TEXT(), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('search_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('keyword',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'search_log_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table(
        'collection_edit_log_report',
        sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column('created_at', mysql.DATETIME(), nullable=True),
        sa.Column('user_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('log_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('processed',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True),
        sa.ForeignKeyConstraint(['log_id'], [u'collection_edit_log.id'],
                                name=u'collection_edit_log_report_ibfk_3'),
        sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                name=u'collection_edit_log_report_ibfk_2'),
        sa.PrimaryKeyConstraint('id'),
        mysql_default_charset=u'utf8',
        mysql_engine=u'InnoDB')
    op.create_table(
        'piece_edit_log_report',
        sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column('created_at', mysql.DATETIME(), nullable=True),
        sa.Column('user_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('processed',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True),
        sa.Column('log_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.ForeignKeyConstraint(['log_id'], [u'piece_edit_log.id'],
                                name=u'piece_edit_log_report_ibfk_3'),
        sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                name=u'piece_edit_log_report_ibfk_2'),
        sa.PrimaryKeyConstraint('id'),
        mysql_default_charset=u'utf8',
        mysql_engine=u'InnoDB')
    op.create_table('sentence',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('content', mysql.TEXT(), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('piece_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['piece_id'], [u'piece.id'],
                                            name=u'sentence_ibfk_1'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'sentence_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('piece_author',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('count',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('collection',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('title',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('cover',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('desc', mysql.TEXT(), nullable=True),
                    sa.Column('kind_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('locked',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['kind_id'],
                                            [u'collection_kind.id'],
                                            name=u'collection_ibfk_1'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'collection_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('click_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('url', mysql.VARCHAR(length=100), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'click_log_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('collection_piece',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('collection_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('piece_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['collection_id'],
                                            [u'collection.id'],
                                            name=u'collection_piece_ibfk_1'),
                    sa.ForeignKeyConstraint(['piece_id'], [u'piece.id'],
                                            name=u'collection_piece_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
예제 #28
0
def downgrade():
    conn = op.get_bind()
    if conn.dialect.name == 'mysql':
        conn.execute("SET time_zone = '+00:00'")
        op.alter_column(table_name='chart',
                        column_name='last_modified',
                        type_=mysql.DATETIME())

        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='DATETIME',
                        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='known_event',
                        column_name='start_date',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='known_event',
                        column_name='end_date',
                        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='DATETIME',
                        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='DATETIME',
                        type_=mysql.DATETIME())
        op.alter_column(table_name='xcom',
                        column_name='execution_date',
                        type_=mysql.DATETIME())
    else:
        if conn.dialect.name in ('sqlite', 'mssql'):
            return

        # we try to be database agnostic, but not every db (e.g. sqlserver)
        # supports per session time zones
        #if conn.dialect.name == 'postgresql':
        #    conn.execute("set timezone=UTC")

        op.alter_column(table_name='chart',
                        column_name='last_modified',
                        type_=sa.DateTime())

        op.alter_column(table_name='dag',
                        column_name='last_scheduler_run',
                        type_=sa.DateTime())
        op.alter_column(table_name='dag',
                        column_name='last_pickled',
                        type_=sa.DateTime())
        op.alter_column(table_name='dag',
                        column_name='last_expired',
                        type_=sa.DateTime())

        op.alter_column(table_name='dag_pickle',
                        column_name='created_dttm',
                        type_=sa.DateTime())

        op.alter_column(table_name='dag_run',
                        column_name='execution_date',
                        type_=sa.DateTime())
        op.alter_column(table_name='dag_run',
                        column_name='start_date',
                        type_=sa.DateTime())
        op.alter_column(table_name='dag_run',
                        column_name='end_date',
                        type_=sa.DateTime())

        op.alter_column(table_name='import_error',
                        column_name='timestamp',
                        type_=sa.DateTime())

        op.alter_column(table_name='job',
                        column_name='start_date',
                        type_=sa.DateTime())
        op.alter_column(table_name='job',
                        column_name='end_date',
                        type_=sa.DateTime())
        op.alter_column(table_name='job',
                        column_name='latest_heartbeat',
                        type_=sa.DateTime())

        op.alter_column(table_name='known_event',
                        column_name='start_date',
                        type_=sa.DateTime())
        op.alter_column(table_name='known_event',
                        column_name='end_date',
                        type_=sa.DateTime())

        op.alter_column(table_name='log',
                        column_name='dttm',
                        type_=sa.DateTime())
        op.alter_column(table_name='log',
                        column_name='execution_date',
                        type_=sa.DateTime())

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

        op.alter_column(table_name='task_fail',
                        column_name='execution_date',
                        type_=sa.DateTime())
        op.alter_column(table_name='task_fail',
                        column_name='start_date',
                        type_=sa.DateTime())
        op.alter_column(table_name='task_fail',
                        column_name='end_date',
                        type_=sa.DateTime())

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

        op.alter_column(table_name='xcom',
                        column_name='timestamp',
                        type_=sa.DateTime())
        op.alter_column(table_name='xcom',
                        column_name='execution_date',
                        type_=sa.DateTime())
예제 #29
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users',
                  sa.Column('date_join', mysql.DATETIME(), nullable=True))
    op.add_column(
        'users',
        sa.Column('human_token', mysql.VARCHAR(length=250), nullable=True))
    op.add_column(
        'users', sa.Column('img_link',
                           mysql.VARCHAR(length=250),
                           nullable=True))
    op.add_column('users',
                  sa.Column('email', mysql.VARCHAR(length=50), nullable=True))
    op.add_column(
        'users',
        sa.Column('is_staff',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'users',
        sa.Column('access_token', mysql.VARCHAR(length=250), nullable=True))
    op.add_column(
        'users', sa.Column('zip_code', mysql.VARCHAR(length=10),
                           nullable=True))
    op.add_column(
        'users',
        sa.Column('display_name', mysql.VARCHAR(length=50), nullable=True))
    op.drop_constraint(None, 'users', type_='unique')
    op.alter_column('users',
                    'user_id',
                    existing_type=sa.Integer(),
                    type_=mysql.VARCHAR(length=50),
                    autoincrement=True)
    op.drop_column('users', 'sex')
    op.drop_column('users', 'firebase_id')
    op.drop_column('users', 'date_birth')
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_diarrhea',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_extreme_fatigue',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_asthma',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_dry_cough',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_hiv_aids',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_abdominal_pain',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_no_smell_taste',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('feeling_well', mysql.VARCHAR(length=50), nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_liver_disease',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_diabetes',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_bmi_over_40',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_other',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_copd_emphysema',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_chronic_kidney_disease',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_sore_throat',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_cancer',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_cardiovascular_disease',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('datetime_submitted', mysql.DATETIME(), nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_chills',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_pink_eye',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_pressure_chest',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_nausea_vomiting',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_high_blood_pressure',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_wet_cough',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.alter_column('survey_responses',
                    'user_id',
                    existing_type=sa.Integer(),
                    type_=mysql.VARCHAR(length=50),
                    nullable=True)
예제 #30
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('certificates', 'is_ev')
    op.drop_column('certificates', 'is_cn_wildcard')
    op.drop_column('certificates', 'is_alt_wildcard')
    op.create_table('user_ip_scan_record',
    sa.Column('id', mysql.BIGINT(display_width=20), nullable=False),
    sa.Column('user_id', mysql.INTEGER(display_width=10, unsigned=True), autoincrement=False, nullable=False),
    sa.Column('ip_scan_record_id', mysql.BIGINT(display_width=20), autoincrement=False, nullable=False),
    sa.Column('created_at', mysql.DATETIME(), nullable=True),
    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
    sa.Column('deleted_at', mysql.DATETIME(), nullable=True),
    sa.Column('disabled_at', mysql.DATETIME(), nullable=True),
    sa.Column('scan_periodicity', mysql.BIGINT(display_width=20), autoincrement=False, nullable=True),
    sa.Column('auto_fill_watches', mysql.SMALLINT(display_width=6), server_default=sa.text(u"'0'"), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['ip_scan_record_id'], [u'ip_scan_record.id'], name=u'fk_ip_scan_record_ip_scan_record_id', ondelete=u'CASCADE'),
    sa.ForeignKeyConstraint(['user_id'], [u'users.id'], name=u'fk_user_ip_scan_record_users_id', ondelete=u'CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset=u'utf8',
    mysql_engine=u'InnoDB'
    )
    op.create_table('user_subdomain_watch_target',
    sa.Column('id', mysql.BIGINT(display_width=20), nullable=False),
    sa.Column('user_id', mysql.INTEGER(display_width=10, unsigned=True), autoincrement=False, nullable=False),
    sa.Column('watch_id', mysql.BIGINT(display_width=20), autoincrement=False, nullable=False),
    sa.Column('created_at', mysql.DATETIME(), nullable=True),
    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
    sa.Column('deleted_at', mysql.DATETIME(), nullable=True),
    sa.Column('disabled_at', mysql.DATETIME(), nullable=True),
    sa.Column('auto_scan_added_at', mysql.DATETIME(), nullable=True),
    sa.Column('scan_periodicity', mysql.BIGINT(display_width=20), autoincrement=False, nullable=True),
    sa.Column('scan_type', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True),
    sa.Column('auto_fill_watches', mysql.SMALLINT(display_width=6), autoincrement=False, nullable=False),
    sa.ForeignKeyConstraint(['user_id'], [u'users.id'], name=u'wa_sub_users_id', ondelete=u'CASCADE'),
    sa.ForeignKeyConstraint(['watch_id'], [u'subdomain_watch_target.id'], name=u'wa_sub_watch_target_id', ondelete=u'CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset=u'utf8',
    mysql_engine=u'InnoDB'
    )
    op.create_table('user_watch_target',
    sa.Column('id', mysql.BIGINT(display_width=20), nullable=False),
    sa.Column('user_id', mysql.INTEGER(display_width=10, unsigned=True), autoincrement=False, nullable=False),
    sa.Column('watch_id', mysql.BIGINT(display_width=20), autoincrement=False, nullable=False),
    sa.Column('created_at', mysql.DATETIME(), nullable=True),
    sa.Column('updated_at', mysql.DATETIME(), nullable=True),
    sa.Column('deleted_at', mysql.DATETIME(), nullable=True),
    sa.Column('scan_periodicity', mysql.BIGINT(display_width=20), autoincrement=False, nullable=True),
    sa.Column('scan_type', mysql.INTEGER(display_width=11), autoincrement=False, nullable=True),
    sa.Column('auto_scan_added_at', mysql.DATETIME(), nullable=True),
    sa.Column('disabled_at', mysql.DATETIME(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], [u'users.id'], name=u'wa_users_id', ondelete=u'CASCADE'),
    sa.ForeignKeyConstraint(['watch_id'], [u'watch_target.id'], name=u'wa_watch_target_id', ondelete=u'CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset=u'utf8',
    mysql_engine=u'InnoDB'
    )