Auto-indexing service and GraphQL API for AT Protocol Records quickslice.slices.network/
atproto gleam graphql
at main 113 lines 3.6 kB view raw
1# Quickslice Server Makefile 2# Database operations and development helpers 3 4.PHONY: help build test clean db-create db-migrate db-rollback db-status db-reset db-setup-sqlite db-setup-postgres 5 6# Load .env file if it exists (exports DATABASE_URL and other vars) 7ifneq (,$(wildcard .env)) 8 include .env 9 export 10endif 11 12# Default target 13help: 14 @echo "Quickslice Server Commands" 15 @echo "" 16 @echo "Build:" 17 @echo " make build - Build the Gleam project" 18 @echo " make test - Run tests" 19 @echo " make clean - Clean build artifacts" 20 @echo "" 21 @echo "Database (requires DATABASE_URL env var):" 22 @echo " make db-create - Create the database" 23 @echo " make db-migrate - Run pending migrations" 24 @echo " make db-rollback - Rollback the last migration" 25 @echo " make db-status - Show migration status" 26 @echo " make db-reset - Drop and recreate database (DESTRUCTIVE)" 27 @echo "" 28 @echo "Database Setup Helpers:" 29 @echo " make db-setup-sqlite - Set up SQLite database" 30 @echo " make db-setup-postgres - Set up PostgreSQL database" 31 @echo "" 32 @echo "Environment Variables:" 33 @echo " DATABASE_URL - Connection string (auto-loaded from .env if present)" 34 @echo " SQLite: sqlite:data/quickslice.db" 35 @echo " PostgreSQL: postgres://user:pass@localhost:5432/quickslice" 36 37# Build targets 38build: 39 gleam build 40 41test: 42 gleam test 43 44clean: 45 rm -rf build/ 46 47# Database targets (use dbmate) 48# These require DATABASE_URL to be set 49 50db-create: 51 @if [ -z "$$DATABASE_URL" ]; then echo "ERROR: DATABASE_URL not set"; exit 1; fi 52 @echo "Creating database..." 53 @if echo "$$DATABASE_URL" | grep -q "^postgres"; then \ 54 dbmate --migrations-dir ./db/migrations_postgres create; \ 55 else \ 56 dbmate create; \ 57 fi 58 59db-migrate: 60 @if [ -z "$$DATABASE_URL" ]; then echo "ERROR: DATABASE_URL not set"; exit 1; fi 61 @echo "Running migrations..." 62 @if echo "$$DATABASE_URL" | grep -q "^postgres"; then \ 63 dbmate --migrations-dir ./db/migrations_postgres up; \ 64 else \ 65 dbmate up; \ 66 fi 67 68db-rollback: 69 @if [ -z "$$DATABASE_URL" ]; then echo "ERROR: DATABASE_URL not set"; exit 1; fi 70 @echo "Rolling back last migration..." 71 @if echo "$$DATABASE_URL" | grep -q "^postgres"; then \ 72 dbmate --migrations-dir ./db/migrations_postgres down; \ 73 else \ 74 dbmate down; \ 75 fi 76 77db-status: 78 @if [ -z "$$DATABASE_URL" ]; then echo "ERROR: DATABASE_URL not set"; exit 1; fi 79 @echo "Migration status:" 80 @if echo "$$DATABASE_URL" | grep -q "^postgres"; then \ 81 dbmate --migrations-dir ./db/migrations_postgres status; \ 82 else \ 83 dbmate status; \ 84 fi 85 86db-reset: 87 @if [ -z "$$DATABASE_URL" ]; then echo "ERROR: DATABASE_URL not set"; exit 1; fi 88 @echo "WARNING: This will destroy all data!" 89 @read -p "Are you sure? [y/N] " confirm && [ "$$confirm" = "y" ] || exit 1 90 @echo "Dropping and recreating database..." 91 @if echo "$$DATABASE_URL" | grep -q "^postgres"; then \ 92 dbmate --migrations-dir ./db/migrations_postgres drop && \ 93 dbmate --migrations-dir ./db/migrations_postgres up; \ 94 else \ 95 dbmate drop && dbmate up; \ 96 fi 97 98# Convenience targets for local development 99db-setup-sqlite: 100 @mkdir -p data 101 DATABASE_URL=sqlite:data/quickslice.db $(MAKE) db-create db-migrate 102 @echo "SQLite database ready at data/quickslice.db" 103 @echo "Set DATABASE_URL=sqlite:data/quickslice.db to use it" 104 105db-setup-postgres: 106 @echo "Setting up PostgreSQL database..." 107 @echo "Ensure PostgreSQL is running and DATABASE_URL is set" 108 @if [ -z "$$DATABASE_URL" ]; then \ 109 echo "Example: DATABASE_URL=postgres://localhost:5432/quickslice make db-setup-postgres"; \ 110 exit 1; \ 111 fi 112 $(MAKE) db-create db-migrate 113 @echo "PostgreSQL database ready"