Skip to content

Commit

Permalink
Delete old case and context rows
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Apr 30, 2021
1 parent 777b95a commit 0a0b131
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
78 changes: 78 additions & 0 deletions conbench/tests/migrations/test_8411faeebc1f_old_case_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import os

from alembic import command
from alembic.config import Config
from sqlalchemy.exc import InvalidRequestError

from ...db import Session
from ...entities.case import Case
from ...entities.context import Context


this_dir = os.path.abspath(os.path.dirname(__file__))
config_path = os.path.join(this_dir, "../../../alembic.ini")


def test_upgrade():
case_1 = Case.create(
{
"name": "case 1",
"tags": {
"dataset": "nyctaxi_sample",
"cpu_count": 2,
"file_type": "parquet",
"gc_collect": True,
"gc_disable": True,
"input_type": "arrow",
"compression": "snappy",
},
}
)
case_2 = Case.create(
{
"name": "case 2",
"tags": {
"dataset": "nyctaxi_sample",
"cpu_count": 2,
"file_type": "parquet",
"input_type": "arrow",
"compression": "snappy",
},
}
)
context_1 = Context.create(
{
"tags": {
"arrow_compiler_version": "9.3.0",
"arrow_version": "4.0.0",
"benchmark_language": "C++",
"arrow_git_revision": "d5fd3b497c4254ec18bea5943bb9920d0",
},
}
)
context_2 = Context.create(
{
"tags": {
"arrow_compiler_version": "9.3.0",
"arrow_version": "4.0.0",
"benchmark_language": "C++",
},
}
)

# do migration
alembic_config = Config(config_path)
command.stamp(alembic_config, "4a5177dc4e44")
command.upgrade(alembic_config, "8411faeebc1f")

# assert after migration
try:
Session.refresh(case_1)
except InvalidRequestError:
pass # deleted
Session.refresh(case_2)
try:
Session.refresh(context_1)
except InvalidRequestError:
pass # deleted
Session.refresh(context_2)
34 changes: 34 additions & 0 deletions migrations/versions/8411faeebc1f_old_case_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""old case context
Revision ID: 8411faeebc1f
Revises: 4a5177dc4e44
Create Date: 2021-04-30 08:46:48.985283
"""
from alembic import op
from sqlalchemy import MetaData


# revision identifiers, used by Alembic.
revision = "8411faeebc1f"
down_revision = "4a5177dc4e44"
branch_labels = None
depends_on = None


def upgrade():
connection = op.get_bind()
meta = MetaData()
meta.reflect(bind=connection)
case_table = meta.tables["case"]
context_table = meta.tables["context"]
where = case_table.c.tags.has_key("gc_collect") # noqa
connection.execute(case_table.delete().where(where))
where = case_table.c.tags.has_key("gc_disable") # noqa
connection.execute(case_table.delete().where(where))
where = context_table.c.tags.has_key("arrow_git_revision") # noqa
connection.execute(context_table.delete().where(where))


def downgrade():
pass

0 comments on commit 0a0b131

Please sign in to comment.