forked from jmug/cactoide
fix: small adjusments, renames for the /healthz and readme
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Postgres configuration
|
||||
POSTGRES_DB=cactoied_database
|
||||
POSTGRES_DB=cactoide_database
|
||||
POSTGRES_USER=cactoide
|
||||
POSTGRES_PASSWORD=cactoide_password
|
||||
POSTGRES_PORT=5432
|
||||
|
||||
11
Makefile
11
Makefile
@@ -1,4 +1,4 @@
|
||||
.PHONY: help build up db-only logs clean
|
||||
.PHONY: help build up db-only logs db-clean prune
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@@ -13,7 +13,8 @@ help:
|
||||
@echo ""
|
||||
@echo "Utility commands:"
|
||||
@echo " make logs - Show logs from all services"
|
||||
@echo " make clean - Remove all containers, images, and volumes"
|
||||
@echo " make db-clean - Stop & remove database container"
|
||||
@echo " make prune - Remove all containers, images, and volumes"
|
||||
@echo " make help - Show this help message"
|
||||
|
||||
# Build the Docker images
|
||||
@@ -36,8 +37,12 @@ logs:
|
||||
@echo "Showing logs from all services..."
|
||||
docker compose logs -f
|
||||
|
||||
db-clean:
|
||||
@echo "Cleaning up all Docker resources..."
|
||||
docker stop cactoide-db && docker rm cactoide-db && docker volume prune -f && docker network prune -f
|
||||
|
||||
# Clean up everything (containers, images, volumes)
|
||||
clean:
|
||||
prune:
|
||||
@echo "Cleaning up all Docker resources..."
|
||||
docker compose down -v --rmi all
|
||||
|
||||
|
||||
@@ -27,7 +27,10 @@ A mobile-first event RSVP platform that lets you create events, share unique URL
|
||||
|
||||
### Quick Start
|
||||
|
||||
Requirements: git, docker, docker-compose
|
||||
#### Requirements
|
||||
|
||||
`git, docker, docker-compose, node at least suggested 20.19.0`
|
||||
|
||||
Uses the [`docker-compose.yml`](docker-compose.yml) file to setup the application with the database. You can define all ENV variables in the [`.env`](.env.example) file from the `.env.example`.
|
||||
|
||||
```bash
|
||||
@@ -39,8 +42,6 @@ docker compose up -d
|
||||
|
||||
### Development
|
||||
|
||||
Requirements: git, docker, docker-compose, node at least suggested 20.19.0
|
||||
|
||||
```bash
|
||||
git clone https://github.com/polaroi8d/cactoide/
|
||||
cd cactoide
|
||||
@@ -51,6 +52,8 @@ npm run dev -- --open
|
||||
|
||||
Your app will be available at `http://localhost:5173`. You can use the Makefile commands to run the application or the database, eg.: `make db-only`.
|
||||
|
||||
Use the `database/seed.sql` if you want to populate your database with dummy data.
|
||||
|
||||
### License
|
||||
|
||||
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
||||
|
||||
@@ -8,7 +8,9 @@ services:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-cactoide}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-cactoide_password}
|
||||
expose:
|
||||
- '${POSTGRES_PORT:-5437}'
|
||||
- '${POSTGRES_PORT:-5432}'
|
||||
ports:
|
||||
- '${POSTGRES_PORT:-5432}:5432'
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./database/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||
|
||||
@@ -3,6 +3,13 @@ import { env } from '$env/dynamic/private';
|
||||
import * as schema from './schema';
|
||||
import postgres from 'postgres';
|
||||
|
||||
const client = postgres(env.DATABASE_URL, {});
|
||||
// Database connection configuration
|
||||
const connectionConfig = {
|
||||
max: 10, // Maximum number of connections
|
||||
idle_timeout: 20, // Close idle connections after 20 seconds
|
||||
connect_timeout: 10 // Connection timeout in seconds
|
||||
};
|
||||
|
||||
export const drizzleQuery = drizzle(client, { schema });
|
||||
const client = postgres(env.DATABASE_URL, connectionConfig);
|
||||
|
||||
export const database = drizzle(client, { schema });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { drizzleQuery } from '$lib/database/db';
|
||||
import { database } from '$lib/database/db';
|
||||
import { events } from '$lib/database/schema';
|
||||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import type { Actions } from './$types';
|
||||
@@ -66,7 +66,7 @@ export const actions: Actions = {
|
||||
|
||||
const eventId = generateEventId();
|
||||
|
||||
await drizzleQuery
|
||||
await database
|
||||
.insert(events)
|
||||
.values({
|
||||
id: eventId,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { drizzleQuery } from '$lib/database/db';
|
||||
import { database } from '$lib/database/db';
|
||||
import { eq, desc } from 'drizzle-orm';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { events } from '$lib/database/schema';
|
||||
@@ -6,7 +6,7 @@ import { events } from '$lib/database/schema';
|
||||
export const load: PageServerLoad = async () => {
|
||||
try {
|
||||
// Fetch all public events ordered by creation date (newest first)
|
||||
const publicEvents = await drizzleQuery
|
||||
const publicEvents = await database
|
||||
.select()
|
||||
.from(events)
|
||||
.where(eq(events.visibility, 'public'))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { drizzleQuery } from '$lib/database/db';
|
||||
import { database } from '$lib/database/db';
|
||||
import { events } from '$lib/database/schema';
|
||||
import { fail } from '@sveltejs/kit';
|
||||
import { eq, desc } from 'drizzle-orm';
|
||||
@@ -11,7 +11,7 @@ export const load = async ({ cookies }) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const userEvents = await drizzleQuery
|
||||
const userEvents = await database
|
||||
.select()
|
||||
.from(events)
|
||||
.where(eq(events.userId, userId))
|
||||
@@ -50,7 +50,7 @@ export const actions: Actions = {
|
||||
|
||||
try {
|
||||
// First verify the user owns this event
|
||||
const [eventData] = await drizzleQuery.select().from(events).where(eq(events.id, eventId));
|
||||
const [eventData] = await database.select().from(events).where(eq(events.id, eventId));
|
||||
|
||||
if (!eventData) {
|
||||
return fail(404, { error: 'Event not found' });
|
||||
@@ -61,7 +61,7 @@ export const actions: Actions = {
|
||||
}
|
||||
|
||||
// Delete the event (RSVPs will be deleted automatically due to CASCADE)
|
||||
await drizzleQuery.delete(events).where(eq(events.id, eventId));
|
||||
await database.delete(events).where(eq(events.id, eventId));
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { drizzleQuery } from '$lib/database/db';
|
||||
import { database } from '$lib/database/db';
|
||||
import { events, rsvps } from '$lib/database/schema';
|
||||
import { eq, asc } from 'drizzle-orm';
|
||||
import { error, fail } from '@sveltejs/kit';
|
||||
@@ -14,12 +14,8 @@ export const load: PageServerLoad = async ({ params, cookies }) => {
|
||||
try {
|
||||
// Fetch event and RSVPs in parallel
|
||||
const [eventData, rsvpData] = await Promise.all([
|
||||
drizzleQuery.select().from(events).where(eq(events.id, eventId)).limit(1),
|
||||
drizzleQuery
|
||||
.select()
|
||||
.from(rsvps)
|
||||
.where(eq(rsvps.eventId, eventId))
|
||||
.orderBy(asc(rsvps.createdAt))
|
||||
database.select().from(events).where(eq(events.id, eventId)).limit(1),
|
||||
database.select().from(rsvps).where(eq(rsvps.eventId, eventId)).orderBy(asc(rsvps.createdAt))
|
||||
]);
|
||||
|
||||
if (!eventData[0]) {
|
||||
@@ -81,33 +77,27 @@ export const actions: Actions = {
|
||||
|
||||
try {
|
||||
// Check if event exists and get its details
|
||||
const [eventData] = await drizzleQuery.select().from(events).where(eq(events.id, eventId));
|
||||
const [eventData] = await database.select().from(events).where(eq(events.id, eventId));
|
||||
if (!eventData) {
|
||||
return fail(404, { error: 'Event not found' });
|
||||
}
|
||||
|
||||
// Check if event is full (for limited type events)
|
||||
if (eventData.type === 'limited' && eventData.attendeeLimit) {
|
||||
const currentRSVPs = await drizzleQuery
|
||||
.select()
|
||||
.from(rsvps)
|
||||
.where(eq(rsvps.eventId, eventId));
|
||||
const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId));
|
||||
if (currentRSVPs.length >= eventData.attendeeLimit) {
|
||||
return fail(400, { error: 'Event is full' });
|
||||
}
|
||||
}
|
||||
|
||||
// Check if name is already in the list
|
||||
const existingRSVPs = await drizzleQuery
|
||||
.select()
|
||||
.from(rsvps)
|
||||
.where(eq(rsvps.eventId, eventId));
|
||||
const existingRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId));
|
||||
if (existingRSVPs.some((rsvp) => rsvp.name.toLowerCase() === name.toLowerCase())) {
|
||||
return fail(400, { error: 'Name already exists for this event' });
|
||||
}
|
||||
|
||||
// Add RSVP to database
|
||||
await drizzleQuery.insert(rsvps).values({
|
||||
await database.insert(rsvps).values({
|
||||
eventId: eventId,
|
||||
name: name.trim(),
|
||||
userId: userId,
|
||||
@@ -131,7 +121,7 @@ export const actions: Actions = {
|
||||
}
|
||||
|
||||
try {
|
||||
await drizzleQuery.delete(rsvps).where(eq(rsvps.id, rsvpId));
|
||||
await database.delete(rsvps).where(eq(rsvps.id, rsvpId));
|
||||
return { success: true, type: 'remove' };
|
||||
} catch (err) {
|
||||
console.error('Error removing RSVP:', err);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// src/routes/healthz/+server.ts
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { drizzleQuery } from '$lib/database/db';
|
||||
import { database } from '$lib/database/db';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
await drizzleQuery.execute(sql`select 1`);
|
||||
await database.execute(sql`select 1`);
|
||||
return json({ ok: true }, { headers: { 'cache-control': 'no-store' } });
|
||||
} catch (err) {
|
||||
return json(
|
||||
{ ok: false, error: (err as Error)?.message ?? 'DB unavailable' },
|
||||
{ ok: false, error: (err as Error)?.message, message: 'Database unreachable.' },
|
||||
{ status: 503, headers: { 'cache-control': 'no-store' } }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ const config = {
|
||||
preprocess: vitePreprocess(),
|
||||
|
||||
kit: {
|
||||
// Using Netlify adapter for deployment
|
||||
adapter: adapter({
|
||||
// if you want to use 'split' mode, set this to 'split'
|
||||
// and create a _redirects file with the redirects you want
|
||||
|
||||
Reference in New Issue
Block a user