@panoptic-it-solutions/coolify-setup 1.1.35 → 1.1.36

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/dist/generator.js CHANGED
@@ -19,6 +19,65 @@ function getDefaultDbPath() {
19
19
  const srcAppPath = join(process.cwd(), 'src/app');
20
20
  return existsSync(srcAppPath) ? 'src/lib/db' : 'lib/db';
21
21
  }
22
+ function getDrizzleConfigPath() {
23
+ const cwd = process.cwd();
24
+ const possiblePaths = ['drizzle.config.ts', 'drizzle.config.js', 'drizzle.config.mjs'];
25
+ for (const configPath of possiblePaths) {
26
+ if (existsSync(join(cwd, configPath))) {
27
+ return configPath;
28
+ }
29
+ }
30
+ return null;
31
+ }
32
+ function updateDrizzleConfigOutput(dbPath) {
33
+ const configPath = getDrizzleConfigPath();
34
+ if (!configPath) {
35
+ return false;
36
+ }
37
+ const fullPath = join(process.cwd(), configPath);
38
+ const expectedOut = `./${dbPath}/migrations`;
39
+ try {
40
+ let content = readFileSync(fullPath, 'utf-8');
41
+ // Check if output path already matches
42
+ if (content.includes(`out: "${expectedOut}"`) || content.includes(`out: '${expectedOut}'`)) {
43
+ return false; // Already correct
44
+ }
45
+ // Replace the out path - handles both single and double quotes
46
+ const outRegex = /out:\s*["']\.\/[^"']+["']/;
47
+ if (outRegex.test(content)) {
48
+ content = content.replace(outRegex, `out: "${expectedOut}"`);
49
+ writeFileSync(fullPath, content, 'utf-8');
50
+ console.log(`Updated ${configPath} output path to ${expectedOut}`);
51
+ return true;
52
+ }
53
+ return false;
54
+ }
55
+ catch (error) {
56
+ console.log(`Warning: Failed to update ${configPath}:`, error);
57
+ return false;
58
+ }
59
+ }
60
+ function runDrizzleKitGenerate(packageManager) {
61
+ if (!getDrizzleConfigPath()) {
62
+ console.log('Warning: No drizzle.config.ts found, skipping migration generation');
63
+ return false;
64
+ }
65
+ try {
66
+ // Use the package manager's exec command to run drizzle-kit
67
+ const execCmd = packageManager === 'pnpm'
68
+ ? 'pnpm drizzle-kit generate'
69
+ : packageManager === 'yarn'
70
+ ? 'yarn drizzle-kit generate'
71
+ : 'npx drizzle-kit generate';
72
+ console.log(`Running ${execCmd}...`);
73
+ execSync(execCmd, { stdio: 'inherit', cwd: process.cwd() });
74
+ return true;
75
+ }
76
+ catch (error) {
77
+ console.log('Warning: Failed to run drizzle-kit generate:', error);
78
+ return false;
79
+ }
80
+ }
22
81
  function addEsbuildToPackageJson(packageManager) {
23
82
  const packageJsonPath = join(process.cwd(), 'package.json');
24
83
  if (!existsSync(packageJsonPath)) {
@@ -180,7 +239,15 @@ export async function generateFiles(options) {
180
239
  }
181
240
  // Clean up old files from previous runs (if dbPath changed)
182
241
  cleanupOldMigrationFiles(dbPath);
183
- // Create empty migrations folder if none exists
242
+ // Update drizzle.config.ts output path to match our expected location
243
+ updateDrizzleConfigOutput(dbPath);
244
+ // Run drizzle-kit generate to create migration SQL files from schema
245
+ // This only works if drizzle.config.ts exists and schema is defined
246
+ const migrationsGenerated = runDrizzleKitGenerate(packageManager);
247
+ if (migrationsGenerated) {
248
+ console.log('Generated database migrations from schema');
249
+ }
250
+ // Create empty migrations folder if drizzle-kit didn't create one
184
251
  const migrationsPath = join(process.cwd(), dbPath, 'migrations');
185
252
  if (!existsSync(migrationsPath)) {
186
253
  ensureDir(join(migrationsPath, 'dummy'));
@@ -197,7 +264,12 @@ export async function generateFiles(options) {
197
264
  }
198
265
  }
199
266
  else {
200
- // For Node.js projects, write to scripts/ directory
267
+ // For Node.js projects, update drizzle config and run generate
268
+ updateDrizzleConfigOutput(dbPath);
269
+ const migrationsGenerated = runDrizzleKitGenerate(packageManager);
270
+ if (migrationsGenerated) {
271
+ console.log('Generated database migrations from schema');
272
+ }
201
273
  const migrateScript = generateMigrateScript({ projectType, dbPath });
202
274
  writeFile('scripts/migrate.ts', migrateScript);
203
275
  }
package/dist/index.js CHANGED
@@ -96,16 +96,22 @@ async function main() {
96
96
  else {
97
97
  generatedFiles.push('package-lock.json');
98
98
  }
99
- // Add migrate script if postgres included
99
+ // Add migrate script and migrations folder if postgres included
100
100
  if (response.includePostgres) {
101
+ // drizzle.config.ts may be updated to use correct output path
102
+ generatedFiles.push('drizzle.config.ts');
103
+ generatedFiles.push('drizzle.config.js');
104
+ generatedFiles.push('drizzle.config.mjs');
101
105
  if (project.type === 'nextjs') {
102
106
  // Use detected dbPath, or fall back to default based on project structure
103
107
  const dbPath = project.dbPath ?? (project.type === 'nextjs' ? 'lib/db' : 'db');
104
108
  generatedFiles.push(`${dbPath}/migrate.ts`);
109
+ generatedFiles.push(`${dbPath}/migrations`); // Include generated migrations
105
110
  generatedFiles.push('tsconfig.json'); // May be modified with exclude
106
111
  }
107
112
  else {
108
113
  generatedFiles.push('scripts/migrate.ts');
114
+ generatedFiles.push('scripts/migrations'); // Include generated migrations
109
115
  }
110
116
  }
111
117
  console.log(chalk.green(' ✓ Dockerfile'));
@@ -39,7 +39,7 @@ export function generateDockerCompose(options) {
39
39
  volumes:
40
40
  - postgres-data:/var/lib/postgresql/data
41
41
  healthcheck:
42
- test: ["CMD-SHELL", "pg_isready -U \${POSTGRES_USER:-postgres}"]
42
+ test: ["CMD-SHELL", "pg_isready -U \${POSTGRES_USER:-postgres} -d \${POSTGRES_DB:-app}"]
43
43
  interval: 10s
44
44
  timeout: 5s
45
45
  retries: 5`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panoptic-it-solutions/coolify-setup",
3
- "version": "1.1.35",
3
+ "version": "1.1.36",
4
4
  "description": "CLI tool for setting up Coolify deployment on Panoptic projects",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",