feat: simplify SOP to immediate-effect configuration
This commit is contained in:
1
migrations/000003_multitable_outbox.down.sql
Normal file
1
migrations/000003_multitable_outbox.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS multitable_outbox;
|
||||
23
migrations/000003_multitable_outbox.up.sql
Normal file
23
migrations/000003_multitable_outbox.up.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
CREATE TABLE multitable_outbox (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
audit_log_id BIGINT UNSIGNED NULL,
|
||||
resource VARCHAR(64) NOT NULL,
|
||||
resource_id BIGINT UNSIGNED NOT NULL,
|
||||
action VARCHAR(64) NOT NULL,
|
||||
payload JSON NOT NULL,
|
||||
dedupe_key VARCHAR(191) NOT NULL,
|
||||
status VARCHAR(24) NOT NULL DEFAULT 'pending',
|
||||
attempts INT NOT NULL DEFAULT 0,
|
||||
available_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
last_error TEXT NOT NULL,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_multitable_outbox_audit (audit_log_id),
|
||||
UNIQUE KEY uk_multitable_outbox_dedupe (dedupe_key),
|
||||
KEY idx_multitable_outbox_pending (status, available_at),
|
||||
KEY idx_multitable_outbox_resource (tenant_id, resource, resource_id),
|
||||
CONSTRAINT fk_multitable_outbox_tenant FOREIGN KEY (tenant_id) REFERENCES tenants(id),
|
||||
CONSTRAINT fk_multitable_outbox_audit FOREIGN KEY (audit_log_id) REFERENCES audit_logs(id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
1
migrations/000004_remove_review_workflow.down.sql
Normal file
1
migrations/000004_remove_review_workflow.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
-- The review workflow is intentionally not restored by rollback.
|
||||
15
migrations/000004_remove_review_workflow.up.sql
Normal file
15
migrations/000004_remove_review_workflow.up.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
UPDATE sop_versions
|
||||
SET status = 'draft', reviewed_by = NULL
|
||||
WHERE status = 'reviewing';
|
||||
|
||||
UPDATE sops
|
||||
SET status = CASE
|
||||
WHEN EXISTS (
|
||||
SELECT 1
|
||||
FROM sop_versions
|
||||
WHERE sop_versions.sop_id = sops.id
|
||||
AND sop_versions.status = 'published'
|
||||
) THEN 'published'
|
||||
ELSE 'draft'
|
||||
END
|
||||
WHERE status = 'reviewing';
|
||||
4
migrations/000005_generic_scenario_runtime.down.sql
Normal file
4
migrations/000005_generic_scenario_runtime.down.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE sop_runs DROP INDEX uk_sop_runs_external_ref;
|
||||
ALTER TABLE sop_runs DROP COLUMN outputs, DROP COLUMN derived, DROP COLUMN input, DROP COLUMN external_ref;
|
||||
ALTER TABLE scenario_fields DROP COLUMN source_path;
|
||||
ALTER TABLE scenarios DROP COLUMN output_schema, DROP COLUMN input_schema;
|
||||
20
migrations/000005_generic_scenario_runtime.up.sql
Normal file
20
migrations/000005_generic_scenario_runtime.up.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
ALTER TABLE scenarios
|
||||
ADD COLUMN input_schema JSON NULL AFTER created_by,
|
||||
ADD COLUMN output_schema JSON NULL AFTER input_schema;
|
||||
|
||||
UPDATE scenarios SET input_schema = JSON_OBJECT('fields', JSON_ARRAY()), output_schema = JSON_OBJECT('fields', JSON_ARRAY());
|
||||
ALTER TABLE scenarios MODIFY input_schema JSON NOT NULL, MODIFY output_schema JSON NOT NULL;
|
||||
|
||||
ALTER TABLE scenario_fields
|
||||
ADD COLUMN source_path VARCHAR(255) NOT NULL DEFAULT '' AFTER field_name;
|
||||
|
||||
ALTER TABLE sop_runs
|
||||
ADD COLUMN external_ref VARCHAR(191) NULL AFTER operator_id,
|
||||
ADD COLUMN input JSON NULL AFTER answers,
|
||||
ADD COLUMN derived JSON NULL AFTER input,
|
||||
ADD COLUMN outputs JSON NULL AFTER derived;
|
||||
|
||||
UPDATE sop_runs SET input = answers, derived = JSON_OBJECT(), outputs = JSON_ARRAY();
|
||||
ALTER TABLE sop_runs MODIFY input JSON NOT NULL, MODIFY derived JSON NOT NULL, MODIFY outputs JSON NOT NULL;
|
||||
|
||||
ALTER TABLE sop_runs ADD UNIQUE KEY uk_sop_runs_external_ref (tenant_id, sop_id, external_ref);
|
||||
2
migrations/000006_knowledge_graph.down.sql
Normal file
2
migrations/000006_knowledge_graph.down.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
DROP TABLE IF EXISTS knowledge_relations;
|
||||
DROP TABLE IF EXISTS knowledge_items;
|
||||
38
migrations/000006_knowledge_graph.up.sql
Normal file
38
migrations/000006_knowledge_graph.up.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
CREATE TABLE knowledge_items (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
scenario_id BIGINT UNSIGNED NOT NULL,
|
||||
item_key VARCHAR(64) NOT NULL,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
type VARCHAR(64) NOT NULL,
|
||||
content JSON NOT NULL,
|
||||
status VARCHAR(24) NOT NULL DEFAULT 'active',
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_knowledge_items_key (scenario_id, item_key),
|
||||
KEY idx_knowledge_items_type (tenant_id, scenario_id, type, status),
|
||||
CONSTRAINT fk_knowledge_items_tenant FOREIGN KEY (tenant_id) REFERENCES tenants(id),
|
||||
CONSTRAINT fk_knowledge_items_scenario FOREIGN KEY (scenario_id) REFERENCES scenarios(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE knowledge_relations (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
scenario_id BIGINT UNSIGNED NOT NULL,
|
||||
from_knowledge_id BIGINT UNSIGNED NOT NULL,
|
||||
relation_type VARCHAR(64) NOT NULL,
|
||||
to_knowledge_id BIGINT UNSIGNED NOT NULL,
|
||||
`condition` JSON NOT NULL,
|
||||
sort_order INT NOT NULL DEFAULT 0,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_knowledge_relation (scenario_id, from_knowledge_id, relation_type, to_knowledge_id),
|
||||
KEY idx_knowledge_relation_from (tenant_id, scenario_id, from_knowledge_id, relation_type),
|
||||
CONSTRAINT fk_knowledge_relations_tenant FOREIGN KEY (tenant_id) REFERENCES tenants(id),
|
||||
CONSTRAINT fk_knowledge_relations_scenario FOREIGN KEY (scenario_id) REFERENCES scenarios(id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_knowledge_relations_from FOREIGN KEY (from_knowledge_id) REFERENCES knowledge_items(id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_knowledge_relations_to FOREIGN KEY (to_knowledge_id) REFERENCES knowledge_items(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
3
migrations/000007_public_sdk_access.down.sql
Normal file
3
migrations/000007_public_sdk_access.down.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
DROP TABLE IF EXISTS public_run_sessions;
|
||||
ALTER TABLE scenarios DROP INDEX uk_scenarios_public_key, DROP INDEX uk_scenarios_scenario_key;
|
||||
ALTER TABLE scenarios DROP COLUMN allowed_origins, DROP COLUMN public_key, DROP COLUMN scenario_key;
|
||||
31
migrations/000007_public_sdk_access.up.sql
Normal file
31
migrations/000007_public_sdk_access.up.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
ALTER TABLE scenarios
|
||||
ADD COLUMN scenario_key VARCHAR(128) NULL AFTER tenant_id,
|
||||
ADD COLUMN public_key VARCHAR(128) NULL AFTER scenario_key,
|
||||
ADD COLUMN allowed_origins JSON NULL AFTER public_key;
|
||||
|
||||
UPDATE scenarios
|
||||
SET scenario_key = CONCAT('scenario-', id),
|
||||
public_key = CONCAT('pk_', REPLACE(UUID(), '-', '')),
|
||||
allowed_origins = JSON_ARRAY();
|
||||
|
||||
ALTER TABLE scenarios
|
||||
MODIFY scenario_key VARCHAR(128) NOT NULL,
|
||||
MODIFY public_key VARCHAR(128) NOT NULL,
|
||||
MODIFY allowed_origins JSON NOT NULL,
|
||||
ADD UNIQUE KEY uk_scenarios_scenario_key (scenario_key),
|
||||
ADD UNIQUE KEY uk_scenarios_public_key (public_key);
|
||||
|
||||
CREATE TABLE public_run_sessions (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
run_id BIGINT UNSIGNED NOT NULL,
|
||||
token_hash VARCHAR(64) NOT NULL,
|
||||
expires_at DATETIME(3) NOT NULL,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_public_run_sessions_token (token_hash),
|
||||
KEY idx_public_run_sessions_run (tenant_id, run_id),
|
||||
CONSTRAINT fk_public_sessions_tenant FOREIGN KEY (tenant_id) REFERENCES tenants(id),
|
||||
CONSTRAINT fk_public_sessions_run FOREIGN KEY (run_id) REFERENCES sop_runs(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
1
migrations/000008_scenario_rules.down.sql
Normal file
1
migrations/000008_scenario_rules.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS scenario_rules;
|
||||
18
migrations/000008_scenario_rules.up.sql
Normal file
18
migrations/000008_scenario_rules.up.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE scenario_rules (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
scenario_id BIGINT UNSIGNED NOT NULL,
|
||||
rule_key VARCHAR(64) NOT NULL,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
`condition` JSON NOT NULL,
|
||||
actions JSON NOT NULL,
|
||||
priority INT NOT NULL DEFAULT 0,
|
||||
status VARCHAR(24) NOT NULL DEFAULT 'active',
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_scenario_rules_key (scenario_id, rule_key),
|
||||
KEY idx_scenario_rules_active (tenant_id, scenario_id, status, priority),
|
||||
CONSTRAINT fk_scenario_rules_tenant FOREIGN KEY (tenant_id) REFERENCES tenants(id),
|
||||
CONSTRAINT fk_scenario_rules_scenario FOREIGN KEY (scenario_id) REFERENCES scenarios(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
1
migrations/000009_run_knowledge_snapshot.down.sql
Normal file
1
migrations/000009_run_knowledge_snapshot.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE sop_runs DROP COLUMN knowledge_snapshot;
|
||||
3
migrations/000009_run_knowledge_snapshot.up.sql
Normal file
3
migrations/000009_run_knowledge_snapshot.up.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE sop_runs ADD COLUMN knowledge_snapshot JSON NULL AFTER outputs;
|
||||
UPDATE sop_runs SET knowledge_snapshot = JSON_OBJECT('items', JSON_ARRAY(), 'relations', JSON_ARRAY());
|
||||
ALTER TABLE sop_runs MODIFY knowledge_snapshot JSON NOT NULL;
|
||||
2
migrations/000010_scenario_final_result.down.sql
Normal file
2
migrations/000010_scenario_final_result.down.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE sop_runs DROP COLUMN final_result;
|
||||
ALTER TABLE scenarios DROP COLUMN result_schema;
|
||||
8
migrations/000010_scenario_final_result.up.sql
Normal file
8
migrations/000010_scenario_final_result.up.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE scenarios
|
||||
ADD COLUMN result_schema JSON NULL AFTER output_schema;
|
||||
|
||||
UPDATE scenarios SET result_schema = JSON_OBJECT('fields', JSON_ARRAY());
|
||||
ALTER TABLE scenarios MODIFY result_schema JSON NOT NULL;
|
||||
|
||||
ALTER TABLE sop_runs
|
||||
ADD COLUMN final_result JSON NULL AFTER result;
|
||||
Reference in New Issue
Block a user