forked from wangziqi/gongxue-base
feat: add pocketbase dry-run report
This commit is contained in:
@@ -87,6 +87,109 @@ async function main() {
|
||||
try {
|
||||
await client.query('begin');
|
||||
|
||||
await client.query(
|
||||
`
|
||||
create temporary table smoke_seed_transient_questions (
|
||||
id uuid primary key
|
||||
) on commit drop
|
||||
`,
|
||||
);
|
||||
|
||||
await client.query(
|
||||
`
|
||||
insert into smoke_seed_transient_questions (id)
|
||||
select distinct q.id
|
||||
from public.questions q
|
||||
left join public.question_collection_items ci
|
||||
on ci.tenant_id = q.tenant_id
|
||||
and ci.question_id = q.id
|
||||
where q.tenant_id = $1
|
||||
and q.id <> all($3::uuid[])
|
||||
and (
|
||||
q.primary_collection_id = $2::uuid
|
||||
or ci.collection_id = $2::uuid
|
||||
or coalesce(q.legacy_id, '') like any($4::text[])
|
||||
)
|
||||
`,
|
||||
[
|
||||
tenantId,
|
||||
ids.questionCollection,
|
||||
[ids.question, ids.questionTwo, ids.questionThree],
|
||||
['integration-import-%', 'worker-import-question-%', 'public-sync-source-%', 'content-import:%'],
|
||||
],
|
||||
);
|
||||
|
||||
await client.query(
|
||||
`
|
||||
delete from public.question_collection_items
|
||||
where tenant_id = $1
|
||||
and (
|
||||
question_id in (select id from smoke_seed_transient_questions)
|
||||
or (
|
||||
collection_id = $2::uuid
|
||||
and question_id <> all($3::uuid[])
|
||||
)
|
||||
)
|
||||
`,
|
||||
[tenantId, ids.questionCollection, [ids.question, ids.questionTwo, ids.questionThree]],
|
||||
);
|
||||
|
||||
await client.query(
|
||||
`
|
||||
delete from public.question_versions
|
||||
where tenant_id = $1
|
||||
and question_id in (select id from smoke_seed_transient_questions)
|
||||
`,
|
||||
[tenantId],
|
||||
);
|
||||
|
||||
await client.query(
|
||||
`
|
||||
delete from public.questions
|
||||
where tenant_id = $1
|
||||
and id in (select id from smoke_seed_transient_questions)
|
||||
`,
|
||||
[tenantId],
|
||||
);
|
||||
|
||||
await client.query(
|
||||
`
|
||||
delete from public.content_export_jobs
|
||||
where tenant_id = $1
|
||||
and scope_id = $2::uuid
|
||||
`,
|
||||
[tenantId, ids.questionCollection],
|
||||
);
|
||||
|
||||
await client.query(
|
||||
`
|
||||
delete from public.content_import_jobs
|
||||
where tenant_id = $1
|
||||
and (
|
||||
source_name = any($2::text[])
|
||||
or source_name like 'worker-import-%'
|
||||
)
|
||||
`,
|
||||
[
|
||||
tenantId,
|
||||
[
|
||||
'large-but-allowed-question-import.json',
|
||||
'invalid-question-import.json',
|
||||
'valid-question-import.json',
|
||||
'questions.csv',
|
||||
'async-question-import.json',
|
||||
'invalid-vocabulary-import.json',
|
||||
'legacy-vocabulary-import.json',
|
||||
'vocabulary.csv',
|
||||
'handbook-nested-import.json',
|
||||
'scoreline-batch-import.json',
|
||||
'scoreline-mixed-items.json',
|
||||
'scoreline.xlsx',
|
||||
'video-batch-import.json',
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
await client.query(
|
||||
`
|
||||
delete from public.report_status_events
|
||||
|
||||
Reference in New Issue
Block a user