feat: persist feature research and versioned alpha assessments
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Stage two: immutable evaluations; features and saved views reuse asset revisions."""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "0007"
|
||||
down_revision = "0006"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
edges = op.create_table(
|
||||
"research_parents",
|
||||
sa.Column("child_id", sa.String(36), sa.ForeignKey("research_experiments.id"), primary_key=True),
|
||||
sa.Column("parent_kind", sa.String(30), primary_key=True),
|
||||
sa.Column("parent_id", sa.String(100), primary_key=True),
|
||||
)
|
||||
op.create_index("ix_research_parents_parent_id", "research_parents", ["parent_id"])
|
||||
experiments = sa.table("research_experiments", sa.column("id"), sa.column("parents", sa.JSON()))
|
||||
for row in op.get_bind().execute(sa.select(experiments)).mappings():
|
||||
values = [
|
||||
{"child_id": row["id"], "parent_kind": kind, "parent_id": parent_id}
|
||||
for kind, parent_id in {(p["kind"], p["id"]) for p in row["parents"]}
|
||||
]
|
||||
if values:
|
||||
op.bulk_insert(edges, values)
|
||||
op.create_table(
|
||||
"research_evaluations",
|
||||
sa.Column("id", sa.String(36), primary_key=True),
|
||||
sa.Column("alpha_id", sa.String(100), sa.ForeignKey("alphas.id"), nullable=True),
|
||||
sa.Column("experiment_id", sa.String(36), sa.ForeignKey("research_experiments.id"), nullable=True),
|
||||
sa.Column("report", sa.JSON(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_index("ix_research_evaluations_alpha_id", "research_evaluations", ["alpha_id"])
|
||||
op.create_index("ix_research_evaluations_experiment_id", "research_evaluations", ["experiment_id"])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table("research_evaluations")
|
||||
op.drop_table("research_parents")
|
||||
Reference in New Issue
Block a user