Stelle den Frontend-MVP und die v0.3-API auf develop bereit, damit Dev API und PWA zusammen deployen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
827e6a2a11
commit
b276758ee1
152 files changed
+25846
-34
No files matched your search
@@ -0,0 +1,38 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from app.settings import get_settings
|
||||
|
||||
config = context.config
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
config.set_main_option("sqlalchemy.url", get_settings().database_url)
|
||||
target_metadata = None
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(url=url, target_metadata=target_metadata, literal_binds=True)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
with connectable.connect() as connection:
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
@@ -0,0 +1,25 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
revision: str = ${repr(up_revision)}
|
||||
down_revision: str | None = ${repr(down_revision)}
|
||||
branch_labels: str | Sequence[str] | None = ${repr(branch_labels)}
|
||||
depends_on: str | Sequence[str] | None = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,21 @@
|
||||
"""Deploy skeleton — domain schema follows in 0002.
|
||||
|
||||
Revision ID: 0001_deploy_skeleton
|
||||
Revises:
|
||||
Create Date: 2026-10-03
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
revision: str = "0001_deploy_skeleton"
|
||||
down_revision: str | None = None
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
pass
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
pass
|
||||
@@ -0,0 +1,233 @@
|
||||
"""Global product/price schema for v0.1. No user or workspace columns.
|
||||
|
||||
Revision ID: 0002_domain_schema
|
||||
Revises: 0001_deploy_skeleton
|
||||
Create Date: 2026-10-03
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision: str = "0002_domain_schema"
|
||||
down_revision: str | None = "0001_deploy_skeleton"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"attribute_definitions",
|
||||
sa.Column("key", sa.String(128), primary_key=True),
|
||||
sa.Column("value_type", sa.String(32), nullable=False),
|
||||
sa.Column("canonical_unit", sa.String(32)),
|
||||
sa.Column("minimum", sa.Numeric(12, 4)),
|
||||
sa.Column("maximum", sa.Numeric(12, 4)),
|
||||
sa.Column("description", sa.Text()),
|
||||
sa.CheckConstraint(
|
||||
"value_type IN ('number', 'string', 'boolean', 'string_list')",
|
||||
name="ck_attribute_definitions_value_type",
|
||||
),
|
||||
)
|
||||
op.create_table(
|
||||
"sources",
|
||||
sa.Column("id", sa.String(64), primary_key=True),
|
||||
sa.Column("name", sa.String(128), nullable=False),
|
||||
sa.Column("adapter_type", sa.String(64), nullable=False),
|
||||
)
|
||||
op.create_table(
|
||||
"scoring_models",
|
||||
sa.Column("version", sa.String(64), primary_key=True),
|
||||
sa.Column("algorithm_id", sa.String(128), nullable=False),
|
||||
sa.Column("definition", postgresql.JSONB, nullable=False),
|
||||
sa.Column("definition_hash", sa.String(64), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_table(
|
||||
"product_profiles",
|
||||
sa.Column("id", sa.String(128), primary_key=True),
|
||||
sa.Column("version", sa.Integer(), primary_key=True),
|
||||
sa.Column("name", sa.String(256), nullable=False),
|
||||
sa.Column("category", sa.String(128), nullable=False),
|
||||
sa.Column("scoring_version", sa.String(64), sa.ForeignKey("scoring_models.version"), nullable=False),
|
||||
sa.Column("definition", postgresql.JSONB, nullable=False),
|
||||
sa.Column("definition_hash", sa.String(64), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.CheckConstraint("version > 0", name="ck_product_profiles_version"),
|
||||
)
|
||||
op.create_table(
|
||||
"products",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("category", sa.String(128), nullable=False),
|
||||
sa.Column("brand", sa.String(128), nullable=False),
|
||||
sa.Column("name", sa.String(256), nullable=False),
|
||||
sa.Column("model", sa.String(128)),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_table(
|
||||
"product_variants",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("product_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("products.id"), nullable=False),
|
||||
sa.Column("name", sa.String(256), nullable=False),
|
||||
sa.Column("manufacturer_sku", sa.String(128)),
|
||||
sa.Column("identifiers", postgresql.JSONB, nullable=False, server_default=sa.text("'{}'::jsonb")),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_index("ix_product_variants_product_id", "product_variants", ["product_id"])
|
||||
op.create_table(
|
||||
"variant_attributes",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("variant_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("product_variants.id"), nullable=False),
|
||||
sa.Column("attribute_key", sa.String(128), sa.ForeignKey("attribute_definitions.key"), nullable=False),
|
||||
sa.Column("source_id", sa.String(64), sa.ForeignKey("sources.id"), nullable=False),
|
||||
sa.Column("raw_value", postgresql.JSONB, nullable=False),
|
||||
sa.Column("normalized_value", postgresql.JSONB),
|
||||
sa.Column("unit", sa.String(32)),
|
||||
sa.Column("normalization_status", sa.String(32), nullable=False),
|
||||
sa.Column("normalizer_version", sa.String(64), nullable=False),
|
||||
sa.Column("confidence", sa.Numeric(4, 3), nullable=False),
|
||||
sa.Column("source_reference", sa.String(256), nullable=False),
|
||||
sa.Column("observed_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("ingested_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("normalization_error", sa.Text()),
|
||||
sa.CheckConstraint("confidence >= 0 AND confidence <= 1", name="ck_variant_attributes_confidence"),
|
||||
sa.CheckConstraint(
|
||||
"normalization_status IN ('normalized', 'unknown')",
|
||||
name="ck_variant_attributes_status",
|
||||
),
|
||||
)
|
||||
op.execute(
|
||||
"CREATE INDEX ix_variant_attributes_lookup ON variant_attributes "
|
||||
"(variant_id, attribute_key, observed_at DESC, ingested_at DESC, id DESC)"
|
||||
)
|
||||
op.create_table(
|
||||
"offers",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("variant_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("product_variants.id"), nullable=False),
|
||||
sa.Column("source_id", sa.String(64), sa.ForeignKey("sources.id"), nullable=False),
|
||||
sa.Column("external_id", sa.String(256), nullable=False),
|
||||
sa.Column("seller", sa.String(256), nullable=False),
|
||||
sa.Column("url", sa.Text()),
|
||||
sa.Column("market", sa.String(16), nullable=False),
|
||||
sa.Column("currency", sa.String(3), nullable=False),
|
||||
sa.Column("condition", sa.String(32), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.UniqueConstraint("source_id", "external_id", name="uq_offers_source_external"),
|
||||
sa.CheckConstraint("currency ~ '^[A-Z]{3}$'", name="ck_offers_currency"),
|
||||
sa.CheckConstraint("condition IN ('new', 'refurbished', 'used')", name="ck_offers_condition"),
|
||||
)
|
||||
op.create_index("ix_offers_variant_id", "offers", ["variant_id"])
|
||||
op.create_table(
|
||||
"price_observations",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("offer_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("offers.id"), nullable=False),
|
||||
sa.Column("source_id", sa.String(64), sa.ForeignKey("sources.id"), nullable=False),
|
||||
sa.Column("external_observation_id", sa.String(256), nullable=False),
|
||||
sa.Column("observed_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("ingested_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("item_price", sa.Numeric(12, 2), nullable=False),
|
||||
sa.Column("shipping_price", sa.Numeric(12, 2)),
|
||||
sa.Column("currency", sa.String(3), nullable=False),
|
||||
sa.Column("availability", sa.String(32), nullable=False),
|
||||
sa.Column("raw_payload", postgresql.JSONB, nullable=False),
|
||||
sa.Column("confidence", sa.Numeric(4, 3), nullable=False),
|
||||
sa.UniqueConstraint("offer_id", "external_observation_id", name="uq_price_obs_offer_external"),
|
||||
sa.CheckConstraint("item_price > 0", name="ck_price_obs_item_price"),
|
||||
sa.CheckConstraint("shipping_price IS NULL OR shipping_price >= 0", name="ck_price_obs_shipping"),
|
||||
sa.CheckConstraint("confidence >= 0 AND confidence <= 1", name="ck_price_obs_confidence"),
|
||||
sa.CheckConstraint(
|
||||
"availability IN ('in_stock', 'out_of_stock', 'unknown')",
|
||||
name="ck_price_obs_availability",
|
||||
),
|
||||
sa.CheckConstraint("currency ~ '^[A-Z]{3}$'", name="ck_price_obs_currency"),
|
||||
)
|
||||
op.execute(
|
||||
"CREATE INDEX ix_price_observations_lookup ON price_observations "
|
||||
"(offer_id, observed_at DESC, ingested_at DESC, id DESC)"
|
||||
)
|
||||
op.create_table(
|
||||
"evaluations",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("variant_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("product_variants.id"), nullable=False),
|
||||
sa.Column("offer_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("offers.id"), nullable=False),
|
||||
sa.Column("profile_id", sa.String(128), nullable=False),
|
||||
sa.Column("profile_version", sa.Integer(), nullable=False),
|
||||
sa.Column("scoring_version", sa.String(64), sa.ForeignKey("scoring_models.version"), nullable=False),
|
||||
sa.Column("as_of", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("snapshot_cutoff", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("scoring_hash", sa.String(64), nullable=False),
|
||||
sa.Column("engine_build", sa.String(64), nullable=False),
|
||||
sa.Column("product_eligibility", sa.String(16), nullable=False),
|
||||
sa.Column("offer_eligibility", sa.String(16), nullable=False),
|
||||
sa.Column("overall_eligibility", sa.String(16), nullable=False),
|
||||
sa.Column("product_score", sa.Numeric(6, 2)),
|
||||
sa.Column("price_score", sa.Numeric(6, 2)),
|
||||
sa.Column("deal_score", sa.Numeric(6, 2)),
|
||||
sa.Column("classification", sa.String(32), nullable=False),
|
||||
sa.Column("price_reference_scope", sa.String(32), nullable=False),
|
||||
sa.Column("input_snapshot", postgresql.JSONB, nullable=False),
|
||||
sa.Column("result_snapshot", postgresql.JSONB, nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(
|
||||
["profile_id", "profile_version"],
|
||||
["product_profiles.id", "product_profiles.version"],
|
||||
name="fk_evaluations_profile",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"product_eligibility IN ('ELIGIBLE', 'INELIGIBLE', 'UNKNOWN')",
|
||||
name="ck_eval_product_eligibility",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"offer_eligibility IN ('ELIGIBLE', 'INELIGIBLE', 'UNKNOWN')",
|
||||
name="ck_eval_offer_eligibility",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"overall_eligibility IN ('ELIGIBLE', 'INELIGIBLE', 'UNKNOWN')",
|
||||
name="ck_eval_overall_eligibility",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"product_score IS NULL OR (product_score >= 0 AND product_score <= 100)",
|
||||
name="ck_eval_product_score",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"price_score IS NULL OR (price_score >= 0 AND price_score <= 100)",
|
||||
name="ck_eval_price_score",
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"deal_score IS NULL OR (deal_score >= 0 AND deal_score <= 100)",
|
||||
name="ck_eval_deal_score",
|
||||
),
|
||||
)
|
||||
op.create_index("ix_evaluations_variant_id", "evaluations", ["variant_id"])
|
||||
op.execute(
|
||||
"CREATE INDEX ix_evaluations_profile_created ON evaluations "
|
||||
"(profile_id, profile_version, created_at DESC)"
|
||||
)
|
||||
op.create_table(
|
||||
"evaluation_components",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("evaluation_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("evaluations.id"), nullable=False),
|
||||
sa.Column("kind", sa.String(64), nullable=False),
|
||||
sa.Column("component_key", sa.String(128), nullable=False),
|
||||
sa.Column("raw_score", sa.Numeric(12, 6)),
|
||||
sa.Column("weight", sa.Numeric(12, 6)),
|
||||
sa.Column("contribution", sa.Numeric(12, 6)),
|
||||
sa.Column("details", postgresql.JSONB, nullable=False),
|
||||
sa.UniqueConstraint("evaluation_id", "kind", "component_key", name="uq_eval_component"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("evaluation_components")
|
||||
op.drop_table("evaluations")
|
||||
op.drop_table("price_observations")
|
||||
op.drop_table("offers")
|
||||
op.drop_table("variant_attributes")
|
||||
op.drop_table("product_variants")
|
||||
op.drop_table("products")
|
||||
op.drop_table("product_profiles")
|
||||
op.drop_table("scoring_models")
|
||||
op.drop_table("sources")
|
||||
op.drop_table("attribute_definitions")
|
||||
@@ -0,0 +1,229 @@
|
||||
"""Discovery, taxonomy, search runs, and project candidates.
|
||||
|
||||
Revision ID: 0003_discovery_schema
|
||||
Revises: 0002_domain_schema
|
||||
Create Date: 2026-10-04
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision: str = "0003_discovery_schema"
|
||||
down_revision: str | None = "0002_domain_schema"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"buying_projects",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("name", sa.String(256), nullable=False),
|
||||
sa.Column("status", sa.String(32), nullable=False),
|
||||
sa.Column("workspace_id", sa.String(64)),
|
||||
sa.Column("profile_id", sa.String(128), nullable=False),
|
||||
sa.Column("profile_version", sa.Integer(), nullable=False),
|
||||
sa.Column("shortlist_size", sa.Integer(), nullable=False, server_default="5"),
|
||||
sa.Column("schedule_interval_minutes", sa.Integer(), nullable=False, server_default="180"),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("archived_at", sa.DateTime(timezone=True)),
|
||||
sa.ForeignKeyConstraint(
|
||||
["profile_id", "profile_version"],
|
||||
["product_profiles.id", "product_profiles.version"],
|
||||
name="fk_buying_projects_profile",
|
||||
),
|
||||
sa.CheckConstraint("status IN ('ACTIVE', 'PURCHASED', 'ARCHIVED')", name="ck_buying_projects_status"),
|
||||
sa.CheckConstraint("shortlist_size > 0", name="ck_buying_projects_shortlist"),
|
||||
sa.CheckConstraint("schedule_interval_minutes > 0", name="ck_buying_projects_interval"),
|
||||
)
|
||||
op.create_table(
|
||||
"buying_project_criteria",
|
||||
sa.Column("project_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("buying_projects.id"), primary_key=True),
|
||||
sa.Column("version", sa.Integer(), primary_key=True),
|
||||
sa.Column("definition", postgresql.JSONB, nullable=False),
|
||||
sa.Column("definition_hash", sa.String(64), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.CheckConstraint("version > 0", name="ck_project_criteria_version"),
|
||||
)
|
||||
op.create_table(
|
||||
"source_categories",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("source_id", sa.String(64), sa.ForeignKey("sources.id"), nullable=False),
|
||||
sa.Column("external_category_key", sa.String(64), nullable=False),
|
||||
sa.Column("name", sa.String(256), nullable=False),
|
||||
sa.Column("source_url", sa.Text(), nullable=False),
|
||||
sa.Column("status", sa.String(32), nullable=False),
|
||||
sa.Column("last_verified_at", sa.DateTime(timezone=True)),
|
||||
sa.UniqueConstraint("source_id", "external_category_key", name="uq_source_category"),
|
||||
)
|
||||
op.create_table(
|
||||
"source_filter_definitions",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("source_category_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_categories.id"), nullable=False),
|
||||
sa.Column("external_filter_key", sa.String(64), nullable=False),
|
||||
sa.Column("label", sa.String(256), nullable=False),
|
||||
sa.Column("filter_type", sa.String(32), nullable=False),
|
||||
sa.Column("canonical_unit", sa.String(32)),
|
||||
sa.Column("status", sa.String(32), nullable=False),
|
||||
sa.UniqueConstraint("source_category_id", "external_filter_key", name="uq_source_filter"),
|
||||
)
|
||||
op.create_table(
|
||||
"source_filter_options",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("filter_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_filter_definitions.id"), nullable=False),
|
||||
sa.Column("source_value", sa.String(256), nullable=False),
|
||||
sa.Column("normalized_value", postgresql.JSONB),
|
||||
sa.Column("operator", sa.String(16)),
|
||||
sa.Column("unit", sa.String(32)),
|
||||
sa.UniqueConstraint("filter_id", "source_value", name="uq_filter_option"),
|
||||
)
|
||||
op.create_table(
|
||||
"source_filter_ranges",
|
||||
sa.Column("filter_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_filter_definitions.id"), primary_key=True),
|
||||
sa.Column("minimum", sa.Numeric(12, 2)),
|
||||
sa.Column("maximum", sa.Numeric(12, 2)),
|
||||
sa.Column("step", sa.Numeric(12, 2)),
|
||||
sa.Column("unit", sa.String(32)),
|
||||
)
|
||||
op.create_table(
|
||||
"criterion_definitions",
|
||||
sa.Column("key", sa.String(128), primary_key=True),
|
||||
sa.Column("value_type", sa.String(32), nullable=False),
|
||||
sa.Column("unit", sa.String(32)),
|
||||
sa.Column("semantic", sa.String(128)),
|
||||
sa.Column("description", sa.Text()),
|
||||
)
|
||||
op.create_table(
|
||||
"criterion_mappings",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("criterion_key", sa.String(128), sa.ForeignKey("criterion_definitions.key"), nullable=False),
|
||||
sa.Column("source_id", sa.String(64), sa.ForeignKey("sources.id"), nullable=False),
|
||||
sa.Column("source_category_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_categories.id"), nullable=False),
|
||||
sa.Column("external_filter_key", sa.String(64), nullable=False),
|
||||
sa.Column("source_value", sa.String(256)),
|
||||
sa.Column("encoding", postgresql.JSONB, nullable=False),
|
||||
sa.Column("status", sa.String(32), nullable=False),
|
||||
sa.Column("definition_hash", sa.String(64), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_table(
|
||||
"discovery_searches",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("buying_project_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("buying_projects.id"), nullable=False),
|
||||
sa.Column("source_id", sa.String(64), sa.ForeignKey("sources.id"), nullable=False),
|
||||
sa.Column("source_category_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_categories.id"), nullable=False),
|
||||
sa.Column("criteria_version", sa.Integer(), nullable=False),
|
||||
sa.Column("mapping_version", sa.String(64), nullable=False),
|
||||
sa.Column("generated_url", sa.Text(), nullable=False),
|
||||
sa.Column("status", sa.String(32), nullable=False),
|
||||
sa.Column("broad_result_threshold", sa.Integer(), nullable=False, server_default="300"),
|
||||
sa.Column("next_run_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("last_successful_run_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_table(
|
||||
"search_runs",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("discovery_search_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("discovery_searches.id"), nullable=False),
|
||||
sa.Column("criteria_version", sa.Integer(), nullable=False),
|
||||
sa.Column("mapping_version", sa.String(64), nullable=False),
|
||||
sa.Column("generated_url", sa.Text(), nullable=False),
|
||||
sa.Column("started_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("finished_at", sa.DateTime(timezone=True)),
|
||||
sa.Column("status", sa.String(32), nullable=False),
|
||||
sa.Column("result_count", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("page_count", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("http_status_summary", postgresql.JSONB, nullable=False),
|
||||
sa.Column("error_code", sa.String(64)),
|
||||
)
|
||||
op.create_table(
|
||||
"source_product_references",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("source_id", sa.String(64), sa.ForeignKey("sources.id"), nullable=False),
|
||||
sa.Column("source_category_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_categories.id"), nullable=False),
|
||||
sa.Column("source_external_id", sa.String(256)),
|
||||
sa.Column("source_url", sa.Text()),
|
||||
sa.Column("source_title", sa.String(512), nullable=False),
|
||||
sa.Column("manufacturer", sa.String(256)),
|
||||
sa.Column("model", sa.String(256)),
|
||||
sa.Column("manufacturer_sku", sa.String(128)),
|
||||
sa.Column("gtin_ean", sa.String(32)),
|
||||
sa.Column("normalized_spec_fingerprint", sa.Text()),
|
||||
sa.Column("first_seen_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("last_seen_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("lifecycle_status", sa.String(32), nullable=False),
|
||||
sa.Column("match_status", sa.String(32), nullable=False),
|
||||
sa.Column("consecutive_missing_success_runs", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("product_variant_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("product_variants.id")),
|
||||
)
|
||||
op.create_table(
|
||||
"product_observations",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("source_product_reference_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_product_references.id"), nullable=False),
|
||||
sa.Column("search_run_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("search_runs.id"), nullable=False),
|
||||
sa.Column("observed_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("raw_title", sa.String(512), nullable=False),
|
||||
sa.Column("best_price", sa.Numeric(12, 2)),
|
||||
sa.Column("currency", sa.String(3)),
|
||||
sa.Column("raw_attributes", postgresql.JSONB, nullable=False),
|
||||
sa.Column("normalized_attributes", postgresql.JSONB, nullable=False),
|
||||
sa.Column("availability", sa.String(32)),
|
||||
sa.Column("seller_count", sa.Integer()),
|
||||
)
|
||||
op.create_table(
|
||||
"search_run_items",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("search_run_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("search_runs.id"), nullable=False),
|
||||
sa.Column("source_product_reference_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_product_references.id"), nullable=False),
|
||||
sa.Column("observation_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("product_observations.id")),
|
||||
sa.Column("diff_status", sa.String(32), nullable=False),
|
||||
sa.UniqueConstraint("search_run_id", "source_product_reference_id", name="uq_run_item"),
|
||||
)
|
||||
op.create_table(
|
||||
"project_candidates",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("buying_project_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("buying_projects.id"), nullable=False),
|
||||
sa.Column("source_product_reference_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_product_references.id"), nullable=False),
|
||||
sa.Column("product_variant_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("product_variants.id")),
|
||||
sa.Column("status", sa.String(32), nullable=False),
|
||||
sa.Column("match_status", sa.String(32), nullable=False),
|
||||
sa.Column("product_eligibility", sa.String(16)),
|
||||
sa.Column("product_score", sa.Numeric(6, 2)),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.UniqueConstraint("buying_project_id", "source_product_reference_id", name="uq_project_candidate"),
|
||||
)
|
||||
op.create_table(
|
||||
"candidate_status_history",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("candidate_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("project_candidates.id"), nullable=False),
|
||||
sa.Column("from_status", sa.String(32)),
|
||||
sa.Column("to_status", sa.String(32), nullable=False),
|
||||
sa.Column("reason", sa.String(128)),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_index("ix_discovery_searches_next_run", "discovery_searches", ["next_run_at"])
|
||||
op.create_index("ix_search_runs_search", "search_runs", ["discovery_search_id", "started_at"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("candidate_status_history")
|
||||
op.drop_table("project_candidates")
|
||||
op.drop_table("search_run_items")
|
||||
op.drop_table("product_observations")
|
||||
op.drop_table("source_product_references")
|
||||
op.drop_table("search_runs")
|
||||
op.drop_table("discovery_searches")
|
||||
op.drop_table("criterion_mappings")
|
||||
op.drop_table("criterion_definitions")
|
||||
op.drop_table("source_filter_ranges")
|
||||
op.drop_table("source_filter_options")
|
||||
op.drop_table("source_filter_definitions")
|
||||
op.drop_table("source_categories")
|
||||
op.drop_table("buying_project_criteria")
|
||||
op.drop_table("buying_projects")
|
||||
@@ -0,0 +1,127 @@
|
||||
"""Dynamic attribute and criterion value records.
|
||||
|
||||
Revision ID: 0004_dynamic_attributes
|
||||
Revises: 0003_discovery_schema
|
||||
Create Date: 2026-10-04
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision: str = "0004_dynamic_attributes"
|
||||
down_revision: str | None = "0003_discovery_schema"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("criterion_definitions", sa.Column("category", sa.String(128)))
|
||||
op.add_column("source_categories", sa.Column("canonical_category", sa.String(128)))
|
||||
op.create_table(
|
||||
"project_criteria",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("project_id", postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("version", sa.Integer(), nullable=False),
|
||||
sa.Column("item_id", sa.String(128), nullable=False),
|
||||
sa.Column("criterion_key", sa.String(128), sa.ForeignKey("criterion_definitions.key"), nullable=False),
|
||||
sa.Column("operator", sa.String(16), nullable=False),
|
||||
sa.Column("value", postgresql.JSONB),
|
||||
sa.Column("mandatory", sa.Boolean(), nullable=False, server_default=sa.true()),
|
||||
sa.ForeignKeyConstraint(
|
||||
["project_id", "version"],
|
||||
["buying_project_criteria.project_id", "buying_project_criteria.version"],
|
||||
name="fk_project_criteria_version",
|
||||
),
|
||||
sa.UniqueConstraint("project_id", "version", "item_id", name="uq_project_criterion_item"),
|
||||
)
|
||||
op.create_table(
|
||||
"product_observation_attributes",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column(
|
||||
"observation_id",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("product_observations.id"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("attribute_key", sa.String(128), nullable=False),
|
||||
sa.Column("raw_value", postgresql.JSONB),
|
||||
sa.Column("normalized_value", postgresql.JSONB),
|
||||
sa.Column("unit", sa.String(32)),
|
||||
sa.UniqueConstraint("observation_id", "attribute_key", name="uq_observation_attribute"),
|
||||
)
|
||||
_migrate_criteria_json()
|
||||
_migrate_observation_json()
|
||||
op.drop_column("buying_project_criteria", "definition")
|
||||
op.drop_column("product_observations", "raw_attributes")
|
||||
op.drop_column("product_observations", "normalized_attributes")
|
||||
|
||||
|
||||
def _migrate_criteria_json() -> None:
|
||||
bind = op.get_bind()
|
||||
rows = bind.execute(sa.text("SELECT project_id, version, definition FROM buying_project_criteria")).mappings()
|
||||
for row in rows:
|
||||
items = (row["definition"] or {}).get("items") or []
|
||||
for raw in items:
|
||||
bind.execute(
|
||||
sa.text(
|
||||
"""
|
||||
INSERT INTO project_criteria
|
||||
(id, project_id, version, item_id, criterion_key, operator, value, mandatory)
|
||||
VALUES
|
||||
(gen_random_uuid(), :project_id, :version, :item_id, :criterion_key, :operator, :value, :mandatory)
|
||||
"""
|
||||
),
|
||||
{
|
||||
"project_id": row["project_id"],
|
||||
"version": row["version"],
|
||||
"item_id": str(raw.get("id") or raw.get("criterion")),
|
||||
"criterion_key": str(raw.get("criterion")),
|
||||
"operator": str(raw.get("operator")),
|
||||
"value": raw.get("value"),
|
||||
"mandatory": bool(raw.get("mandatory", True)),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def _migrate_observation_json() -> None:
|
||||
bind = op.get_bind()
|
||||
rows = bind.execute(
|
||||
sa.text("SELECT id, raw_attributes, normalized_attributes FROM product_observations")
|
||||
).mappings()
|
||||
for row in rows:
|
||||
raw = row["raw_attributes"] or {}
|
||||
normalized = row["normalized_attributes"] or {}
|
||||
keys = set(raw) | set(normalized)
|
||||
for key in keys:
|
||||
bind.execute(
|
||||
sa.text(
|
||||
"""
|
||||
INSERT INTO product_observation_attributes
|
||||
(id, observation_id, attribute_key, raw_value, normalized_value, unit)
|
||||
VALUES
|
||||
(gen_random_uuid(), :observation_id, :attribute_key, :raw_value, :normalized_value, NULL)
|
||||
"""
|
||||
),
|
||||
{
|
||||
"observation_id": row["id"],
|
||||
"attribute_key": key,
|
||||
"raw_value": raw.get(key),
|
||||
"normalized_value": normalized.get(key),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.add_column("product_observations", sa.Column("raw_attributes", postgresql.JSONB, nullable=False, server_default="{}"))
|
||||
op.add_column(
|
||||
"product_observations",
|
||||
sa.Column("normalized_attributes", postgresql.JSONB, nullable=False, server_default="{}"),
|
||||
)
|
||||
op.add_column("buying_project_criteria", sa.Column("definition", postgresql.JSONB, nullable=False, server_default='{"items":[]}'))
|
||||
op.drop_table("product_observation_attributes")
|
||||
op.drop_table("project_criteria")
|
||||
op.drop_column("source_categories", "canonical_category")
|
||||
op.drop_column("criterion_definitions", "category")
|
||||
@@ -0,0 +1,261 @@
|
||||
"""Frontend MVP v0.3 contracts: categories, optional templates, criterion UUIDs.
|
||||
|
||||
Revision ID: 0005_frontend_mvp_v03
|
||||
Revises: 0004_dynamic_attributes
|
||||
Create Date: 2026-10-04
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision: str = "0005_frontend_mvp_v03"
|
||||
down_revision: str | None = "0004_dynamic_attributes"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"product_categories",
|
||||
sa.Column("id", sa.String(64), primary_key=True),
|
||||
sa.Column("name", sa.String(256), nullable=False),
|
||||
sa.Column("status", sa.String(32), nullable=False, server_default="ACTIVE"),
|
||||
)
|
||||
op.execute("INSERT INTO product_categories (id, name, status) VALUES ('notebook', 'Notebooks', 'ACTIVE')")
|
||||
|
||||
op.add_column("source_categories", sa.Column("product_category_id", sa.String(64)))
|
||||
op.create_foreign_key(
|
||||
"fk_source_categories_product_category",
|
||||
"source_categories",
|
||||
"product_categories",
|
||||
["product_category_id"],
|
||||
["id"],
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE source_categories
|
||||
SET product_category_id = canonical_category
|
||||
WHERE canonical_category IS NOT NULL
|
||||
AND EXISTS (SELECT 1 FROM product_categories WHERE id = source_categories.canonical_category)
|
||||
"""
|
||||
)
|
||||
|
||||
op.add_column("criterion_definitions", sa.Column("id", postgresql.UUID(as_uuid=True)))
|
||||
op.execute("UPDATE criterion_definitions SET id = gen_random_uuid() WHERE id IS NULL")
|
||||
op.alter_column("criterion_definitions", "id", nullable=False)
|
||||
op.add_column(
|
||||
"criterion_definitions",
|
||||
sa.Column("origin", sa.String(16), nullable=False, server_default="SOURCE"),
|
||||
)
|
||||
op.add_column("criterion_definitions", sa.Column("source", sa.String(64)))
|
||||
op.add_column("criterion_definitions", sa.Column("product_category_id", sa.String(64)))
|
||||
op.add_column("criterion_definitions", sa.Column("label", sa.String(256)))
|
||||
op.add_column("criterion_definitions", sa.Column("scoring_attribute_key", sa.String(128)))
|
||||
op.execute("UPDATE criterion_definitions SET label = key WHERE label IS NULL")
|
||||
op.execute("UPDATE criterion_definitions SET scoring_attribute_key = key")
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE criterion_definitions
|
||||
SET product_category_id = category
|
||||
WHERE category IS NOT NULL
|
||||
AND EXISTS (SELECT 1 FROM product_categories WHERE id = criterion_definitions.category)
|
||||
"""
|
||||
)
|
||||
op.alter_column("criterion_definitions", "label", nullable=False)
|
||||
op.create_foreign_key(
|
||||
"fk_criterion_definitions_product_category",
|
||||
"criterion_definitions",
|
||||
"product_categories",
|
||||
["product_category_id"],
|
||||
["id"],
|
||||
)
|
||||
|
||||
op.add_column("project_criteria", sa.Column("criterion_definition_id", postgresql.UUID(as_uuid=True)))
|
||||
op.add_column(
|
||||
"project_criteria",
|
||||
sa.Column("enabled_for_discovery", sa.Boolean(), nullable=False, server_default=sa.true()),
|
||||
)
|
||||
op.add_column("project_criteria", sa.Column("created_at", sa.DateTime(timezone=True)))
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE project_criteria
|
||||
SET enabled_for_discovery = mandatory,
|
||||
created_at = timezone('utc', now())
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE project_criteria AS pc
|
||||
SET criterion_definition_id = cd.id
|
||||
FROM criterion_definitions AS cd
|
||||
WHERE pc.criterion_key = cd.key
|
||||
"""
|
||||
)
|
||||
op.alter_column("project_criteria", "criterion_definition_id", nullable=False)
|
||||
op.alter_column("project_criteria", "created_at", nullable=False)
|
||||
op.drop_constraint("project_criteria_criterion_key_fkey", "project_criteria", type_="foreignkey")
|
||||
|
||||
op.add_column("criterion_mappings", sa.Column("criterion_definition_id", postgresql.UUID(as_uuid=True)))
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE criterion_mappings AS cm
|
||||
SET criterion_definition_id = cd.id
|
||||
FROM criterion_definitions AS cd
|
||||
WHERE cm.criterion_key = cd.key
|
||||
"""
|
||||
)
|
||||
op.alter_column("criterion_mappings", "criterion_definition_id", nullable=False)
|
||||
op.drop_constraint("criterion_mappings_criterion_key_fkey", "criterion_mappings", type_="foreignkey")
|
||||
|
||||
op.drop_constraint("criterion_definitions_pkey", "criterion_definitions", type_="primary")
|
||||
op.create_primary_key("criterion_definitions_pkey", "criterion_definitions", ["id"])
|
||||
op.create_unique_constraint("uq_criterion_definition_key", "criterion_definitions", ["key"])
|
||||
op.create_foreign_key(
|
||||
"fk_project_criteria_definition",
|
||||
"project_criteria",
|
||||
"criterion_definitions",
|
||||
["criterion_definition_id"],
|
||||
["id"],
|
||||
)
|
||||
op.create_foreign_key(
|
||||
"fk_criterion_mappings_definition",
|
||||
"criterion_mappings",
|
||||
"criterion_definitions",
|
||||
["criterion_definition_id"],
|
||||
["id"],
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"source_attribute_mappings",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("source_id", sa.String(64), sa.ForeignKey("sources.id"), nullable=False),
|
||||
sa.Column("source_category_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("source_categories.id")),
|
||||
sa.Column("raw_name", sa.String(256), nullable=False),
|
||||
sa.Column(
|
||||
"criterion_definition_id",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("criterion_definitions.id"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("status", sa.String(32), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
|
||||
op.add_column("buying_projects", sa.Column("product_category_id", sa.String(64)))
|
||||
op.add_column("buying_projects", sa.Column("market", sa.String(8)))
|
||||
op.add_column("buying_projects", sa.Column("currency", sa.String(3)))
|
||||
op.add_column("buying_projects", sa.Column("target_budget", sa.Numeric(12, 2)))
|
||||
op.add_column("buying_projects", sa.Column("template_id", sa.String(128)))
|
||||
op.add_column("buying_projects", sa.Column("template_version", sa.Integer()))
|
||||
op.add_column("buying_projects", sa.Column("criteria_version", sa.Integer(), nullable=False, server_default="1"))
|
||||
op.add_column("buying_projects", sa.Column("updated_at", sa.DateTime(timezone=True)))
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE buying_projects
|
||||
SET template_id = profile_id,
|
||||
template_version = profile_version,
|
||||
product_category_id = 'notebook',
|
||||
market = 'DE',
|
||||
currency = 'EUR',
|
||||
updated_at = created_at
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE buying_projects AS bp
|
||||
SET criteria_version = COALESCE((
|
||||
SELECT MAX(version) FROM buying_project_criteria WHERE project_id = bp.id
|
||||
), 1)
|
||||
"""
|
||||
)
|
||||
op.alter_column("buying_projects", "product_category_id", nullable=False)
|
||||
op.alter_column("buying_projects", "market", nullable=False)
|
||||
op.alter_column("buying_projects", "currency", nullable=False)
|
||||
op.alter_column("buying_projects", "updated_at", nullable=False)
|
||||
op.create_foreign_key(
|
||||
"fk_buying_projects_product_category",
|
||||
"buying_projects",
|
||||
"product_categories",
|
||||
["product_category_id"],
|
||||
["id"],
|
||||
)
|
||||
op.drop_constraint("fk_buying_projects_profile", "buying_projects", type_="foreignkey")
|
||||
op.drop_constraint("ck_buying_projects_interval", "buying_projects", type_="check")
|
||||
op.drop_column("buying_projects", "profile_id")
|
||||
op.drop_column("buying_projects", "profile_version")
|
||||
op.drop_column("buying_projects", "schedule_interval_minutes")
|
||||
op.create_foreign_key(
|
||||
"fk_buying_projects_template",
|
||||
"buying_projects",
|
||||
"product_profiles",
|
||||
["template_id", "template_version"],
|
||||
["id", "version"],
|
||||
)
|
||||
|
||||
op.add_column(
|
||||
"discovery_searches",
|
||||
sa.Column("schedule_interval_minutes", sa.Integer(), nullable=False, server_default="180"),
|
||||
)
|
||||
op.add_column("search_runs", sa.Column("new_count", sa.Integer(), nullable=False, server_default="0"))
|
||||
op.add_column("search_runs", sa.Column("changed_count", sa.Integer(), nullable=False, server_default="0"))
|
||||
op.add_column("search_runs", sa.Column("unchanged_count", sa.Integer(), nullable=False, server_default="0"))
|
||||
op.add_column("search_runs", sa.Column("missing_count", sa.Integer(), nullable=False, server_default="0"))
|
||||
|
||||
op.add_column(
|
||||
"product_observation_attributes",
|
||||
sa.Column("criterion_definition_id", postgresql.UUID(as_uuid=True)),
|
||||
)
|
||||
op.add_column("product_observation_attributes", sa.Column("raw_name", sa.String(256)))
|
||||
op.create_foreign_key(
|
||||
"fk_observation_attributes_definition",
|
||||
"product_observation_attributes",
|
||||
"criterion_definitions",
|
||||
["criterion_definition_id"],
|
||||
["id"],
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE product_observation_attributes AS poa
|
||||
SET criterion_definition_id = cd.id,
|
||||
raw_name = poa.attribute_key
|
||||
FROM criterion_definitions AS cd
|
||||
WHERE poa.attribute_key = cd.scoring_attribute_key
|
||||
OR poa.attribute_key = cd.key
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_constraint("fk_observation_attributes_definition", "product_observation_attributes", type_="foreignkey")
|
||||
op.drop_column("product_observation_attributes", "raw_name")
|
||||
op.drop_column("product_observation_attributes", "criterion_definition_id")
|
||||
op.drop_column("search_runs", "missing_count")
|
||||
op.drop_column("search_runs", "unchanged_count")
|
||||
op.drop_column("search_runs", "changed_count")
|
||||
op.drop_column("search_runs", "new_count")
|
||||
op.drop_column("discovery_searches", "schedule_interval_minutes")
|
||||
op.drop_constraint("fk_buying_projects_template", "buying_projects", type_="foreignkey")
|
||||
op.add_column("buying_projects", sa.Column("profile_id", sa.String(128)))
|
||||
op.add_column("buying_projects", sa.Column("profile_version", sa.Integer()))
|
||||
op.add_column(
|
||||
"buying_projects",
|
||||
sa.Column("schedule_interval_minutes", sa.Integer(), nullable=False, server_default="180"),
|
||||
)
|
||||
op.execute("UPDATE buying_projects SET profile_id = template_id, profile_version = template_version")
|
||||
op.alter_column("buying_projects", "profile_id", nullable=False)
|
||||
op.alter_column("buying_projects", "profile_version", nullable=False)
|
||||
op.drop_constraint("fk_buying_projects_product_category", "buying_projects", type_="foreignkey")
|
||||
op.drop_column("buying_projects", "updated_at")
|
||||
op.drop_column("buying_projects", "criteria_version")
|
||||
op.drop_column("buying_projects", "template_version")
|
||||
op.drop_column("buying_projects", "template_id")
|
||||
op.drop_column("buying_projects", "target_budget")
|
||||
op.drop_column("buying_projects", "currency")
|
||||
op.drop_column("buying_projects", "market")
|
||||
op.drop_column("buying_projects", "product_category_id")
|
||||
op.drop_table("source_attribute_mappings")
|
||||
raise NotImplementedError("full downgrade of criterion UUID primary key is not supported")
|
||||
Reference in new issue
Block a user