Gate task execution on approval source refs

This commit is contained in:
ZacharyZhang-NY committed 2026-05-23 21:52:52 -04:00
1 parent 4dbd8997c0
commit c59be97b79
12 files changed
+183 -16

No files matched your search

@@ -0,0 +1,49 @@
export const approvalSourceRefsSchema = `
alter table approvals add column source_entity_type text;
alter table approvals add column source_entity_id text;
update approvals
set
source_entity_type = 'task',
source_entity_id = (
select tasks.id
from tasks
where tasks.org_id = approvals.org_id
and tasks.title = approvals.title
and tasks.description = approvals.details
order by tasks.created_at desc
limit 1
)
where kind = 'task_risk'
and source_entity_id is null
and exists (
select 1
from tasks
where tasks.org_id = approvals.org_id
and tasks.title = approvals.title
and tasks.description = approvals.details
);
update approvals
set
source_entity_type = 'scheduled_post',
source_entity_id = (
select scheduled_posts.id
from scheduled_posts
where scheduled_posts.approval_id = approvals.id
limit 1
)
where kind = 'social_publish'
and source_entity_id is null
and exists (
select 1
from scheduled_posts
where scheduled_posts.approval_id = approvals.id
);
create index if not exists idx_approvals_source
on approvals(org_id, source_entity_type, source_entity_id, kind, state);
insert into schema_migrations(version, name, applied_at)
values (30, 'approval_source_refs', datetime('now'));
`;
@@ -28,6 +28,7 @@ import { browserPlatformGovernanceSchema } from "./migrations/026-browser-platfo
import { socialAuditRecordsSchema } from "./migrations/027-social-audit-records";
import { migrationCutoverJournalSchema } from "./migrations/028-migration-cutover-journal";
import { fileHandoffRecordsSchema } from "./migrations/029-file-handoff-records";
import { approvalSourceRefsSchema } from "./migrations/030-approval-source-refs";
interface Migration {
version: number;
@@ -65,6 +66,7 @@ const MIGRATIONS: Migration[] = [
{ version: 27, name: "social_audit_records", sql: socialAuditRecordsSchema },
{ version: 28, name: "migration_cutover_journal", sql: migrationCutoverJournalSchema },
{ version: 29, name: "file_handoff_records", sql: fileHandoffRecordsSchema },
{ version: 30, name: "approval_source_refs", sql: approvalSourceRefsSchema },
];
const SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1].version;