commit
9c5fef1a4d
412 files changed
+94582
No files matched your search
@@ -0,0 +1,60 @@
|
||||
"""add artwork ocr texts
|
||||
|
||||
Revision ID: 0007_artwork_ocr_texts
|
||||
Revises: 0006_push_device_tokens
|
||||
Create Date: 2026-06-06
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = "0007_artwork_ocr_texts"
|
||||
down_revision = "0006_push_device_tokens"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"artwork_ocr_texts",
|
||||
sa.Column("user_id", sa.String(length=36), nullable=False),
|
||||
sa.Column("artwork_id", sa.String(length=36), nullable=False),
|
||||
sa.Column("file_id", sa.String(length=36), nullable=True),
|
||||
sa.Column("source_platform", sa.String(length=20), nullable=True),
|
||||
sa.Column("source_id", sa.String(length=50), nullable=True),
|
||||
sa.Column("language", sa.String(length=20), nullable=False),
|
||||
sa.Column("ocr_text", sa.Text(), nullable=False),
|
||||
sa.Column("confidence", sa.Float(), nullable=True),
|
||||
sa.Column("engine", sa.String(length=50), nullable=False),
|
||||
sa.Column("status", sa.String(length=20), nullable=False),
|
||||
sa.Column("attempts", sa.Integer(), nullable=False),
|
||||
sa.Column("error", sa.Text(), nullable=True),
|
||||
sa.Column("id", sa.String(length=36), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(["artwork_id"], ["artworks.id"], ondelete="CASCADE"),
|
||||
sa.ForeignKeyConstraint(["file_id"], ["user_files.id"], ondelete="SET NULL"),
|
||||
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("user_id", "artwork_id", name="uq_artwork_ocr_texts_user_artwork"),
|
||||
)
|
||||
op.create_index("ix_artwork_ocr_texts_user_artwork", "artwork_ocr_texts", ["user_id", "artwork_id"])
|
||||
op.create_index("ix_artwork_ocr_texts_user_status", "artwork_ocr_texts", ["user_id", "status"])
|
||||
op.create_index("ix_artwork_ocr_texts_user_source", "artwork_ocr_texts", ["user_id", "source_platform", "source_id"])
|
||||
if op.get_bind().dialect.name == "postgresql":
|
||||
op.execute(
|
||||
"CREATE INDEX ix_artwork_ocr_texts_ocr_text_gin "
|
||||
"ON artwork_ocr_texts USING gin (to_tsvector('simple', coalesce(ocr_text, '')))"
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if op.get_bind().dialect.name == "postgresql":
|
||||
op.execute("DROP INDEX IF EXISTS ix_artwork_ocr_texts_ocr_text_gin")
|
||||
op.drop_index("ix_artwork_ocr_texts_user_source", table_name="artwork_ocr_texts")
|
||||
op.drop_index("ix_artwork_ocr_texts_user_status", table_name="artwork_ocr_texts")
|
||||
op.drop_index("ix_artwork_ocr_texts_user_artwork", table_name="artwork_ocr_texts")
|
||||
op.drop_table("artwork_ocr_texts")
|
||||
Reference in new issue
Block a user