fix(entrypoint): drop prisma db push; add NextAuth DDL to SQL bootstrap
prisma db push compared DB to schema-only NextAuth models and proposed dropping fs_*, agent_*, atlas_*, etc. on every container start. Use CREATE TABLE IF NOT EXISTS for users/accounts/sessions/verification_tokens plus existing app tables — same pattern as admin migrate. Made-with: Cursor
This commit is contained in:
@@ -1,17 +1,50 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "=== Syncing NextAuth schema ==="
|
# Do NOT run `prisma db push` here. The Prisma schema only lists NextAuth tables; db push
|
||||||
# NOTE: Do NOT use --accept-data-loss — it drops tables not in the Prisma schema,
|
# would try to DROP every other table (fs_*, agent_*, atlas_*, etc.) to match the schema.
|
||||||
# which destroys fs_users, fs_projects etc. Use --skip-generate only.
|
# NextAuth tables are created below with IF NOT EXISTS (same DDL as /api/admin/migrate).
|
||||||
npx prisma db push --skip-generate || echo "Prisma push failed (non-fatal — tables may already be correct)"
|
|
||||||
|
|
||||||
echo "=== Ensuring app tables exist ==="
|
echo "=== Ensuring database tables exist (idempotent SQL) ==="
|
||||||
node -e "
|
node -e "
|
||||||
const { Pool } = require('pg');
|
const { Pool } = require('pg');
|
||||||
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
||||||
pool.query(\`
|
pool.query(\`
|
||||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
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 (
|
CREATE TABLE IF NOT EXISTS fs_users (
|
||||||
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
|
id TEXT PRIMARY KEY DEFAULT gen_random_uuid()::text,
|
||||||
user_id TEXT,
|
user_id TEXT,
|
||||||
|
|||||||
Reference in New Issue
Block a user