fix: merge main branch and renumber migration 037→040
Resolve all merge conflicts between our automation feature branch and current main (v0.163.0, 920 commits ahead). Conflicts resolved: - app/api/__init__.py: add automation_router alongside main's new routers (classification_rules, qr_auth, sessions, system_reset) - app/config.py: add main's new settings (dropbox_use_global_credentials, factory_reset_on_startup, enable_factory_reset) - app/models.py: add main's new models (ClassificationRuleModel, UserSession, QRLoginChallenge, SharePoint integration type) - app/utils/settings_service.py: merge automation_hooks_enabled with main's new metadata entries - docs/API.md: merge automation API docs with main's classification rules docs - docs/ConfigurationGuide.md: add factory reset settings - tests/conftest.py: import both AutomationHook and new main models Migration renumbered: - 037_add_automation_hooks → 040_add_automation_hooks - down_revision: 039_add_classification_rules (was 036_add_document_translation_fields) - Chain: 036 → 037 → 038 → 039 → 040 (automation hooks) For all non-automation files with conflicts, main's version was taken since our branch did not modify those files (conflicts were from a stale prior merge). Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> Agent-Logs-Url: https://github.com/christianlouis/DocuElevate/sessions/cb62f012-3b69-4415-835e-3857ce3e9f45
This commit is contained in:
@@ -24,6 +24,7 @@ from app.models import ( # noqa: F401
|
||||
ApplicationSettings,
|
||||
AuditLog,
|
||||
BackupRecord,
|
||||
ClassificationRuleModel,
|
||||
ComplianceTemplate,
|
||||
DocumentMetadata,
|
||||
FileProcessingStep,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
|
||||
from typing import Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = ${repr(up_revision)}
|
||||
down_revision: Union[str, None] = ${repr(down_revision)}
|
||||
depends_on: Union[str, None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""${message}."""
|
||||
# Use ``op.batch_alter_table()`` for SQLite compatibility.
|
||||
# Always check whether the table/column already exists before altering
|
||||
# to keep migrations idempotent (safe to re-run).
|
||||
#
|
||||
# Example – add a column only if it is missing:
|
||||
#
|
||||
# conn = op.get_bind()
|
||||
# inspector = sa.inspect(conn)
|
||||
# if "my_table" in inspector.get_table_names():
|
||||
# existing = {c["name"] for c in inspector.get_columns("my_table")}
|
||||
# if "new_col" not in existing:
|
||||
# with op.batch_alter_table("my_table") as batch_op:
|
||||
# batch_op.add_column(sa.Column("new_col", sa.String(128), nullable=True))
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Reverse ${message}."""
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,72 @@
|
||||
"""Add user_sessions and qr_login_challenges tables.
|
||||
|
||||
Adds server-side session tracking (user_sessions) for the "log off
|
||||
everywhere" feature and per-session revocation, and QR login challenges
|
||||
(qr_login_challenges) for secure mobile app authentication via QR code.
|
||||
|
||||
Revision ID: 037_add_user_sessions_and_qr_challenges
|
||||
Revises: 036_add_document_translation_fields
|
||||
Create Date: 2026-03-16
|
||||
"""
|
||||
|
||||
from typing import Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "037_add_user_sessions_and_qr_challenges"
|
||||
down_revision: Union[str, None] = "036_add_document_translation_fields"
|
||||
depends_on: Union[str, None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Create user_sessions and qr_login_challenges tables."""
|
||||
conn = op.get_bind()
|
||||
inspector = sa.inspect(conn)
|
||||
existing_tables = set(inspector.get_table_names())
|
||||
|
||||
if "user_sessions" not in existing_tables:
|
||||
op.create_table(
|
||||
"user_sessions",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("session_token", sa.String(128), nullable=False, unique=True, index=True),
|
||||
sa.Column("user_id", sa.String(), nullable=False, index=True),
|
||||
sa.Column("ip_address", sa.String(45), nullable=True),
|
||||
sa.Column("user_agent", sa.String(512), nullable=True),
|
||||
sa.Column("device_info", sa.String(255), nullable=True),
|
||||
sa.Column("is_revoked", sa.Boolean(), nullable=False, server_default="0"),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
sa.Column("last_active_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("revoked_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
|
||||
if "qr_login_challenges" not in existing_tables:
|
||||
op.create_table(
|
||||
"qr_login_challenges",
|
||||
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
||||
sa.Column("challenge_token", sa.String(128), nullable=False, unique=True, index=True),
|
||||
sa.Column("user_id", sa.String(), nullable=False, index=True),
|
||||
sa.Column("is_claimed", sa.Boolean(), nullable=False, server_default="0"),
|
||||
sa.Column("is_cancelled", sa.Boolean(), nullable=False, server_default="0"),
|
||||
sa.Column("created_by_ip", sa.String(45), nullable=True),
|
||||
sa.Column("claimed_by_ip", sa.String(45), nullable=True),
|
||||
sa.Column("device_name", sa.String(255), nullable=True),
|
||||
sa.Column("issued_token_id", sa.Integer(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("claimed_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Drop user_sessions and qr_login_challenges tables."""
|
||||
conn = op.get_bind()
|
||||
inspector = sa.inspect(conn)
|
||||
existing_tables = set(inspector.get_table_names())
|
||||
|
||||
if "qr_login_challenges" in existing_tables:
|
||||
op.drop_table("qr_login_challenges")
|
||||
|
||||
if "user_sessions" in existing_tables:
|
||||
op.drop_table("user_sessions")
|
||||
@@ -0,0 +1,43 @@
|
||||
"""Add expires_at column to api_tokens table.
|
||||
|
||||
Allows API tokens to be issued with an optional lifetime. If ``expires_at``
|
||||
is set, the token is automatically rejected after that timestamp.
|
||||
|
||||
Revision ID: 038_add_api_token_expires_at
|
||||
Revises: 037_add_user_sessions_and_qr_challenges
|
||||
Create Date: 2026-03-18
|
||||
"""
|
||||
|
||||
from typing import Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "038_add_api_token_expires_at"
|
||||
down_revision: Union[str, None] = "037_add_user_sessions_and_qr_challenges"
|
||||
depends_on: Union[str, None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Add expires_at column to api_tokens (idempotent)."""
|
||||
conn = op.get_bind()
|
||||
inspector = sa.inspect(conn)
|
||||
if "api_tokens" not in inspector.get_table_names():
|
||||
return
|
||||
existing_columns = {col["name"] for col in inspector.get_columns("api_tokens")}
|
||||
if "expires_at" not in existing_columns:
|
||||
op.add_column(
|
||||
"api_tokens",
|
||||
sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Remove expires_at column from api_tokens."""
|
||||
conn = op.get_bind()
|
||||
inspector = sa.inspect(conn)
|
||||
if "api_tokens" not in inspector.get_table_names():
|
||||
return
|
||||
existing_columns = {col["name"] for col in inspector.get_columns("api_tokens")}
|
||||
if "expires_at" in existing_columns:
|
||||
op.drop_column("api_tokens", "expires_at")
|
||||
@@ -0,0 +1,46 @@
|
||||
"""Add classification_rules table for custom document classification rules.
|
||||
|
||||
Revision ID: 039_add_classification_rules
|
||||
Revises: 038_add_api_token_expires_at
|
||||
Create Date: 2026-03-17
|
||||
"""
|
||||
|
||||
from typing import Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "039_add_classification_rules"
|
||||
down_revision: Union[str, None] = "038_add_api_token_expires_at"
|
||||
depends_on: Union[str, None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Create classification_rules table."""
|
||||
op.create_table(
|
||||
"classification_rules",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("owner_id", sa.String(), nullable=True),
|
||||
sa.Column("name", sa.String(255), nullable=False),
|
||||
sa.Column("category", sa.String(100), nullable=False),
|
||||
sa.Column("rule_type", sa.String(50), nullable=False),
|
||||
sa.Column("pattern", sa.String(1000), nullable=False),
|
||||
sa.Column("priority", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("case_sensitive", sa.Boolean(), nullable=False, server_default="0"),
|
||||
sa.Column("enabled", sa.Boolean(), nullable=False, server_default="1"),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now()),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("owner_id", "name", name="uq_classification_rules_owner_name"),
|
||||
)
|
||||
op.create_index("ix_classification_rules_id", "classification_rules", ["id"])
|
||||
op.create_index("ix_classification_rules_owner_id", "classification_rules", ["owner_id"])
|
||||
op.create_index("ix_classification_rules_category", "classification_rules", ["category"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Drop classification_rules table."""
|
||||
op.drop_index("ix_classification_rules_category", "classification_rules")
|
||||
op.drop_index("ix_classification_rules_owner_id", "classification_rules")
|
||||
op.drop_index("ix_classification_rules_id", "classification_rules")
|
||||
op.drop_table("classification_rules")
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
"""Add automation_hooks table for Zapier / Make.com webhook subscriptions.
|
||||
|
||||
Revision ID: 037_add_automation_hooks
|
||||
Revises: 036_add_document_translation_fields
|
||||
Revision ID: 040_add_automation_hooks
|
||||
Revises: 039_add_classification_rules
|
||||
Create Date: 2026-03-09
|
||||
"""
|
||||
|
||||
@@ -10,8 +10,8 @@ from typing import Union
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "037_add_automation_hooks"
|
||||
down_revision: Union[str, None] = "036_add_document_translation_fields"
|
||||
revision: str = "040_add_automation_hooks"
|
||||
down_revision: Union[str, None] = "039_add_classification_rules"
|
||||
depends_on: Union[str, None] = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user