Files
orion/alembic/versions_backup/f2b3c4d5e6f7_create_translation_tables.py
Samir Boulahtit f20266167d
Some checks failed
CI / ruff (push) Failing after 7s
CI / pytest (push) Failing after 1s
CI / architecture (push) Failing after 9s
CI / dependency-scanning (push) Successful in 27s
CI / audit (push) Successful in 8s
CI / docs (push) Has been skipped
fix(lint): auto-fix ruff violations and tune lint rules
- Auto-fixed 4,496 lint issues (import sorting, modern syntax, etc.)
- Added ignore rules for patterns intentional in this codebase:
  E402 (late imports), E712 (SQLAlchemy filters), B904 (raise from),
  SIM108/SIM105/SIM117 (readability preferences)
- Added per-file ignores for tests and scripts
- Excluded broken scripts/rename_terminology.py (has curly quotes)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 23:10:42 +01:00

148 lines
5.1 KiB
Python

"""Create translation tables for multi-language support
Revision ID: f2b3c4d5e6f7
Revises: e1a2b3c4d5e6
Create Date: 2025-12-11
This migration creates:
- marketplace_product_translations: Localized content from marketplace sources
- product_translations: Vendor-specific localized overrides
The translation tables support multi-language product information with
language fallback capabilities. Fields in product_translations can be
NULL to inherit from marketplace_product_translations.
"""
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision: str = "f2b3c4d5e6f7"
down_revision: str | None = "e1a2b3c4d5e6"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
# Create marketplace_product_translations table
# Note: Unique constraint is included in create_table for SQLite compatibility
op.create_table(
"marketplace_product_translations",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column(
"marketplace_product_id",
sa.Integer(),
sa.ForeignKey("marketplace_products.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("language", sa.String(5), nullable=False),
# Localized content
sa.Column("title", sa.String(), nullable=False),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("short_description", sa.String(500), nullable=True),
# SEO fields
sa.Column("meta_title", sa.String(70), nullable=True),
sa.Column("meta_description", sa.String(160), nullable=True),
sa.Column("url_slug", sa.String(255), nullable=True),
# Source tracking
sa.Column("source_import_id", sa.Integer(), nullable=True),
sa.Column("source_file", sa.String(), nullable=True),
# Timestamps
sa.Column(
"created_at",
sa.DateTime(),
nullable=False,
server_default=sa.text("CURRENT_TIMESTAMP"),
),
sa.Column(
"updated_at",
sa.DateTime(),
nullable=False,
server_default=sa.text("CURRENT_TIMESTAMP"),
),
# Unique constraint included in table creation for SQLite
sa.UniqueConstraint(
"marketplace_product_id",
"language",
name="uq_marketplace_product_translation",
),
)
# Create indexes for marketplace_product_translations
op.create_index(
"idx_mpt_marketplace_product_id",
"marketplace_product_translations",
["marketplace_product_id"],
)
op.create_index(
"idx_mpt_language",
"marketplace_product_translations",
["language"],
)
# Create product_translations table
# Note: Unique constraint is included in create_table for SQLite compatibility
op.create_table(
"product_translations",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column(
"product_id",
sa.Integer(),
sa.ForeignKey("products.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("language", sa.String(5), nullable=False),
# Overridable localized content (NULL = inherit from marketplace)
sa.Column("title", sa.String(), nullable=True),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("short_description", sa.String(500), nullable=True),
# SEO overrides
sa.Column("meta_title", sa.String(70), nullable=True),
sa.Column("meta_description", sa.String(160), nullable=True),
sa.Column("url_slug", sa.String(255), nullable=True),
# Timestamps
sa.Column(
"created_at",
sa.DateTime(),
nullable=False,
server_default=sa.text("CURRENT_TIMESTAMP"),
),
sa.Column(
"updated_at",
sa.DateTime(),
nullable=False,
server_default=sa.text("CURRENT_TIMESTAMP"),
),
# Unique constraint included in table creation for SQLite
sa.UniqueConstraint("product_id", "language", name="uq_product_translation"),
)
# Create indexes for product_translations
op.create_index(
"idx_pt_product_id",
"product_translations",
["product_id"],
)
op.create_index(
"idx_pt_product_language",
"product_translations",
["product_id", "language"],
)
def downgrade() -> None:
# Drop product_translations table and its indexes
op.drop_index("idx_pt_product_language", table_name="product_translations")
op.drop_index("idx_pt_product_id", table_name="product_translations")
op.drop_table("product_translations")
# Drop marketplace_product_translations table and its indexes
op.drop_index("idx_mpt_language", table_name="marketplace_product_translations")
op.drop_index(
"idx_mpt_marketplace_product_id", table_name="marketplace_product_translations"
)
op.drop_table("marketplace_product_translations")