diff --git a/entrypoint.sh b/entrypoint.sh index a61c178..b9aa0e8 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,17 +1,50 @@ #!/bin/sh set -e -echo "=== Syncing NextAuth schema ===" -# NOTE: Do NOT use --accept-data-loss — it drops tables not in the Prisma schema, -# which destroys fs_users, fs_projects etc. Use --skip-generate only. -npx prisma db push --skip-generate || echo "Prisma push failed (non-fatal — tables may already be correct)" +# Do NOT run `prisma db push` here. The Prisma schema only lists NextAuth tables; db push +# would try to DROP every other table (fs_*, agent_*, atlas_*, etc.) to match the schema. +# NextAuth tables are created below with IF NOT EXISTS (same DDL as /api/admin/migrate). -echo "=== Ensuring app tables exist ===" +echo "=== Ensuring database tables exist (idempotent SQL) ===" node -e " const { Pool } = require('pg'); const pool = new Pool({ connectionString: process.env.DATABASE_URL }); pool.query(\` CREATE EXTENSION IF NOT EXISTS pgcrypto; + CREATE TABLE IF NOT EXISTS users ( + id TEXT PRIMARY KEY, + name TEXT, + email TEXT UNIQUE, + email_verified TIMESTAMPTZ, + image TEXT + ); + CREATE TABLE IF NOT EXISTS accounts ( + id TEXT PRIMARY KEY, + user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, + type TEXT NOT NULL, + provider TEXT NOT NULL, + provider_account_id TEXT NOT NULL, + refresh_token TEXT, + access_token TEXT, + expires_at INTEGER, + token_type TEXT, + scope TEXT, + id_token TEXT, + session_state TEXT, + UNIQUE (provider, provider_account_id) + ); + CREATE TABLE IF NOT EXISTS sessions ( + id TEXT PRIMARY KEY, + session_token TEXT UNIQUE NOT NULL, + user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, + expires TIMESTAMPTZ NOT NULL + ); + CREATE TABLE IF NOT EXISTS verification_tokens ( + identifier TEXT NOT NULL, + token TEXT UNIQUE NOT NULL, + expires TIMESTAMPTZ NOT NULL, + UNIQUE (identifier, token) + ); CREATE TABLE IF NOT EXISTS fs_users ( id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text, user_id TEXT,