93 lines
4.1 KiB
Python
93 lines
4.1 KiB
Python
"""Deprecate backend agent config tables.
|
|
|
|
The Electron client is now the source of truth for agent configuration
|
|
(directory, extract targets, batch interval, custom prompt). Backend keeps
|
|
billing checks and trigger/run logs only.
|
|
|
|
Revision ID: 9a1f2d0b6c7e
|
|
Revises: 818478c251dc
|
|
Create Date: 2026-03-16
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
from sqlalchemy.dialects import postgresql
|
|
|
|
revision: str = "9a1f2d0b6c7e"
|
|
down_revision: Union[str, None] = "818478c251dc"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
existing = set(inspector.get_table_names())
|
|
|
|
if "cloud_agent_configs" in existing:
|
|
op.drop_index("ix_cloud_agent_configs_user_id", table_name="cloud_agent_configs")
|
|
op.drop_table("cloud_agent_configs")
|
|
|
|
if "local_agent_configs" in existing:
|
|
op.drop_index("ix_local_agent_configs_user_id", table_name="local_agent_configs")
|
|
op.drop_table("local_agent_configs")
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.create_table(
|
|
"local_agent_configs",
|
|
sa.Column("id", postgresql.UUID(as_uuid=False), nullable=False),
|
|
sa.Column("user_id", postgresql.UUID(as_uuid=False), nullable=False),
|
|
sa.Column("device_id", sa.String(255), nullable=False),
|
|
sa.Column("name", sa.String(255), nullable=False),
|
|
sa.Column("directory_paths", sa.JSON, nullable=False, server_default="[]"),
|
|
sa.Column("data_types", sa.JSON, nullable=False, server_default="[]"),
|
|
sa.Column("prompt_template", sa.Text, nullable=False, server_default=""),
|
|
sa.Column("file_extensions", sa.JSON, nullable=False, server_default="[]"),
|
|
sa.Column("schedule_cron", sa.String(100), nullable=False, server_default="0 */6 * * *"),
|
|
sa.Column("enabled", sa.Boolean, nullable=False, server_default=sa.true()),
|
|
sa.Column("last_run_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
|
)
|
|
op.create_index("ix_local_agent_configs_user_id", "local_agent_configs", ["user_id"])
|
|
|
|
op.execute(
|
|
"""
|
|
DO $$ BEGIN
|
|
CREATE TYPE cloud_provider AS ENUM ('gmail', 'teams', 'outlook');
|
|
EXCEPTION WHEN duplicate_object THEN NULL;
|
|
END $$;
|
|
"""
|
|
)
|
|
|
|
op.create_table(
|
|
"cloud_agent_configs",
|
|
sa.Column("id", postgresql.UUID(as_uuid=False), nullable=False),
|
|
sa.Column("user_id", postgresql.UUID(as_uuid=False), nullable=False),
|
|
sa.Column(
|
|
"provider",
|
|
postgresql.ENUM("gmail", "teams", "outlook", name="cloud_provider", create_type=False),
|
|
nullable=False,
|
|
),
|
|
sa.Column("name", sa.String(255), nullable=False),
|
|
sa.Column("data_types", sa.JSON, nullable=False, server_default="[]"),
|
|
sa.Column("prompt_template", sa.Text, nullable=False, server_default=""),
|
|
sa.Column("oauth_token_encrypted", sa.Text, nullable=True),
|
|
sa.Column("filter_config", sa.JSON, nullable=True),
|
|
sa.Column("schedule_cron", sa.String(100), nullable=False, server_default="0 */6 * * *"),
|
|
sa.Column("enabled", sa.Boolean, nullable=False, server_default=sa.true()),
|
|
sa.Column("last_run_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
|
|
)
|
|
op.create_index("ix_cloud_agent_configs_user_id", "cloud_agent_configs", ["user_id"])
|