class Package(Base, TimestampMixin): """Represents a meta information about application package.""" __tablename__ = 'package' __table_args__ = (sa.Index('ix_package_fqn_and_owner', 'fully_qualified_name', 'owner_id', unique=True), ) id = sa.Column(sa.String(36), primary_key=True, default=uuidutils.generate_uuid) archive = sa.Column(st.LargeBinary()) fully_qualified_name = sa.Column(sa.String(128), nullable=False) type = sa.Column(sa.String(20), nullable=False, default='class') author = sa.Column(sa.String(80), default='OpenStack') supplier = sa.Column(st.JsonBlob(), nullable=True, default={}) name = sa.Column(sa.String(80), nullable=False) enabled = sa.Column(sa.Boolean, default=True) description = sa.Column(sa.Text(), nullable=False, default='The description is not provided') is_public = sa.Column(sa.Boolean, default=False) tags = sa_orm.relationship("Tag", secondary=package_to_tag, cascade='save-update, merge', lazy='joined') logo = sa.Column(st.LargeBinary(), nullable=True) owner_id = sa.Column(sa.String(64), nullable=False) ui_definition = sa.Column(sa.Text) supplier_logo = sa.Column(sa.LargeBinary, nullable=True) categories = sa_orm.relationship("Category", secondary=package_to_category, cascade='save-update, merge', lazy='joined') class_definitions = sa_orm.relationship( "Class", cascade='save-update, merge, delete', lazy='joined', backref='package') def to_dict(self): d = self.__dict__.copy() not_serializable = [ '_sa_instance_state', 'archive', 'logo', 'ui_definition', 'supplier_logo' ] nested_objects = ['categories', 'tags', 'class_definitions'] for key in not_serializable: if key in d.keys(): del d[key] for key in nested_objects: d[key] = [a.name for a in d.get(key, [])] return d
def upgrade(): engine = op.get_bind() if engine.dialect.dialect_description.startswith('mysql'): engine.execute('SET FOREIGN_KEY_CHECKS=0') if engine.dialect.dialect_description == 'postgresql+psycopg2': op.drop_constraint('package_to_tag_package_id_fkey', 'package_to_tag', 'foreignkey') op.drop_constraint('package_to_tag_tag_id_fkey', 'package_to_tag', 'foreignkey') op.drop_constraint('package_to_category_package_id_fkey', 'package_to_category', 'foreignkey') op.drop_constraint('class_definition_package_id_fkey', 'class_definition', 'foreignkey') helpers.transform_table('package', {}, {}, sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('archive', st.LargeBinary(), nullable=True), sa.Column('fully_qualified_name', sa.String(length=128), nullable=False, unique=True), sa.Column('type', sa.String(length=20), nullable=False), sa.Column('author', sa.String(length=80), nullable=True), sa.Column('name', sa.String(length=80), nullable=False), sa.Column('enabled', sa.Boolean(), nullable=True), sa.Column('description', sa.Text(), nullable=False), sa.Column('is_public', sa.Boolean(), nullable=True), sa.Column('logo', st.LargeBinary(), nullable=True), sa.Column('owner_id', sa.String(length=36), nullable=False), sa.Column('ui_definition', sa.Text(), nullable=True), sa.Column('supplier_logo', sa.types.LargeBinary), sa.Column('supplier', sa.types.Text()), sa.PrimaryKeyConstraint('id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_index('ix_package_fqn', 'package', ['fully_qualified_name']) if engine.dialect.dialect_description.startswith('mysql'): engine.execute('SET FOREIGN_KEY_CHECKS=1') if engine.dialect.dialect_description == 'postgresql+psycopg2': op.create_foreign_key('package_to_tag_package_id_fkey', 'package_to_tag', 'package', ['package_id'], ['id']) op.create_foreign_key('package_to_tag_tag_id_fkey', 'package_to_tag', 'tag', ['tag_id'], ['id']) op.create_foreign_key('package_to_category_package_id_fkey', 'package_to_category', 'package', ['package_id'], ['id']) op.create_foreign_key('class_definition_package_id_fkey', 'class_definition', 'package', ['package_id'], ['id'])
def upgrade(): op.create_table('environment', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=255), nullable=False), sa.Column('name', sa.String(length=255), nullable=False), sa.Column('tenant_id', sa.String(length=36), nullable=False), sa.Column('version', sa.BigInteger(), nullable=False), sa.Column('description', sa.Text(), nullable=False), sa.Column('networking', sa.Text(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('tenant_id', 'name'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_table('tag', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=80), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_table('category', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=80), nullable=False, unique=True), sa.PrimaryKeyConstraint('id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_index('ix_category_name', 'category', ['name']) op.create_table('apistats', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.Integer(), nullable=False), sa.Column('host', sa.String(length=80), nullable=True), sa.Column('request_count', sa.BigInteger(), nullable=True), sa.Column('error_count', sa.BigInteger(), nullable=True), sa.Column('average_response_time', sa.Float(), nullable=True), sa.Column('requests_per_tenant', sa.Text(), nullable=True), sa.Column('requests_per_second', sa.Float(), nullable=True), sa.Column('errors_per_second', sa.Float(), nullable=True), sa.Column('cpu_count', sa.Integer(), nullable=True), sa.Column('cpu_percent', sa.Float(), nullable=True), sa.PrimaryKeyConstraint('id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_table('instance_stats', sa.Column('environment_id', sa.String(length=255), nullable=False), sa.Column('instance_id', sa.String(length=255), nullable=False), sa.Column('instance_type', sa.Integer(), nullable=False), sa.Column('created', sa.Integer(), nullable=False), sa.Column('destroyed', sa.Integer(), nullable=True), sa.Column('type_name', sa.String(length=512), nullable=False), sa.Column('type_title', sa.String(length=512), nullable=True), sa.Column('unit_count', sa.Integer(), nullable=True), sa.Column('tenant_id', sa.String(length=36), nullable=False), sa.PrimaryKeyConstraint('environment_id', 'instance_id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_table('package', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('archive', st.LargeBinary(), nullable=True), sa.Column('fully_qualified_name', sa.String(length=128), nullable=False, unique=True), sa.Column('type', sa.String(length=20), nullable=False), sa.Column('author', sa.String(length=80), nullable=True), sa.Column('name', sa.String(length=80), nullable=False), sa.Column('enabled', sa.Boolean(), nullable=True), sa.Column('description', sa.String(length=512), nullable=False), sa.Column('is_public', sa.Boolean(), nullable=True), sa.Column('logo', st.LargeBinary(), nullable=True), sa.Column('owner_id', sa.String(length=36), nullable=False), sa.Column('ui_definition', sa.Text(), nullable=True), sa.PrimaryKeyConstraint('id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_index('ix_package_fqn', 'package', ['fully_qualified_name']) op.create_table('session', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('environment_id', sa.String(length=255), nullable=True), sa.Column('user_id', sa.String(length=36), nullable=False), sa.Column('state', sa.String(length=36), nullable=False), sa.Column('description', sa.Text(), nullable=False), sa.Column('version', sa.BigInteger(), nullable=False), sa.ForeignKeyConstraint( ['environment_id'], ['environment.id'], ), sa.PrimaryKeyConstraint('id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_table('deployment', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('started', sa.DateTime(), nullable=False), sa.Column('finished', sa.DateTime(), nullable=True), sa.Column('description', sa.Text(), nullable=False), sa.Column('environment_id', sa.String(length=255), nullable=True), sa.ForeignKeyConstraint( ['environment_id'], ['environment.id'], ), sa.PrimaryKeyConstraint('id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_table('class_definition', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=128), nullable=False, unique=True), sa.Column('package_id', sa.String(length=36), nullable=True), sa.ForeignKeyConstraint( ['package_id'], ['package.id'], ), sa.PrimaryKeyConstraint('id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_index('ix_class_definition_name', 'class_definition', ['name']) op.create_table('status', sa.Column('created', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('entity_id', sa.String(length=255), nullable=True), sa.Column('entity', sa.String(length=10), nullable=True), sa.Column('deployment_id', sa.String(length=36), nullable=True), sa.Column('text', sa.Text(), nullable=False), sa.Column('level', sa.String(length=32), nullable=False), sa.Column('details', sa.Text(), nullable=True), sa.ForeignKeyConstraint( ['deployment_id'], ['deployment.id'], ), sa.PrimaryKeyConstraint('id'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_table('package_to_tag', sa.Column('package_id', sa.String(length=36), nullable=False), sa.Column('tag_id', sa.String(length=36), nullable=False), sa.ForeignKeyConstraint( ['package_id'], ['package.id'], ), sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ondelete='CASCADE'), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) op.create_table('package_to_category', sa.Column('package_id', sa.String(length=36), nullable=False), sa.Column('category_id', sa.String(length=36), nullable=False), sa.ForeignKeyConstraint(['category_id'], ['category.id'], ondelete='RESTRICT'), sa.ForeignKeyConstraint( ['package_id'], ['package.id'], ), mysql_engine=MYSQL_ENGINE, mysql_charset=MYSQL_CHARSET) _create_default_categories(op)