mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 12:45:42 +02:00
Implementazioni varie
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
Migrazione 0010: tabella message_templates (Feature 1 – Template messaggi).
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = "0010"
|
||||
down_revision = "0009"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"message_templates",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column(
|
||||
"tenant_id",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("tenants.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("name", sa.String(255), nullable=False),
|
||||
sa.Column("description", sa.Text, nullable=True),
|
||||
sa.Column("subject", sa.Text, nullable=False, server_default=""),
|
||||
sa.Column("body_text", sa.Text, nullable=True),
|
||||
sa.Column("body_html", sa.Text, nullable=True),
|
||||
sa.Column(
|
||||
"created_by",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("users.id", ondelete="SET NULL"),
|
||||
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.UniqueConstraint("tenant_id", "name", name="uq_template_name_tenant"),
|
||||
)
|
||||
op.create_index("idx_templates_tenant", "message_templates", ["tenant_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("idx_templates_tenant", table_name="message_templates")
|
||||
op.drop_table("message_templates")
|
||||
@@ -0,0 +1,110 @@
|
||||
"""
|
||||
Migrazione 0011: tabelle routing_rules, routing_rule_conditions, routing_rule_actions
|
||||
(Feature 2 – Regole di smistamento automatico).
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = "0011"
|
||||
down_revision = "0010"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Tabella principale regole
|
||||
op.create_table(
|
||||
"routing_rules",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column(
|
||||
"tenant_id",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("tenants.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("name", sa.String(255), nullable=False),
|
||||
sa.Column("description", sa.Text, nullable=True),
|
||||
sa.Column("is_active", sa.Boolean, nullable=False, server_default="true"),
|
||||
sa.Column("priority", sa.Integer, nullable=False, server_default="100"),
|
||||
sa.Column("stop_processing", sa.Boolean, nullable=False, server_default="true"),
|
||||
sa.Column(
|
||||
"created_by",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("users.id", ondelete="SET NULL"),
|
||||
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(),
|
||||
),
|
||||
)
|
||||
op.create_index("idx_routing_rules_tenant", "routing_rules", ["tenant_id"])
|
||||
op.create_index(
|
||||
"idx_routing_rules_active",
|
||||
"routing_rules",
|
||||
["tenant_id", "priority"],
|
||||
postgresql_where=sa.text("is_active = true"),
|
||||
)
|
||||
|
||||
# Condizioni delle regole
|
||||
op.create_table(
|
||||
"routing_rule_conditions",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column(
|
||||
"rule_id",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("routing_rules.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
# field: from_address | to_address | subject | mailbox_id | pec_type
|
||||
sa.Column("field", sa.String(50), nullable=False),
|
||||
# operator: contains | equals | starts_with | ends_with | regex | not_contains
|
||||
sa.Column("operator", sa.String(30), nullable=False, server_default="contains"),
|
||||
sa.Column("value", sa.Text, nullable=False),
|
||||
)
|
||||
op.create_index(
|
||||
"idx_routing_conditions_rule",
|
||||
"routing_rule_conditions",
|
||||
["rule_id"],
|
||||
)
|
||||
|
||||
# Azioni delle regole
|
||||
op.create_table(
|
||||
"routing_rule_actions",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column(
|
||||
"rule_id",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("routing_rules.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
# action_type: apply_label | assign_vbox | mark_read | mark_starred | notify_webhook
|
||||
sa.Column("action_type", sa.String(50), nullable=False),
|
||||
# action_value: UUID di label/vbox, URL del webhook, ecc.
|
||||
sa.Column("action_value", sa.Text, nullable=True),
|
||||
)
|
||||
op.create_index(
|
||||
"idx_routing_actions_rule",
|
||||
"routing_rule_actions",
|
||||
["rule_id"],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("idx_routing_actions_rule", table_name="routing_rule_actions")
|
||||
op.drop_table("routing_rule_actions")
|
||||
op.drop_index("idx_routing_conditions_rule", table_name="routing_rule_conditions")
|
||||
op.drop_table("routing_rule_conditions")
|
||||
op.drop_index("idx_routing_rules_active", table_name="routing_rules")
|
||||
op.drop_index("idx_routing_rules_tenant", table_name="routing_rules")
|
||||
op.drop_table("routing_rules")
|
||||
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
Migrazione 0012: campi deadline su tabella messages
|
||||
(Feature 4 – Scadenzario e tracking deadlines).
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "0012"
|
||||
down_revision = "0011"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"messages",
|
||||
sa.Column("deadline_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.add_column(
|
||||
"messages",
|
||||
sa.Column("deadline_note", sa.Text, nullable=True),
|
||||
)
|
||||
op.create_index(
|
||||
"idx_messages_deadline",
|
||||
"messages",
|
||||
["tenant_id", "deadline_at"],
|
||||
postgresql_where=sa.text("deadline_at IS NOT NULL"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("idx_messages_deadline", table_name="messages")
|
||||
op.drop_column("messages", "deadline_note")
|
||||
op.drop_column("messages", "deadline_at")
|
||||
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
Migrazione 0013: campo scheduled_at su send_jobs
|
||||
(Feature 5 – Invio differito).
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "0013"
|
||||
down_revision = "0012"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"send_jobs",
|
||||
sa.Column("scheduled_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.create_index(
|
||||
"idx_sendjobs_scheduled",
|
||||
"send_jobs",
|
||||
["scheduled_at"],
|
||||
postgresql_where=sa.text("status = 'pending' AND scheduled_at IS NOT NULL"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("idx_sendjobs_scheduled", table_name="send_jobs")
|
||||
op.drop_column("send_jobs", "scheduled_at")
|
||||
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
Migrazione 0014: tabella pec_contacts (Feature 6 – Rubrica indirizzi PEC).
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision = "0014"
|
||||
down_revision = "0013"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"pec_contacts",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column(
|
||||
"tenant_id",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("tenants.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("email", sa.String(255), nullable=False),
|
||||
sa.Column("name", sa.String(255), nullable=True),
|
||||
sa.Column("organization", sa.String(255), nullable=True),
|
||||
sa.Column("notes", sa.Text, nullable=True),
|
||||
sa.Column("is_favorite", sa.Boolean, nullable=False, server_default="false"),
|
||||
# auto_saved=True: contatto creato automaticamente dal sistema durante la sync
|
||||
# auto_saved=False: contatto aggiunto manualmente dall'utente
|
||||
sa.Column("auto_saved", sa.Boolean, nullable=False, server_default="false"),
|
||||
sa.Column(
|
||||
"created_by",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("users.id", ondelete="SET NULL"),
|
||||
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.UniqueConstraint("tenant_id", "email", name="uq_pec_contact_email_tenant"),
|
||||
)
|
||||
op.create_index("idx_pec_contacts_tenant", "pec_contacts", ["tenant_id"])
|
||||
op.create_index("idx_pec_contacts_email", "pec_contacts", ["tenant_id", "email"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("idx_pec_contacts_email", table_name="pec_contacts")
|
||||
op.drop_index("idx_pec_contacts_tenant", table_name="pec_contacts")
|
||||
op.drop_table("pec_contacts")
|
||||
Reference in New Issue
Block a user