bmc_hub/migrations/1045_vtiger_case_hub_imports.sql

16 lines
812 B
MySQL
Raw Permalink Normal View History

-- Track individual Cases copied from vTiger into native Hub cases.
-- Unique source IDs make retries safe; this does not modify existing records.
CREATE TABLE IF NOT EXISTS vtiger_case_hub_imports (
vtiger_case_id VARCHAR(80) PRIMARY KEY,
ticket_number VARCHAR(80) NOT NULL,
hub_sag_id INTEGER NOT NULL UNIQUE REFERENCES sag_sager(id) ON DELETE RESTRICT,
hub_customer_id INTEGER NOT NULL REFERENCES customers(id) ON DELETE RESTRICT,
imported_by_user_id INTEGER REFERENCES users(user_id) ON DELETE SET NULL,
imported_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
vtiger_marked_at TIMESTAMP,
source_snapshot JSONB NOT NULL DEFAULT '{}'::jsonb
);
CREATE INDEX IF NOT EXISTS idx_vtiger_case_hub_imports_customer
ON vtiger_case_hub_imports(hub_customer_id, imported_at DESC);