July 4 - Update Vendor Work-Order Workflow

This commit is contained in:
2026-07-04 16:25:31 -04:00
parent 03ce083691
commit 8f971a403b
12 changed files with 718 additions and 6 deletions
@@ -0,0 +1,61 @@
"""phase36 — vendor work orders
Creates the issue_work_orders table backing the vendor work-order workflow
(see §5 model + the work_orders blueprint). A work order dispatches an issue to
an external contractor via a tokenized public link; the contractor acknowledges
and completes it without an account.
Idempotent: guarded by an INFORMATION_SCHEMA table-existence check so it is safe
to re-run across every tenant DB (CLAUDE.md rule 14).
"""
import sqlalchemy as sa
from alembic import op
revision = 'phase36_issue_work_orders'
down_revision = 'phase35_user_mfa'
branch_labels = None
depends_on = None
def _table_exists(bind, table: str) -> bool:
result = bind.execute(sa.text(
"SELECT COUNT(*) FROM information_schema.tables "
"WHERE table_schema = DATABASE() AND table_name = :t"
), {'t': table})
return result.scalar() > 0
def upgrade():
bind = op.get_bind()
if not _table_exists(bind, 'issue_work_orders'):
op.execute(sa.text("""
CREATE TABLE issue_work_orders (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
issue_id INT NOT NULL,
vendor_name VARCHAR(150) NOT NULL,
vendor_email VARCHAR(255) NOT NULL,
token VARCHAR(64) NOT NULL,
status ENUM('sent','acknowledged','completed')
NOT NULL DEFAULT 'sent',
message TEXT NULL,
vendor_note TEXT NULL,
sent_at DATETIME NOT NULL,
acknowledged_at DATETIME NULL,
completed_at DATETIME NULL,
created_by INT NULL,
created_at DATETIME NOT NULL,
CONSTRAINT fk_wo_issue FOREIGN KEY (issue_id)
REFERENCES issues(id) ON DELETE CASCADE,
CONSTRAINT fk_wo_creator FOREIGN KEY (created_by)
REFERENCES users(id) ON DELETE SET NULL,
UNIQUE KEY uq_wo_token (token),
INDEX ix_wo_issue (issue_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
"""))
def downgrade():
bind = op.get_bind()
if _table_exists(bind, 'issue_work_orders'):
op.execute(sa.text('DROP TABLE issue_work_orders'))