This commit is contained in:
phaichayon
2026-07-15 05:46:59 +07:00
parent b51bf3e02a
commit df1821982d
10 changed files with 932 additions and 1346 deletions

View File

@@ -311,6 +311,7 @@ async function main() {
matchingVersion,
});
const targetVersionId = matchingVersion?.id ?? randomUUID();
const isProductVariant = options.variant === 'product-v1';
await sql.begin(async (tx) => {
if (!matchingVersion) {
@@ -322,6 +323,7 @@ async function main() {
version,
file_path,
schema_json,
metadata_json,
preview_image_url,
is_active,
deleted_at,
@@ -333,6 +335,10 @@ async function main() {
${targetVersionLabel},
${templateSource.relativePath},
${JSON.stringify(targetSchema)},
case
when ${isProductVariant} then jsonb_build_object('templateVariant', 'product-v1')
else null
end,
${null},
${options.activate},
${null},
@@ -344,6 +350,11 @@ async function main() {
update crm_document_template_versions
set
file_path = ${templateSource.relativePath},
metadata_json = case
when ${isProductVariant}
then coalesce(metadata_json, '{}'::jsonb) || jsonb_build_object('templateVariant', 'product-v1')
else metadata_json
end,
is_active = ${options.activate ? true : matchingVersion.isActive},
updated_at = now()
where id = ${targetVersionId}