create-restack-pattern 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-restack-pattern",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Scaffold a new Next.js + Hono + Drizzle monorepo using the Restack Pattern (Semi-DDD) template.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  DATABASE_URL=postgresql://user:password@localhost:5432/restack_pattern
2
- JWT_SECRET=your-secret-key-min-32-chars
2
+ JWT_SECRET=your-secret-key-min-32-characters # your-secret-key-min-32-characters
3
3
  NODE_ENV=development
4
4
  PORT=3001
5
5
  FRONTEND_URL=http://localhost:3000,https://myapp.vercel.app
@@ -6,8 +6,8 @@
6
6
  "build": "tsc",
7
7
  "start": "node dist/index.js",
8
8
  "db:generate": "drizzle-kit generate",
9
- "db:push": "drizzle-kit push",
10
- "db:studio": "drizzle-kit studio",
9
+ "db:push": "node scripts/db-check.js && drizzle-kit push",
10
+ "db:studio": "node scripts/db-check.js && drizzle-kit studio",
11
11
  "test": "vitest run"
12
12
  },
13
13
  "dependencies": {
@@ -0,0 +1,31 @@
1
+ import postgres from 'postgres';
2
+ import dotenv from 'dotenv';
3
+ import path from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ dotenv.config({ path: path.resolve(__dirname, '../.env') });
8
+
9
+ const dbUrl = process.env.DATABASE_URL;
10
+
11
+ if (!dbUrl) {
12
+ console.error('\x1b[31m[ERROR] DATABASE_URL is not set in backend/.env\x1b[0m');
13
+ process.exit(1);
14
+ }
15
+
16
+ console.log('\x1b[36mChecking database connection...\x1b[0m');
17
+
18
+ // Configure with 1 max connection and a low timeout for quick check response
19
+ const sql = postgres(dbUrl, { max: 1, connect_timeout: 5 });
20
+
21
+ try {
22
+ await sql`SELECT 1`;
23
+ console.log('\x1b[32m✔ Database connection successful!\x1b[0m');
24
+ await sql.end();
25
+ process.exit(0);
26
+ } catch (err) {
27
+ console.error('\x1b[31m[ERROR] Database connection failed! Please check your credentials in backend/.env\x1b[0m');
28
+ console.error(`\x1b[33mError Details:\x1b[0m ${err.message}\n`);
29
+ await sql.end();
30
+ process.exit(1);
31
+ }