Big changes
This commit is contained in:
parent
4240ad38e2
commit
e3f0d63fec
99 changed files with 8804 additions and 1731 deletions
106
alembic/versions/20260220_0012_add_data_repair_jobs.py
Normal file
106
alembic/versions/20260220_0012_add_data_repair_jobs.py
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
"""Add data repair job audit table.
|
||||
|
||||
Revision ID: 20260220_0012
|
||||
Revises: 20260220_0011
|
||||
Create Date: 2026-02-20 23:35:00.000000
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
revision: str = "20260220_0012"
|
||||
down_revision: str | Sequence[str] | None = "20260220_0011"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def _table_names() -> set[str]:
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
return set(inspector.get_table_names())
|
||||
|
||||
|
||||
def _create_data_repair_jobs_table() -> None:
|
||||
op.create_table(
|
||||
"data_repair_jobs",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("job_name", sa.String(length=64), nullable=False),
|
||||
sa.Column("requested_by", sa.String(length=255), nullable=True),
|
||||
sa.Column(
|
||||
"scope",
|
||||
postgresql.JSONB(astext_type=sa.Text()),
|
||||
nullable=False,
|
||||
server_default=sa.text("'{}'::jsonb"),
|
||||
),
|
||||
sa.Column("dry_run", sa.Boolean(), nullable=False, server_default=sa.text("true")),
|
||||
sa.Column(
|
||||
"status",
|
||||
sa.String(length=16),
|
||||
nullable=False,
|
||||
server_default=sa.text("'planned'"),
|
||||
),
|
||||
sa.Column(
|
||||
"summary",
|
||||
postgresql.JSONB(astext_type=sa.Text()),
|
||||
nullable=False,
|
||||
server_default=sa.text("'{}'::jsonb"),
|
||||
),
|
||||
sa.Column("error_text", sa.Text(), nullable=True),
|
||||
sa.Column("started_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("finished_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column(
|
||||
"created_at",
|
||||
sa.DateTime(timezone=True),
|
||||
nullable=False,
|
||||
server_default=sa.func.now(),
|
||||
),
|
||||
sa.Column(
|
||||
"updated_at",
|
||||
sa.DateTime(timezone=True),
|
||||
nullable=False,
|
||||
server_default=sa.func.now(),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"status IN ('planned', 'running', 'completed', 'failed')",
|
||||
name="data_repair_jobs_status_valid",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_data_repair_jobs")),
|
||||
)
|
||||
|
||||
|
||||
def _create_data_repair_jobs_indexes() -> None:
|
||||
op.create_index(
|
||||
"ix_data_repair_jobs_created_at",
|
||||
"data_repair_jobs",
|
||||
["created_at"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
"ix_data_repair_jobs_job_name_created_at",
|
||||
"data_repair_jobs",
|
||||
["job_name", "created_at"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def _drop_data_repair_jobs_indexes() -> None:
|
||||
op.drop_index("ix_data_repair_jobs_job_name_created_at", table_name="data_repair_jobs")
|
||||
op.drop_index("ix_data_repair_jobs_created_at", table_name="data_repair_jobs")
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if "data_repair_jobs" in _table_names():
|
||||
return
|
||||
_create_data_repair_jobs_table()
|
||||
_create_data_repair_jobs_indexes()
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if "data_repair_jobs" not in _table_names():
|
||||
return
|
||||
_drop_data_repair_jobs_indexes()
|
||||
op.drop_table("data_repair_jobs")
|
||||
179
alembic/versions/20260221_0013_add_publication_pdf_jobs.py
Normal file
179
alembic/versions/20260221_0013_add_publication_pdf_jobs.py
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
"""Add persistent publication PDF job tracking tables.
|
||||
|
||||
Revision ID: 20260221_0013
|
||||
Revises: 20260220_0012
|
||||
Create Date: 2026-02-21 12:25:00.000000
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "20260221_0013"
|
||||
down_revision: str | Sequence[str] | None = "20260220_0012"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def _table_names() -> set[str]:
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
return set(inspector.get_table_names())
|
||||
|
||||
|
||||
def _create_publication_pdf_jobs_table() -> None:
|
||||
op.create_table(
|
||||
"publication_pdf_jobs",
|
||||
sa.Column("publication_id", sa.Integer(), nullable=False),
|
||||
sa.Column(
|
||||
"status",
|
||||
sa.String(length=16),
|
||||
nullable=False,
|
||||
server_default=sa.text("'queued'"),
|
||||
),
|
||||
sa.Column("attempt_count", sa.Integer(), nullable=False, server_default=sa.text("0")),
|
||||
sa.Column("queued_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("last_attempt_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("resolved_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("last_failure_reason", sa.String(length=64), nullable=True),
|
||||
sa.Column("last_failure_detail", sa.Text(), nullable=True),
|
||||
sa.Column("last_source", sa.String(length=32), nullable=True),
|
||||
sa.Column("last_requested_by_user_id", sa.Integer(), nullable=True),
|
||||
sa.Column(
|
||||
"created_at",
|
||||
sa.DateTime(timezone=True),
|
||||
nullable=False,
|
||||
server_default=sa.func.now(),
|
||||
),
|
||||
sa.Column(
|
||||
"updated_at",
|
||||
sa.DateTime(timezone=True),
|
||||
nullable=False,
|
||||
server_default=sa.func.now(),
|
||||
),
|
||||
sa.CheckConstraint(
|
||||
"status IN ('queued', 'running', 'resolved', 'failed')",
|
||||
name="publication_pdf_jobs_status_valid",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["last_requested_by_user_id"],
|
||||
["users.id"],
|
||||
ondelete="SET NULL",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["publication_id"],
|
||||
["publications.id"],
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("publication_id", name=op.f("pk_publication_pdf_jobs")),
|
||||
)
|
||||
|
||||
|
||||
def _create_publication_pdf_jobs_indexes() -> None:
|
||||
op.create_index(
|
||||
"ix_publication_pdf_jobs_status",
|
||||
"publication_pdf_jobs",
|
||||
["status"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
"ix_publication_pdf_jobs_updated_at",
|
||||
"publication_pdf_jobs",
|
||||
["updated_at"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
"ix_publication_pdf_jobs_queued_at",
|
||||
"publication_pdf_jobs",
|
||||
["queued_at"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def _create_publication_pdf_job_events_table() -> None:
|
||||
op.create_table(
|
||||
"publication_pdf_job_events",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("publication_id", sa.Integer(), nullable=False),
|
||||
sa.Column("user_id", sa.Integer(), nullable=True),
|
||||
sa.Column("event_type", sa.String(length=32), nullable=False),
|
||||
sa.Column("status", sa.String(length=16), nullable=True),
|
||||
sa.Column("source", sa.String(length=32), nullable=True),
|
||||
sa.Column("failure_reason", sa.String(length=64), nullable=True),
|
||||
sa.Column("message", sa.Text(), nullable=True),
|
||||
sa.Column(
|
||||
"created_at",
|
||||
sa.DateTime(timezone=True),
|
||||
nullable=False,
|
||||
server_default=sa.func.now(),
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["publication_id"],
|
||||
["publications.id"],
|
||||
ondelete="CASCADE",
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["user_id"],
|
||||
["users.id"],
|
||||
ondelete="SET NULL",
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id", name=op.f("pk_publication_pdf_job_events")),
|
||||
)
|
||||
|
||||
|
||||
def _create_publication_pdf_job_events_indexes() -> None:
|
||||
op.create_index(
|
||||
"ix_publication_pdf_job_events_publication_created",
|
||||
"publication_pdf_job_events",
|
||||
["publication_id", "created_at"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
"ix_publication_pdf_job_events_created_at",
|
||||
"publication_pdf_job_events",
|
||||
["created_at"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
"ix_publication_pdf_job_events_event_type",
|
||||
"publication_pdf_job_events",
|
||||
["event_type"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def _drop_publication_pdf_jobs_indexes() -> None:
|
||||
op.drop_index("ix_publication_pdf_jobs_queued_at", table_name="publication_pdf_jobs")
|
||||
op.drop_index("ix_publication_pdf_jobs_updated_at", table_name="publication_pdf_jobs")
|
||||
op.drop_index("ix_publication_pdf_jobs_status", table_name="publication_pdf_jobs")
|
||||
|
||||
|
||||
def _drop_publication_pdf_job_events_indexes() -> None:
|
||||
op.drop_index("ix_publication_pdf_job_events_event_type", table_name="publication_pdf_job_events")
|
||||
op.drop_index("ix_publication_pdf_job_events_created_at", table_name="publication_pdf_job_events")
|
||||
op.drop_index(
|
||||
"ix_publication_pdf_job_events_publication_created",
|
||||
table_name="publication_pdf_job_events",
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
tables = _table_names()
|
||||
if "publication_pdf_jobs" not in tables:
|
||||
_create_publication_pdf_jobs_table()
|
||||
_create_publication_pdf_jobs_indexes()
|
||||
if "publication_pdf_job_events" not in tables:
|
||||
_create_publication_pdf_job_events_table()
|
||||
_create_publication_pdf_job_events_indexes()
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
tables = _table_names()
|
||||
if "publication_pdf_job_events" in tables:
|
||||
_drop_publication_pdf_job_events_indexes()
|
||||
op.drop_table("publication_pdf_job_events")
|
||||
if "publication_pdf_jobs" in tables:
|
||||
_drop_publication_pdf_jobs_indexes()
|
||||
op.drop_table("publication_pdf_jobs")
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
"""add scholar publication favorite state
|
||||
|
||||
Revision ID: 20260221_0014
|
||||
Revises: 20260221_0013
|
||||
Create Date: 2026-02-21 14:35:00
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "20260221_0014"
|
||||
down_revision = "20260221_0013"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"scholar_publications",
|
||||
sa.Column(
|
||||
"is_favorite",
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.text("false"),
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_scholar_publications_is_favorite",
|
||||
"scholar_publications",
|
||||
["is_favorite"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(
|
||||
"ix_scholar_publications_is_favorite",
|
||||
table_name="scholar_publications",
|
||||
)
|
||||
op.drop_column("scholar_publications", "is_favorite")
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
"""enforce request delay floor at two seconds
|
||||
|
||||
Revision ID: 20260221_0015
|
||||
Revises: 20260221_0014
|
||||
Create Date: 2026-02-21 18:10:00
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "20260221_0015"
|
||||
down_revision: str | Sequence[str] | None = "20260221_0014"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
TABLE_NAME = "user_settings"
|
||||
CHECK_NAME_MIN_1 = "request_delay_seconds_min_1"
|
||||
CHECK_NAME_MIN_2 = "request_delay_seconds_min_2"
|
||||
LEGACY_CHECK_NAME_MIN_1 = "ck_user_settings_request_delay_seconds_min_1"
|
||||
LEGACY_CHECK_NAME_MIN_2 = "ck_user_settings_request_delay_seconds_min_2"
|
||||
|
||||
|
||||
def _check_constraints() -> set[str]:
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
return {
|
||||
str(item.get("name"))
|
||||
for item in inspector.get_check_constraints(TABLE_NAME)
|
||||
if item.get("name")
|
||||
}
|
||||
|
||||
|
||||
def _drop_check_if_exists(name: str) -> None:
|
||||
if name not in _check_constraints():
|
||||
return
|
||||
op.drop_constraint(
|
||||
name,
|
||||
TABLE_NAME,
|
||||
type_="check",
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.execute(
|
||||
sa.text(
|
||||
"UPDATE user_settings SET request_delay_seconds = 2 "
|
||||
"WHERE request_delay_seconds < 2"
|
||||
)
|
||||
)
|
||||
|
||||
_drop_check_if_exists(CHECK_NAME_MIN_1)
|
||||
_drop_check_if_exists(LEGACY_CHECK_NAME_MIN_1)
|
||||
|
||||
existing = _check_constraints()
|
||||
if CHECK_NAME_MIN_2 not in existing and LEGACY_CHECK_NAME_MIN_2 not in existing:
|
||||
op.create_check_constraint(
|
||||
CHECK_NAME_MIN_2,
|
||||
TABLE_NAME,
|
||||
"request_delay_seconds >= 2",
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
_drop_check_if_exists(CHECK_NAME_MIN_2)
|
||||
_drop_check_if_exists(LEGACY_CHECK_NAME_MIN_2)
|
||||
|
||||
existing = _check_constraints()
|
||||
if CHECK_NAME_MIN_1 not in existing and LEGACY_CHECK_NAME_MIN_1 not in existing:
|
||||
op.create_check_constraint(
|
||||
CHECK_NAME_MIN_1,
|
||||
TABLE_NAME,
|
||||
"request_delay_seconds >= 1",
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue