feat(new): enforce social publishing governance
Amp-Thread-ID: https://ampcode.com/threads/T-019e55df-9bcd-73e6-9935-c1e6238cd273 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
1 parent
8a1389bcbc
commit
6d99f515c7
10 files changed
+643
-141
No files matched your search
@@ -0,0 +1,49 @@
|
||||
export const socialGovernanceSchema = `
|
||||
update social_account_grants
|
||||
set scope_json = '{"actions":["login","draft","approve"],"riskCeiling":"medium"}'
|
||||
where scope_json = '{"actions":["login","draft","approve"]}';
|
||||
|
||||
create temp table if not exists social_post_approval_backfill(
|
||||
post_id text primary key,
|
||||
approval_id text not null
|
||||
);
|
||||
|
||||
delete from social_post_approval_backfill;
|
||||
|
||||
insert into social_post_approval_backfill(post_id, approval_id)
|
||||
select id, 'app_' || lower(hex(randomblob(16)))
|
||||
from scheduled_posts
|
||||
where state = 'scheduled' and approval_id is null;
|
||||
|
||||
insert into approvals(
|
||||
id, org_id, kind, title, details, risk, requested_by_type, requested_by_id,
|
||||
state, decided_by_employee_id, created_at, decided_at
|
||||
)
|
||||
select
|
||||
backfill.approval_id,
|
||||
posts.org_id,
|
||||
'social_publish',
|
||||
'Approve social post',
|
||||
posts.body_md,
|
||||
'medium',
|
||||
case when posts.created_by_employee_id is null then 'system' else 'employee' end,
|
||||
posts.created_by_employee_id,
|
||||
'pending',
|
||||
null,
|
||||
posts.created_at,
|
||||
null
|
||||
from scheduled_posts posts
|
||||
join social_post_approval_backfill backfill on backfill.post_id = posts.id;
|
||||
|
||||
update scheduled_posts
|
||||
set approval_id = (
|
||||
select approval_id from social_post_approval_backfill
|
||||
where social_post_approval_backfill.post_id = scheduled_posts.id
|
||||
)
|
||||
where id in (select post_id from social_post_approval_backfill);
|
||||
|
||||
drop table social_post_approval_backfill;
|
||||
|
||||
insert into schema_migrations(version, name, applied_at)
|
||||
values (9, 'social_governance', datetime('now'));
|
||||
`;
|
||||
@@ -7,6 +7,7 @@ import { chatReadState } from "./migrations/005-chat-read-state";
|
||||
import { appStateSchema } from "./migrations/006-app-state";
|
||||
import { skillHardeningSchema } from "./migrations/007-skill-hardening";
|
||||
import { providerHealthSchema } from "./migrations/008-provider-health";
|
||||
import { socialGovernanceSchema } from "./migrations/009-social-governance";
|
||||
|
||||
const MIGRATIONS: Array<{ version: number; sql: string }> = [
|
||||
{ version: 1, sql: initialEnterpriseSchema },
|
||||
@@ -17,6 +18,7 @@ const MIGRATIONS: Array<{ version: number; sql: string }> = [
|
||||
{ version: 6, sql: appStateSchema },
|
||||
{ version: 7, sql: skillHardeningSchema },
|
||||
{ version: 8, sql: providerHealthSchema },
|
||||
{ version: 9, sql: socialGovernanceSchema },
|
||||
];
|
||||
|
||||
const SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1].version;
|
||||
|
||||
Reference in new issue
Block a user