feat: add public question bank adoption

This commit is contained in:
Codex
2026-06-29 03:07:57 +08:00
parent c767b87c6f
commit 7c41bf525f
15 changed files with 1324 additions and 16 deletions

View File

@@ -75,6 +75,8 @@ const ids = {
partnerInvoice: '00000000-0000-0000-0000-000000000903',
partnerInvoiceItem: '00000000-0000-0000-0000-000000000904',
partnerInvoicePayment: '00000000-0000-0000-0000-000000000905',
publicQuestionBankGrant: '00000000-0000-0000-0000-000000000906',
partnerTenantAdminUser: '00000000-0000-0000-0000-000000000907',
platformAdminUser: '00000000-0000-0000-0000-000000000999',
};
@@ -504,6 +506,20 @@ async function main() {
[ids.platformAdminUser, ids.authPlatformAdminUser],
);
await client.query(
`
insert into public.platform_users (id, auth_user_id, username, phone, name, primary_role, raw_profile)
values ($1, null, 'smoke_partner_admin', '13800000907', 'Smoke Partner Admin', 'tenant_admin', '{"source":"smoke-seed"}'::jsonb)
on conflict (id)
do update set username = excluded.username,
phone = excluded.phone,
name = excluded.name,
primary_role = excluded.primary_role,
updated_at = now()
`,
[ids.partnerTenantAdminUser],
);
await client.query(
`
insert into public.user_identities (user_id, provider, provider_subject, phone)
@@ -526,6 +542,16 @@ async function main() {
[tenantId, ids.user],
);
await client.query(
`
delete from public.tenant_memberships
where tenant_id = $1
and user_id = $2
and role = 'tenant_admin'
`,
[ids.partnerTenant, ids.tenantAdminUser],
);
await client.query(
`
insert into public.tenant_memberships (tenant_id, user_id, role, status, permissions)
@@ -650,10 +676,13 @@ async function main() {
await client.query(
`
insert into public.question_banks (id, tenant_id, region_id, name, source_scope, status, metadata)
values ($1, $2, $3, '烟测题库', 'tenant', 'active', '{"source":"smoke-seed"}'::jsonb)
values ($1, $2, $3, '烟测公共题库', 'platform', 'active', '{"source":"smoke-seed","commercialScope":"public_region_bank"}'::jsonb)
on conflict (id)
do update set name = excluded.name,
region_id = excluded.region_id,
source_scope = excluded.source_scope,
status = excluded.status,
metadata = excluded.metadata,
updated_at = now()
`,
[ids.questionBank, tenantId, ids.region],
@@ -1784,6 +1813,109 @@ async function main() {
[ids.partnerInvoicePayment, ids.partnerTenant, ids.partnerInvoice],
);
await client.query(
`
insert into public.tenant_memberships (tenant_id, user_id, role, status, permissions)
values ($1, $2, 'tenant_admin', 'active', '{"content:*":true}'::jsonb)
on conflict (tenant_id, user_id, role)
do update set status = 'active',
permissions = excluded.permissions,
updated_at = now()
`,
[ids.partnerTenant, ids.partnerTenantAdminUser],
);
await client.query(
`
insert into public.question_bank_grants (
id, source_question_bank_id, grant_scope, allowed_plan_codes,
allowed_tenant_ids, status, starts_at, expires_at, metadata
)
values (
$1, $2, 'plans', array['starter_yearly','pro_yearly']::text[],
'{}'::uuid[], 'active', '2026-06-21T00:00:00Z', null,
'{"source":"smoke-seed","business":"public_question_bank_authorization"}'::jsonb
)
on conflict (id)
do update set grant_scope = excluded.grant_scope,
allowed_plan_codes = excluded.allowed_plan_codes,
status = excluded.status,
starts_at = excluded.starts_at,
expires_at = excluded.expires_at,
metadata = excluded.metadata,
updated_at = now()
`,
[ids.publicQuestionBankGrant, ids.questionBank],
);
await client.query(
`
delete from public.tenant_question_bank_adoptions
where tenant_id = $1
and source_question_bank_id = $2
`,
[ids.partnerTenant, ids.questionBank],
);
await client.query(
`
delete from public.question_collection_items
where tenant_id = $1
and metadata->>'source' = 'public_question_bank_adoption'
`,
[ids.partnerTenant],
);
await client.query(
`
delete from public.question_versions
where tenant_id = $1
and question_id in (
select id
from public.questions
where tenant_id = $1
and legacy_id like 'public:%'
)
`,
[ids.partnerTenant],
);
await client.query(
`
delete from public.questions
where tenant_id = $1
and legacy_id like 'public:%'
`,
[ids.partnerTenant],
);
await client.query(
`
delete from public.question_collections
where tenant_id = $1
and metadata->>'source' = 'public_question_bank_adoption'
`,
[ids.partnerTenant],
);
await client.query(
`
delete from public.content_entries
where tenant_id = $1
and entry_key like 'public-%'
`,
[ids.partnerTenant],
);
await client.query(
`
delete from public.question_banks
where tenant_id = $1
and metadata->>'source' = 'public_question_bank_adoption'
`,
[ids.partnerTenant],
);
await client.query(
`
delete from public.tenant_usage_records