fix: update database switching to modify schema file directly
This commit is contained in:
@@ -0,0 +1,129 @@
|
|||||||
|
# justfile for Euchre Camp
|
||||||
|
# Automates development, testing, and deployment tasks.
|
||||||
|
# Designed for CI/CD pipelines and local development.
|
||||||
|
|
||||||
|
# --- Configuration ---
|
||||||
|
set dotenv-load
|
||||||
|
set positional-arguments
|
||||||
|
|
||||||
|
# Project name
|
||||||
|
PROJECT := "euchre-camp"
|
||||||
|
|
||||||
|
# Docker registry (CasaOS local registry)
|
||||||
|
REGISTRY := "dhg.lol:5000" # Update IP to your CasaOS server IP
|
||||||
|
IMAGE_TAG := "latest"
|
||||||
|
|
||||||
|
# --- Variables ---
|
||||||
|
# Database
|
||||||
|
DB_CONTAINER := "euchre-camp-postgres"
|
||||||
|
|
||||||
|
# --- Setup & Installation ---
|
||||||
|
|
||||||
|
# Install dependencies and setup environment
|
||||||
|
setup:
|
||||||
|
@echo "Installing dependencies..."
|
||||||
|
npm install
|
||||||
|
@echo "Setting up database..."
|
||||||
|
npm run db:setup-postgres
|
||||||
|
@echo "Generating Prisma client..."
|
||||||
|
npx prisma generate
|
||||||
|
|
||||||
|
# --- Development ---
|
||||||
|
|
||||||
|
# Start the development server
|
||||||
|
dev:
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# Lint the codebase
|
||||||
|
lint:
|
||||||
|
npm run lint
|
||||||
|
|
||||||
|
# Type check the codebase
|
||||||
|
typecheck:
|
||||||
|
npx tsc --noEmit
|
||||||
|
|
||||||
|
# Format code (if prettier is available, otherwise just lint)
|
||||||
|
format:
|
||||||
|
npx prettier --write .
|
||||||
|
|
||||||
|
# --- Testing ---
|
||||||
|
|
||||||
|
# Run all tests (unit + acceptance)
|
||||||
|
test: test-unit test-acceptance
|
||||||
|
|
||||||
|
# Run unit tests (Vitest)
|
||||||
|
test-unit:
|
||||||
|
npm run test:run
|
||||||
|
|
||||||
|
# Run acceptance tests (Playwright)
|
||||||
|
test-acceptance:
|
||||||
|
@echo "Starting Docker containers for acceptance tests..."
|
||||||
|
docker compose up -d
|
||||||
|
@echo "Waiting for services to be ready..."
|
||||||
|
sleep 10
|
||||||
|
@echo "Running acceptance tests..."
|
||||||
|
npm run test:acceptance
|
||||||
|
@echo "Stopping Docker containers..."
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
# Run database migrations (Prisma)
|
||||||
|
migrate:
|
||||||
|
npx prisma migrate dev
|
||||||
|
|
||||||
|
# Seed the database
|
||||||
|
seed:
|
||||||
|
npm run db:seed
|
||||||
|
|
||||||
|
# --- Docker ---
|
||||||
|
|
||||||
|
# Build the Docker image
|
||||||
|
docker-build:
|
||||||
|
@echo "Building Docker image {{PROJECT}}:{{IMAGE_TAG}}..."
|
||||||
|
docker build -t {{PROJECT}}:{{IMAGE_TAG}} .
|
||||||
|
|
||||||
|
# Run the Docker container locally
|
||||||
|
docker-run: docker-build
|
||||||
|
@echo "Running Docker container {{PROJECT}}..."
|
||||||
|
docker run -d -p 3000:3000 --name {{PROJECT}} {{PROJECT}}:{{IMAGE_TAG}}
|
||||||
|
|
||||||
|
# Stop and remove the Docker container
|
||||||
|
docker-stop:
|
||||||
|
@echo "Stopping Docker container {{PROJECT}}..."
|
||||||
|
docker stop {{PROJECT}} || true
|
||||||
|
docker rm {{PROJECT}} || true
|
||||||
|
|
||||||
|
# Clean up Docker images and containers
|
||||||
|
docker-clean: docker-stop
|
||||||
|
@echo "Removing Docker image {{PROJECT}}:{{IMAGE_TAG}}..."
|
||||||
|
docker rmi {{PROJECT}}:{{IMAGE_TAG}} || true
|
||||||
|
|
||||||
|
# --- Deployment ---
|
||||||
|
|
||||||
|
# Tag image for local registry
|
||||||
|
docker-tag:
|
||||||
|
@echo "Tagging image for registry {{REGISTRY}}..."
|
||||||
|
docker tag {{PROJECT}}:{{IMAGE_TAG}} {{REGISTRY}}/{{PROJECT}}:{{IMAGE_TAG}}
|
||||||
|
|
||||||
|
# Push image to local registry (CasaOS)
|
||||||
|
docker-push: docker-build docker-tag
|
||||||
|
@echo "Pushing image to {{REGISTRY}}..."
|
||||||
|
docker push {{REGISTRY}}/{{PROJECT}}:{{IMAGE_TAG}}
|
||||||
|
|
||||||
|
# --- CI/CD Pipeline Simulation ---
|
||||||
|
|
||||||
|
# Run full CI pipeline locally (lint, test, build, push)
|
||||||
|
ci: lint typecheck test-unit docker-build
|
||||||
|
@echo "CI Pipeline completed successfully!"
|
||||||
|
|
||||||
|
# --- Utilities ---
|
||||||
|
|
||||||
|
# Show help information
|
||||||
|
help:
|
||||||
|
@just --list
|
||||||
|
|
||||||
|
# Clean up project (remove node_modules, build artifacts)
|
||||||
|
clean:
|
||||||
|
@echo "Cleaning project..."
|
||||||
|
rm -rf node_modules .next dist
|
||||||
|
@echo "Cleaning Docker artifacts..."
|
||||||
|
docker system prune -f
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
[tools]
|
[tools]
|
||||||
|
docker-compose = "latest"
|
||||||
|
just = "latest"
|
||||||
node = "latest"
|
node = "latest"
|
||||||
npm = "latest"
|
npm = "latest"
|
||||||
|
postgres = "latest"
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ generator client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = env("DATABASE_PROVIDER", "sqlite")
|
provider = "sqlite"
|
||||||
url = env("DATABASE_URL")
|
url = env("DATABASE_URL")
|
||||||
shadowDatabaseUrl = env("DATABASE_SHADOW_URL")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: For PostgreSQL, create a separate schema file or use environment variable
|
||||||
|
// See scripts/switch-database.js for provider switching logic
|
||||||
|
|
||||||
model Player {
|
model Player {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
name String
|
name String
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function checkPostgresConnection() {
|
|||||||
console.error('❌ DATABASE_URL is not set for PostgreSQL');
|
console.error('❌ DATABASE_URL is not set for PostgreSQL');
|
||||||
console.error('Please update your .env file with:');
|
console.error('Please update your .env file with:');
|
||||||
console.error('DATABASE_PROVIDER=postgresql');
|
console.error('DATABASE_PROVIDER=postgresql');
|
||||||
console.error('DATABASE_URL="postgresql://username:password@localhost:5432/euchre_camp"');
|
console.error('DATABASE_URL="postgresql://euchre_camp:o_7urWjkvPfsE1Q*@localhost:5432/euchre_camp"');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function updateEnvFile(provider) {
|
|||||||
envContent = fs.readFileSync(envExampleFile, 'utf8');
|
envContent = fs.readFileSync(envExampleFile, 'utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update DATABASE_PROVIDER
|
// Update DATABASE_PROVIDER (note: this is for reference only, not used by Prisma)
|
||||||
const providerRegex = /^DATABASE_PROVIDER=.*$/m;
|
const providerRegex = /^DATABASE_PROVIDER=.*$/m;
|
||||||
if (providerRegex.test(envContent)) {
|
if (providerRegex.test(envContent)) {
|
||||||
envContent = envContent.replace(providerRegex, `DATABASE_PROVIDER=${provider}`);
|
envContent = envContent.replace(providerRegex, `DATABASE_PROVIDER=${provider}`);
|
||||||
@@ -54,6 +54,33 @@ function updateEnvFile(provider) {
|
|||||||
console.log(`✅ Updated ${envFile} to use ${provider} database`);
|
console.log(`✅ Updated ${envFile} to use ${provider} database`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSchemaFile(provider) {
|
||||||
|
const schemaPath = path.join(process.cwd(), 'prisma', 'schema.prisma');
|
||||||
|
|
||||||
|
if (!fs.existsSync(schemaPath)) {
|
||||||
|
console.error(`❌ Schema file not found: ${schemaPath}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let schemaContent = fs.readFileSync(schemaPath, 'utf8');
|
||||||
|
|
||||||
|
// Update the provider in the datasource block
|
||||||
|
const providerRegex = /(datasource db\s*\{[^}]*provider\s*=\s*)"[^"]+"/;
|
||||||
|
if (providerRegex.test(schemaContent)) {
|
||||||
|
schemaContent = schemaContent.replace(
|
||||||
|
providerRegex,
|
||||||
|
`$1"${provider}"`
|
||||||
|
);
|
||||||
|
|
||||||
|
fs.writeFileSync(schemaPath, schemaContent);
|
||||||
|
console.log(`✅ Updated schema.prisma to use ${provider} provider`);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
console.error(`❌ Could not find provider declaration in schema.prisma`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
const provider = args[0];
|
const provider = args[0];
|
||||||
@@ -70,6 +97,7 @@ function main() {
|
|||||||
|
|
||||||
const normalizedProvider = provider === 'postgres' ? 'postgresql' : provider;
|
const normalizedProvider = provider === 'postgres' ? 'postgresql' : provider;
|
||||||
updateEnvFile(normalizedProvider);
|
updateEnvFile(normalizedProvider);
|
||||||
|
updateSchemaFile(normalizedProvider);
|
||||||
|
|
||||||
console.log('\nNext steps:');
|
console.log('\nNext steps:');
|
||||||
console.log('1. Run: npx prisma generate');
|
console.log('1. Run: npx prisma generate');
|
||||||
|
|||||||
Reference in New Issue
Block a user