Skip to content
Open
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The database URL is `postgresql://forum:forum_password@localhost:5434/the_forum`
Optionally fill the database with realistic demo data:

```bash
cd apps/database && bun run db:seed
bun run db:seed
```

### 4. Run the app
Expand Down Expand Up @@ -124,6 +124,7 @@ bun run build # build all packages
bun run db:up # start Postgres db:down stop it (data persists)
bun run db:push # push schema (dev) db:generate generate SQL migrations
bun run db:migrate # apply migrations db:studio visual DB browser
bun run db:seed # seed demo data (safe to re-run any time)
```

Pre-commit hooks (Husky + lint-staged) automatically run Biome on staged files —
Expand Down Expand Up @@ -186,4 +187,4 @@ Re-run `bun install` from the repo root (the `prepare` script reinstalls hooks).
Expected unless you've run `uv sync` in `backends/fastapi` and `uv` is on your PATH.

**Wipe the database and start fresh**
`docker compose down -v` (deletes the data volume), then `bun run db:up && bun run db:push`.
`docker compose down -v` (deletes the data volume), then `bun run db:up && bun run db:push && bun run db:seed`.
3 changes: 1 addition & 2 deletions apps/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"db:seed": "tsx src/seed.ts",
"db:seed": "bun run src/seed.ts",
"lint": "biome check .",
"check-types": "tsc --noEmit"
},
Expand All @@ -21,7 +21,6 @@
"devDependencies": {
"@types/node": "^22.13.4",
"drizzle-kit": "^0.31.10",
"tsx": "^4.21.0",
"typescript": "^5.7.3"
}
}
29 changes: 21 additions & 8 deletions apps/database/src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Run: bun run db:seed (from apps/database)
*/

import { eq } from "drizzle-orm";
import { db } from "./db";
import {
events,
Expand Down Expand Up @@ -755,16 +756,30 @@ async function seed() {
},
];

// Events have no unique constraint on title, so skip ones that already
// exist to keep re-runs of the seed from inserting duplicates.
const existingTitles = new Set(
(await db.select({ title: events.title }).from(events)).map((e) => e.title),
// Events have no unique constraint on title, so re-runs match on title. Events
// that already exist get their datetime/endDatetime refreshed (so the seed
// stays future-facing no matter how long ago it was first run); new titles
// get a full insert + tags.
const existingEventsByTitle = new Map(
(await db.select({ id: events.id, title: events.title }).from(events)).map((e) => [
e.title,
e.id,
]),
);

const insertedEvents: { id: string; tags: Tag[] }[] = [];
let refreshedCount = 0;
for (const e of eventList) {
if (existingTitles.has(e.title)) continue;
const { tags: tagList, ...vals } = e;
const existingId = existingEventsByTitle.get(e.title);
if (existingId) {
await db
.update(events)
.set({ datetime: vals.datetime, endDatetime: vals.endDatetime })
.where(eq(events.id, existingId));
refreshedCount++;
continue;
}
const [inserted] = await db.insert(events).values(vals).returning({ id: events.id });
if (inserted) {
insertedEvents.push({ id: inserted.id, tags: tagList });
Expand All @@ -776,9 +791,7 @@ async function seed() {
}
}
}
console.log(
` Events: ${insertedEvents.length} inserted, ${existingTitles.size} already present`,
);
console.log(` Events: ${insertedEvents.length} inserted, ${refreshedCount} dates refreshed`);

/* ═══ 9. RSVPs ═══ */
const allUserIds = [...userMap.values()];
Expand Down
13 changes: 10 additions & 3 deletions apps/web/src/app/(app)/events/my-events-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { cn } from "~/lib/utils";

const TABS = [
{ id: "created", label: "Events Created" },
{ id: "rsvped", label: "Events RSVP'd" },
{ id: "saved", label: "Events Saved" },
] as const;

Expand Down Expand Up @@ -83,7 +84,7 @@ function EventListCard({ event }: { event: FeedEvent }) {
export function MyEventsClient({ created, rsvped, saved }: MyEventsClientProps) {
const [activeTab, setActiveTab] = useState<TabId>("created");

const eventMap: Record<TabId, FeedEvent[]> = { created, saved };
const eventMap: Record<TabId, FeedEvent[]> = { created, rsvped, saved };
const events = eventMap[activeTab];

return (
Expand Down Expand Up @@ -131,12 +132,18 @@ export function MyEventsClient({ created, rsvped, saved }: MyEventsClientProps)
) : (
<div className="flex flex-col items-center justify-center py-[60px]">
<p className="font-serif text-[24px] text-forum-dark-gray mb-[8px]">
{activeTab === "created" ? "No events created yet" : "No saved events"}
{activeTab === "created"
? "No events created yet"
: activeTab === "rsvped"
? "No RSVP'd events"
: "No saved events"}
</p>
<p className="text-[14px] font-dm-sans text-forum-light-gray mb-[24px]">
{activeTab === "created"
? "Share something with campus — create your first event."
: "Bookmark events you're interested in."}
: activeTab === "rsvped"
? "Events you've RSVP'd to will show up here."
: "Bookmark events you're interested in."}
</p>
</div>
)}
Expand Down
7 changes: 0 additions & 7 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"db:migrate": "turbo db:migrate",
"db:push": "turbo db:push",
"db:studio": "turbo db:studio",
"db:seed": "turbo db:seed",
"prepare": "husky"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"db:studio": {
"cache": false,
"persistent": true
},
"db:seed": {
"cache": false
}
}
}