Merge cursor/umfassende-plattform-berarbeitung-d0f0 into dev_test
Resolve email API TLS/env var merge conflicts and bring latest platform changes into dev_test.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
const { spawn, exec } = require('child_process');
|
||||
const { spawn, exec } = require("child_process");
|
||||
const os = require('os');
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
@@ -15,9 +15,23 @@ console.log(`🖥️ Detected architecture: ${arch}`);
|
||||
console.log(`🍎 Apple Silicon: ${isAppleSilicon ? 'Yes' : 'No'}`);
|
||||
|
||||
// Use minimal compose file (only PostgreSQL and Redis)
|
||||
const composeFile = 'docker-compose.dev.minimal.yml';
|
||||
const composeFile = "docker-compose.dev.minimal.yml";
|
||||
console.log(`📦 Using minimal Docker Compose file: ${composeFile}`);
|
||||
|
||||
function runCommand(command, env) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, { env: env ?? process.env }, (error, stdout, stderr) => {
|
||||
if (stdout) process.stdout.write(stdout);
|
||||
if (stderr) process.stderr.write(stderr);
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve(undefined);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Check if docker-compose is available
|
||||
exec('docker-compose --version', (error) => {
|
||||
if (error) {
|
||||
@@ -43,40 +57,60 @@ exec('docker-compose --version', (error) => {
|
||||
|
||||
// Wait a bit for services to be ready
|
||||
setTimeout(() => {
|
||||
console.log('🚀 Starting Next.js development server...');
|
||||
|
||||
// Start Next.js dev server
|
||||
const nextProcess = spawn('npm', ['run', 'dev:next'], {
|
||||
stdio: 'inherit',
|
||||
shell: isWindows,
|
||||
env: {
|
||||
...process.env,
|
||||
DATABASE_URL: process.env.DATABASE_URL || 'postgresql://portfolio_user:portfolio_dev_pass@localhost:5432/portfolio_dev?schema=public',
|
||||
REDIS_URL: 'redis://localhost:6379',
|
||||
NODE_ENV: 'development'
|
||||
const devEnv = {
|
||||
...process.env,
|
||||
DATABASE_URL:
|
||||
process.env.DATABASE_URL ||
|
||||
"postgresql://portfolio_user:portfolio_dev_pass@localhost:5432/portfolio_dev?schema=public",
|
||||
REDIS_URL: "redis://localhost:6379",
|
||||
NODE_ENV: "development",
|
||||
};
|
||||
|
||||
// Ensure DB schema exists before starting Next dev server.
|
||||
// This prevents "table does not exist" errors for Projects/CMS/Analytics.
|
||||
(async () => {
|
||||
try {
|
||||
console.log("🗄️ Applying Prisma migrations (dev)...");
|
||||
await runCommand("npx prisma generate", devEnv);
|
||||
await runCommand("npx prisma migrate deploy", devEnv);
|
||||
// seeding is optional; keep it non-blocking
|
||||
await runCommand("npx prisma db seed", devEnv).catch(() => {});
|
||||
console.log("✅ Database is ready");
|
||||
} catch (_e) {
|
||||
console.warn("⚠️ Could not run Prisma migrations automatically.");
|
||||
console.warn(" You can run: npm run db:setup");
|
||||
}
|
||||
});
|
||||
|
||||
nextProcess.on('close', (code) => {
|
||||
console.log(`Next.js dev server exited with code ${code}`);
|
||||
});
|
||||
console.log("🚀 Starting Next.js development server...");
|
||||
|
||||
// Start Next.js dev server
|
||||
const nextProcess = spawn("npm", ["run", "dev:next"], {
|
||||
stdio: "inherit",
|
||||
shell: isWindows,
|
||||
env: devEnv,
|
||||
});
|
||||
|
||||
// Handle process signals
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n🛑 Stopping development environment...');
|
||||
nextProcess.kill('SIGTERM');
|
||||
|
||||
// Stop Docker services
|
||||
const stopProcess = spawn('docker-compose', ['-f', composeFile, 'down'], {
|
||||
stdio: 'inherit',
|
||||
shell: isWindows
|
||||
nextProcess.on("close", (code) => {
|
||||
console.log(`Next.js dev server exited with code ${code}`);
|
||||
});
|
||||
|
||||
stopProcess.on('close', () => {
|
||||
console.log('✅ Development environment stopped');
|
||||
process.exit(0);
|
||||
|
||||
// Handle process signals
|
||||
process.on("SIGINT", () => {
|
||||
console.log("\n🛑 Stopping development environment...");
|
||||
nextProcess.kill("SIGTERM");
|
||||
|
||||
// Stop Docker services
|
||||
const stopProcess = spawn("docker-compose", ["-f", composeFile, "down"], {
|
||||
stdio: "inherit",
|
||||
shell: isWindows,
|
||||
});
|
||||
|
||||
stopProcess.on("close", () => {
|
||||
console.log("✅ Development environment stopped");
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
}, 5000); // Wait 5 seconds for services to be ready
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ async function setupDatabase() {
|
||||
console.log('📦 Generating Prisma client...');
|
||||
await runCommand('npx prisma generate');
|
||||
|
||||
console.log('🔄 Pushing database schema...');
|
||||
await runCommand('npx prisma db push');
|
||||
console.log('🔄 Applying database migrations...');
|
||||
await runCommand('npx prisma migrate deploy');
|
||||
|
||||
console.log('🌱 Seeding database...');
|
||||
await runCommand('npx prisma db seed');
|
||||
|
||||
68
scripts/start-with-migrate.js
Normal file
68
scripts/start-with-migrate.js
Normal file
@@ -0,0 +1,68 @@
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
/**
|
||||
* Container entrypoint: apply Prisma migrations, then start Next server.
|
||||
*
|
||||
* Why:
|
||||
* - In real deployments you want schema changes applied automatically per deploy.
|
||||
* - `prisma migrate deploy` is safe to run multiple times (idempotent).
|
||||
*
|
||||
* Controls:
|
||||
* - Set `SKIP_PRISMA_MIGRATE=true` to skip migrations (emergency / debugging).
|
||||
*/
|
||||
const { spawnSync } = require("node:child_process");
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
function run(cmd, args, opts = {}) {
|
||||
const res = spawnSync(cmd, args, {
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
...opts,
|
||||
});
|
||||
|
||||
if (res.error) {
|
||||
throw res.error;
|
||||
}
|
||||
if (typeof res.status === "number" && res.status !== 0) {
|
||||
// propagate exit code
|
||||
process.exit(res.status);
|
||||
}
|
||||
}
|
||||
|
||||
const skip = String(process.env.SKIP_PRISMA_MIGRATE || "").toLowerCase() === "true";
|
||||
if (!skip) {
|
||||
const autoBaseline =
|
||||
String(process.env.PRISMA_AUTO_BASELINE || "").toLowerCase() === "true";
|
||||
|
||||
// Avoid relying on `npx` resolution in minimal runtimes.
|
||||
// We copy `node_modules/prisma` into the runtime image.
|
||||
if (autoBaseline) {
|
||||
try {
|
||||
const migrationsDir = path.join(process.cwd(), "prisma", "migrations");
|
||||
const entries = fs
|
||||
.readdirSync(migrationsDir, { withFileTypes: true })
|
||||
.filter((d) => d.isDirectory())
|
||||
.map((d) => d.name);
|
||||
const initMigration = entries.find((n) => n.endsWith("_init"));
|
||||
if (initMigration) {
|
||||
// This is the documented "baseline" flow for existing databases:
|
||||
// mark the initial migration as already applied.
|
||||
run("node", [
|
||||
"node_modules/prisma/build/index.js",
|
||||
"migrate",
|
||||
"resolve",
|
||||
"--applied",
|
||||
initMigration,
|
||||
]);
|
||||
}
|
||||
} catch (_err) {
|
||||
// If baseline fails we continue to migrate deploy, which will surface the real issue.
|
||||
}
|
||||
}
|
||||
run("node", ["node_modules/prisma/build/index.js", "migrate", "deploy"]);
|
||||
} else {
|
||||
console.log("SKIP_PRISMA_MIGRATE=true -> skipping prisma migrate deploy");
|
||||
}
|
||||
|
||||
run("node", ["server.js"]);
|
||||
|
||||
Reference in New Issue
Block a user