Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Connection string for PostgreSQL.
# Requires PostgreSQL >= 15.

DATABASE_URL="postgresql://neet:neet@localhost:5432/neet"
DATABASE_URL="postgresql://neet:neet@127.0.0.1:5432/neet"
26 changes: 25 additions & 1 deletion src/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ import { db } from "./db.ts";
async function main() {
console.log("Seeding database... 🌱");

// Forcefully wipe ALL tables intelligently using a dynamic Postgres query!
// This automatically finds all your tables (even if you add new ones later)
// and TRUNCATES them, while ignoring Prisma's internal state tables.
const wipePlan = db.raw.sql`
DO $$
DECLARE
r RECORD;
BEGIN
FOR r IN (
SELECT tablename
FROM pg_tables
WHERE schemaname = 'public'
AND tablename NOT LIKE 'prisma_%'
AND tablename != '_prisma_migrations'
) LOOP
EXECUTE 'TRUNCATE TABLE ' || quote_ident(r.tablename) || ' CASCADE';
END LOOP;
END $$;
`
.affectedCount()
.build();

await db.runtime().execute(wipePlan);
console.log("Database wiped perfectly! 🧹");

// Create some users
const alice = await db.orm.public.User.create({
name: "Alice Silva",
Expand All @@ -29,7 +54,6 @@ async function main() {
});

// Add availability for Alice (she is free today 14:00 - 15:30)
// We use ZonedDateTime to get an accurate Instant for Lisbon time
const aliceStart = today
.toZonedDateTime({ timeZone: "Europe/Lisbon", plainTime: "14:00" })
.toInstant();
Expand Down
Loading