Skip to content

Commit

Permalink
better seeding
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitoTGT committed May 19, 2024
1 parent 7ff87d8 commit 1387af9
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions src/lib/drizzle/seed.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
import "dotenv/config";

import { db, image } from "@/lib/drizzle/db";
import { execSync } from "child_process";
import { db, image as imageSchema } from "@/lib/drizzle/db";

(async () => {
const insertion = await db
.insert(image)
.values([
{
dockerImage: "ghcr.io/spaceness/debian",
friendlyName: "Debian",
category: ["Desktop"],
icon: "/images/workspaces/debian.svg",
},
{
dockerImage: "ghcr.io/spaceness/chromium",
friendlyName: "Chromium",
category: ["Browser"],
icon: "/images/workspaces/chromium.svg",
},
])
.onConflictDoNothing()
.returning();
console.log(insertion);
console.log("✨ Stardust: Seeded image");
process.exit();
const images = [
{
dockerImage: "ghcr.io/spaceness/debian",
friendlyName: "Debian",
category: ["Desktop"],
icon: "/images/workspaces/debian.svg",
},
{
dockerImage: "ghcr.io/spaceness/chromium",
friendlyName: "Chromium",
category: ["Browser"],
icon: "/images/workspaces/chromium.svg",
},
{
dockerImage: "ghcr.io/spaceness/firefox",
friendlyName: "Firefox",
category: ["Browser"],
icon: "/images/workspaces/firefox.svg",
},
{
dockerImage: "ghcr.io/spaceness/gimp",
friendlyName: "GIMP",
category: ["Photo Editing"],
icon: "https://www.gimp.org/images/frontpage/wilber-big.png",
},
]
const insertion = await db.insert(imageSchema).values(images).onConflictDoNothing().returning()
console.log(`✨Stardust: Seeded ${insertion.length} images.`)
console.log(`✨Stardust: Seeded ${insertion.map((i) => i.dockerImage).join(", ")}`)
if (process.argv.includes("--pull") {
console.log("Pulling images...")
for (const image of images) {
execSync(`docker pull ${image.dockerImage}`)
}
}
process.exit();
})();

0 comments on commit 1387af9

Please sign in to comment.