def setUp(self): # we change DB metadata in tests so we reload # models to refresh the metadata to it's original state six.moves.reload_module(rally.common.db.sqlalchemy.models) super(MigrationTestCase, self).setUp() self.alembic_config = api._alembic_config() self.engine = api.get_engine() # remove everything from DB and stamp it as 'base' # so that migration (i.e. upgrade up to 'head') # will actually take place db.schema_cleanup() db.schema_stamp("base")
def setUp(self): # we change DB metadata in tests so we reload # models to refresh the metadata to it's original state six.moves.reload_module(rally.common.db.sqlalchemy.models) super(MigrationTestCase, self).setUp() self.alembic_config = api._alembic_config() self.engine = api.get_engine() # remove everything from DB and stamp it as 'base' # so that migration (i.e. upgrade up to 'head') # will actually take place db.schema_cleanup() db.schema_stamp("base")
def run_migrations_online(): """Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context. """ engine = api.get_engine() with engine.connect() as connection: context.configure(connection=connection, target_metadata=target_metadata) with context.begin_transaction(): context.run_migrations()
def setUp(self): super(MigrationWalkTestCase, self).setUp() self.engine = api.get_engine()
def drop_db(): from rally.common.db.sqlalchemy import api as sa_api drop_all_objects(sa_api.get_engine())
def create_db(): from rally.common.db.sqlalchemy import api as sa_api BASE.metadata.create_all(sa_api.get_engine())
def drop_db(): # NOTE(LimingWu): We can't direct import the api module. That will # result in the cyclic reference import since the api has imported # this module. from rally.common.db.sqlalchemy import api as sa_api drop_all_objects(sa_api.get_engine())
def upgrade(): dialect = api.get_engine().dialect deployments_columns = [ sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("uuid", sa.String(length=36), nullable=False), sa.Column("parent_uuid", sa.String(length=36), nullable=True), sa.Column("name", sa.String(length=255), nullable=True), sa.Column("started_at", sa.DateTime(), nullable=True), sa.Column("completed_at", sa.DateTime(), nullable=True), sa.Column("config", rally.common.db.sqlalchemy.types.MutableJSONEncodedDict(), nullable=False), sa.Column("admin", sa.PickleType(), nullable=True), sa.Column("users", sa.PickleType(), nullable=False), sa.Column("enum_deployments_status", sa.Enum("cleanup->failed", "cleanup->finished", "cleanup->started", "deploy->failed", "deploy->finished", "deploy->inconsistent", "deploy->init", "deploy->started", "deploy->subdeploy", name="enum_deploy_status"), nullable=False), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name") ] if dialect.name.startswith("sqlite"): deployments_columns.append( sa.ForeignKeyConstraint(["parent_uuid"], [u"deployments.uuid"], name="fk_parent_uuid", use_alter=True)) # commands auto generated by Alembic - please adjust! op.create_table("deployments", *deployments_columns) op.create_index("deployment_parent_uuid", "deployments", ["parent_uuid"], unique=False) op.create_index("deployment_uuid", "deployments", ["uuid"], unique=True) if not dialect.name.startswith("sqlite"): op.create_foreign_key("fk_parent_uuid", "deployments", "deployments", ["parent_uuid"], ["uuid"]) op.create_table( "workers", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("hostname", sa.String(length=255), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("hostname", name="uniq_worker@hostname")) op.create_table( "resources", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("provider_name", sa.String(length=255), nullable=True), sa.Column("type", sa.String(length=255), nullable=True), sa.Column("info", rally.common.db.sqlalchemy.types.MutableJSONEncodedDict(), nullable=False), sa.Column("deployment_uuid", sa.String(length=36), nullable=False), sa.ForeignKeyConstraint(["deployment_uuid"], [u"deployments.uuid"]), sa.PrimaryKeyConstraint("id")) op.create_index("resource_deployment_uuid", "resources", ["deployment_uuid"], unique=False) op.create_index("resource_provider_name", "resources", ["deployment_uuid", "provider_name"], unique=False) op.create_index("resource_provider_name_and_type", "resources", ["deployment_uuid", "provider_name", "type"], unique=False) op.create_index("resource_type", "resources", ["deployment_uuid", "type"], unique=False) op.create_table( "tasks", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("uuid", sa.String(length=36), nullable=False), sa.Column("status", sa.Enum("aborted", "aborting", "cleaning up", "failed", "finished", "init", "paused", "running", "setting up", "soft_aborting", "verifying", name="enum_tasks_status"), nullable=False), sa.Column("verification_log", sa.Text(), nullable=True), sa.Column("tag", sa.String(length=64), nullable=True), sa.Column("deployment_uuid", sa.String(length=36), nullable=False), sa.ForeignKeyConstraint( ["deployment_uuid"], [u"deployments.uuid"], ), sa.PrimaryKeyConstraint("id")) op.create_index("task_deployment", "tasks", ["deployment_uuid"], unique=False) op.create_index("task_status", "tasks", ["status"], unique=False) op.create_index("task_uuid", "tasks", ["uuid"], unique=True) op.create_table( "verifications", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("uuid", sa.String(length=36), nullable=False), sa.Column("deployment_uuid", sa.String(length=36), nullable=False), sa.Column("status", sa.Enum("aborted", "aborting", "cleaning up", "failed", "finished", "init", "paused", "running", "setting up", "soft_aborting", "verifying", name="enum_tasks_status"), nullable=False), sa.Column("set_name", sa.String(length=20), nullable=True), sa.Column("tests", sa.Integer(), nullable=True), sa.Column("errors", sa.Integer(), nullable=True), sa.Column("failures", sa.Integer(), nullable=True), sa.Column("time", sa.Float(), nullable=True), sa.ForeignKeyConstraint( ["deployment_uuid"], [u"deployments.uuid"], ), sa.PrimaryKeyConstraint("id")) op.create_index("verification_uuid", "verifications", ["uuid"], unique=True) op.create_table( "task_results", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("key", rally.common.db.sqlalchemy.types.MutableJSONEncodedDict(), nullable=False), sa.Column("data", rally.common.db.sqlalchemy.types.BigMutableJSONEncodedDict(), nullable=False), sa.Column("task_uuid", sa.String(length=36), nullable=True), sa.ForeignKeyConstraint( ["task_uuid"], ["tasks.uuid"], ), sa.PrimaryKeyConstraint("id")) op.create_table( "verification_results", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("verification_uuid", sa.String(length=36), nullable=True), sa.Column("data", rally.common.db.sqlalchemy.types.BigMutableJSONEncodedDict(), nullable=False), sa.ForeignKeyConstraint(["verification_uuid"], ["verifications.uuid"]), sa.PrimaryKeyConstraint("id"))
def setUp(self): super(MigrationWalkTestCase, self).setUp() self.engine = api.get_engine()
def upgrade(): dialect = api.get_engine().dialect deployments_columns = [ sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("uuid", sa.String(length=36), nullable=False), sa.Column("parent_uuid", sa.String(length=36), nullable=True), sa.Column("name", sa.String(length=255), nullable=True), sa.Column("started_at", sa.DateTime(), nullable=True), sa.Column("completed_at", sa.DateTime(), nullable=True), sa.Column( "config", rally.common.db.sqlalchemy.types.MutableJSONEncodedDict(), nullable=False), sa.Column("admin", sa.PickleType(), nullable=True), sa.Column("users", sa.PickleType(), nullable=False), sa.Column("enum_deployments_status", sa.Enum( "cleanup->failed", "cleanup->finished", "cleanup->started", "deploy->failed", "deploy->finished", "deploy->inconsistent", "deploy->init", "deploy->started", "deploy->subdeploy", name="enum_deploy_status"), nullable=False), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("name") ] if dialect.name.startswith("sqlite"): deployments_columns.append( sa.ForeignKeyConstraint( ["parent_uuid"], [u"deployments.uuid"], name="fk_parent_uuid", use_alter=True) ) # commands auto generated by Alembic - please adjust! op.create_table("deployments", *deployments_columns) op.create_index("deployment_parent_uuid", "deployments", ["parent_uuid"], unique=False) op.create_index("deployment_uuid", "deployments", ["uuid"], unique=True) if not dialect.name.startswith("sqlite"): op.create_foreign_key("fk_parent_uuid", "deployments", "deployments", ["parent_uuid"], ["uuid"]) op.create_table( "workers", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("hostname", sa.String(length=255), nullable=True), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("hostname", name="uniq_worker@hostname") ) op.create_table( "resources", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("provider_name", sa.String(length=255), nullable=True), sa.Column("type", sa.String(length=255), nullable=True), sa.Column( "info", rally.common.db.sqlalchemy.types.MutableJSONEncodedDict(), nullable=False), sa.Column("deployment_uuid", sa.String(length=36), nullable=False), sa.ForeignKeyConstraint(["deployment_uuid"], [u"deployments.uuid"]), sa.PrimaryKeyConstraint("id") ) op.create_index("resource_deployment_uuid", "resources", ["deployment_uuid"], unique=False) op.create_index("resource_provider_name", "resources", ["deployment_uuid", "provider_name"], unique=False) op.create_index("resource_provider_name_and_type", "resources", ["deployment_uuid", "provider_name", "type"], unique=False) op.create_index("resource_type", "resources", ["deployment_uuid", "type"], unique=False) op.create_table( "tasks", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("uuid", sa.String(length=36), nullable=False), sa.Column("status", sa.Enum( "aborted", "aborting", "cleaning up", "failed", "finished", "init", "paused", "running", "setting up", "soft_aborting", "verifying", name="enum_tasks_status"), nullable=False), sa.Column("verification_log", sa.Text(), nullable=True), sa.Column("tag", sa.String(length=64), nullable=True), sa.Column("deployment_uuid", sa.String(length=36), nullable=False), sa.ForeignKeyConstraint(["deployment_uuid"], [u"deployments.uuid"], ), sa.PrimaryKeyConstraint("id") ) op.create_index("task_deployment", "tasks", ["deployment_uuid"], unique=False) op.create_index("task_status", "tasks", ["status"], unique=False) op.create_index("task_uuid", "tasks", ["uuid"], unique=True) op.create_table( "verifications", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("uuid", sa.String(length=36), nullable=False), sa.Column("deployment_uuid", sa.String(length=36), nullable=False), sa.Column("status", sa.Enum( "aborted", "aborting", "cleaning up", "failed", "finished", "init", "paused", "running", "setting up", "soft_aborting", "verifying", name="enum_tasks_status"), nullable=False), sa.Column("set_name", sa.String(length=20), nullable=True), sa.Column("tests", sa.Integer(), nullable=True), sa.Column("errors", sa.Integer(), nullable=True), sa.Column("failures", sa.Integer(), nullable=True), sa.Column("time", sa.Float(), nullable=True), sa.ForeignKeyConstraint(["deployment_uuid"], [u"deployments.uuid"], ), sa.PrimaryKeyConstraint("id") ) op.create_index("verification_uuid", "verifications", ["uuid"], unique=True) op.create_table( "task_results", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column( "key", rally.common.db.sqlalchemy.types.MutableJSONEncodedDict(), nullable=False), sa.Column( "data", rally.common.db.sqlalchemy.types.BigMutableJSONEncodedDict(), nullable=False), sa.Column("task_uuid", sa.String(length=36), nullable=True), sa.ForeignKeyConstraint(["task_uuid"], ["tasks.uuid"], ), sa.PrimaryKeyConstraint("id") ) op.create_table( "verification_results", sa.Column("created_at", sa.DateTime(), nullable=True), sa.Column("updated_at", sa.DateTime(), nullable=True), sa.Column("id", sa.Integer(), nullable=False), sa.Column("verification_uuid", sa.String(length=36), nullable=True), sa.Column( "data", rally.common.db.sqlalchemy.types.BigMutableJSONEncodedDict(), nullable=False), sa.ForeignKeyConstraint(["verification_uuid"], ["verifications.uuid"]), sa.PrimaryKeyConstraint("id") )
def drop_db(): from rally.common.db.sqlalchemy import api as sa_api drop_all_objects(sa_api.get_engine())
def create_db(): from rally.common.db.sqlalchemy import api as sa_api BASE.metadata.create_all(sa_api.get_engine())
def drop_db(): # NOTE(LimingWu): We can't direct import the api module. That will # result in the cyclic reference import since the api has imported # this module. from rally.common.db.sqlalchemy import api as sa_api drop_all_objects(sa_api.get_engine())