From 5f57679bb3738c7ffc911a70d5cd2f4f13b0152c Mon Sep 17 00:00:00 2001 From: Grant Date: Mon, 8 Jul 2024 20:43:09 -0600 Subject: [PATCH] add option to print sql instead of committing the changes itself --- packages/server/src/tools/seed_palette.ts | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/server/src/tools/seed_palette.ts b/packages/server/src/tools/seed_palette.ts index 7aa8f37..84fc6fc 100644 --- a/packages/server/src/tools/seed_palette.ts +++ b/packages/server/src/tools/seed_palette.ts @@ -147,16 +147,25 @@ async function main() { }, ]; - for (const { name, hex } of palette) { - log("Ensuring color", { name, hex }); - await prisma.paletteColor.upsert({ - where: { hex }, - update: {}, - create: { - name, - hex, - }, - }); + if (process.argv?.[2] === "sql") { + log(`ALTER SEQUENCE "PaletteColor_id_seq" RESTART WITH 1;`); + for (const { name, hex } of palette) { + log( + `INSERT INTO "PaletteColor" (name, hex) VALUES ('${name}', '${hex}');` + ); + } + } else { + for (const { name, hex } of palette) { + log("Ensuring color", { name, hex }); + await prisma.paletteColor.upsert({ + where: { hex }, + update: {}, + create: { + name, + hex, + }, + }); + } } }