Fix migrations - include schema.ts and use npm run db:push

This commit is contained in:
Christomatt
2026-01-31 06:52:05 +01:00
parent c512ecea80
commit 82f8d77abe
2 changed files with 23 additions and 17 deletions
+2 -1
View File
@@ -64,11 +64,12 @@ COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy drizzle migrations and config # Copy drizzle migrations, config, and schema (needed for migrations)
COPY --from=builder --chown=nextjs:nodejs /app/drizzle ./drizzle COPY --from=builder --chown=nextjs:nodejs /app/drizzle ./drizzle
COPY --from=builder --chown=nextjs:nodejs /app/drizzle.config.ts ./ COPY --from=builder --chown=nextjs:nodejs /app/drizzle.config.ts ./
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./ COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
COPY --from=builder --chown=nextjs:nodejs /app/package-lock.json ./ COPY --from=builder --chown=nextjs:nodejs /app/package-lock.json ./
COPY --from=builder --chown=nextjs:nodejs /app/src/db/schema.ts ./src/db/schema.ts
# Install drizzle-kit and pg (postgres driver) for migrations # Install drizzle-kit and pg (postgres driver) for migrations
# These are needed at runtime for the entrypoint to run migrations # These are needed at runtime for the entrypoint to run migrations
+21 -16
View File
@@ -1,30 +1,32 @@
#!/bin/sh #!/bin/sh
# Synapsis Docker Entrypoint Script # Synapsis Docker Entrypoint Script
# Handles database migrations, seeding, and application startup # Handles database migrations and application startup
set -e set -e
echo "========================================" echo "========================================"
echo " Synapsis - Starting Application" echo " Synapsis - Starting Application"
echo "========================================" echo "========================================"
echo " Time: $(date)"
echo " Working Dir: $(pwd)"
echo " Database URL: ${DATABASE_URL%%:*}://***@***"
echo "========================================"
# Function to wait for database # Function to wait for database
wait_for_db() { wait_for_db() {
echo ""
echo "⏳ Waiting for PostgreSQL..." echo "⏳ Waiting for PostgreSQL..."
# Extract connection details from DATABASE_URL # Extract host and port from DATABASE_URL
# Format: postgresql://user:password@host:port/database
DB_HOST=$(echo "$DATABASE_URL" | sed -n 's/.*@\([^:]*\):.*/\1/p') DB_HOST=$(echo "$DATABASE_URL" | sed -n 's/.*@\([^:]*\):.*/\1/p')
DB_PORT=$(echo "$DATABASE_URL" | sed -n 's/.*:\([0-9]*\)\/.*/\1/p') DB_PORT=$(echo "$DATABASE_URL" | sed -n 's/.*:\([0-9]*\)\/.*/\1/p')
# Default values
DB_HOST=${DB_HOST:-postgres} DB_HOST=${DB_HOST:-postgres}
DB_PORT=${DB_PORT:-5432} DB_PORT=${DB_PORT:-5432}
max_retries=30 max_retries=30
retry_count=0 retry_count=0
while ! nc -z "$DB_HOST" "$DB_PORT"; do while ! nc -z "$DB_HOST" "$DB_PORT" 2>/dev/null; do
retry_count=$((retry_count + 1)) retry_count=$((retry_count + 1))
if [ $retry_count -ge $max_retries ]; then if [ $retry_count -ge $max_retries ]; then
echo "❌ Failed to connect to database after $max_retries attempts" echo "❌ Failed to connect to database after $max_retries attempts"
@@ -41,33 +43,36 @@ wait_for_db() {
run_migrations() { run_migrations() {
echo "" echo ""
echo "🔄 Running database migrations..." echo "🔄 Running database migrations..."
echo " Current directory: $(pwd)"
echo " Drizzle directory contents:"
ls -la drizzle/ 2>/dev/null || echo " (drizzle dir not found or empty)"
# Run drizzle-kit push to create/update database schema # Run migrations using npm script
# This creates tables if they don't exist # This uses the drizzle.config.ts which should be in the app root
npx drizzle-kit push --force 2>&1 || { echo " Executing: npm run db:push"
echo "⚠️ Migration push returned non-zero (may be already up to date or error)" npm run db:push 2>&1 || {
echo " Continuing anyway..." echo "⚠️ Migration command exited with error (may be already up to date)"
} }
echo "✅ Migration check complete" echo "✅ Migration step complete"
} }
# Wait for database to be ready # Wait for database
wait_for_db wait_for_db
# Run migrations # Run migrations
run_migrations run_migrations
# Display startup info # Final startup message
echo "" echo ""
echo "========================================" echo "========================================"
echo " 🚀 Starting Synapsis Server" echo " 🚀 Starting Synapsis Server"
echo "========================================" echo "========================================"
echo " Environment: $NODE_ENV" echo " Environment: $NODE_ENV"
echo " Port: $PORT" echo " Port: $PORT"
echo " Database: Connected" echo " Node Version: $(node --version)"
echo "========================================" echo "========================================"
echo "" echo ""
# Execute the main command (passed as arguments) # Execute the main command
exec "$@" exec "$@"