@panoptic-it-solutions/coolify-setup 1.1.34 → 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'));
@@ -232,8 +238,9 @@ async function main() {
232
238
  console.log(' staging → Staging deployment (auto-deploy on merge)');
233
239
  console.log(' main → Production deployment (merge PR to deploy)\n');
234
240
  console.log(chalk.bold('Deployment Flow:\n'));
235
- console.log(' develop/feature/** → build → PR to staging → merge → staging deploys');
236
- console.log(' → PR to main → merge → prod deploys\n');
241
+ console.log(' feature/** → PR to develop → merge');
242
+ console.log(' develop → PR to staging → merge → staging deploys');
243
+ console.log(' staging → PR to main → merge → prod deploys\n');
237
244
  }
238
245
  main().catch((error) => {
239
246
  console.error(chalk.red('Error:'), error);
@@ -27,19 +27,23 @@ This project uses a trunk-based development workflow with deployment branches:
27
27
  - Fixes: \`fix/bug-description\`
28
28
  - Hotfixes: \`hotfix/urgent-fix\`
29
29
 
30
- 2. **Build**: Push triggers GitHub Actions
30
+ 2. **Feature Development**: Push feature/fix/hotfix branches
31
31
  - Builds Docker image
32
32
  - Pushes to private registry
33
+ - Creates PR to \`develop\` branch
34
+
35
+ 3. **Integration**: Merge PR to \`develop\`
36
+ - Builds Docker image
33
37
  - Creates PR to \`staging\` branch
34
38
 
35
- 3. **Staging Deployment**: Merge PR to \`staging\`
39
+ 4. **Staging Deployment**: Merge PR to \`staging\`
36
40
  - Coolify auto-deploys to staging server
37
41
  - GitHub Actions runs semantic versioning workflow
38
42
  - Creates \`staging-v*\` tags based on conventional commits
43
+ - Creates PR to \`main\` branch
39
44
  - Test changes in staging environment
40
45
 
41
- 4. **Production Deployment**: Create PR from \`staging\` to \`main\`
42
- - Review changes and merge
46
+ 5. **Production Deployment**: Merge PR to \`main\`
43
47
  - Coolify auto-deploys to production server
44
48
 
45
49
  ### Conventional Commits
@@ -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`);
@@ -46,11 +46,21 @@ jobs:
46
46
  - name: Determine target branch
47
47
  id: target
48
48
  run: |
49
- # All branches deploy to staging
50
- # Promotion to main is a manual step
51
- echo "branch=staging" >> $GITHUB_OUTPUT
49
+ SOURCE_BRANCH="\${{ github.ref_name }}"
50
+
51
+ # Feature/fix/hotfix branches target develop
52
+ if [[ "\\$SOURCE_BRANCH" == feature/* ]] || [[ "\\$SOURCE_BRANCH" == fix/* ]] || [[ "\\$SOURCE_BRANCH" == hotfix/* ]]; then
53
+ echo "branch=develop" >> \\$GITHUB_OUTPUT
54
+ # Develop targets staging
55
+ elif [[ "\\$SOURCE_BRANCH" == "develop" ]]; then
56
+ echo "branch=staging" >> \\$GITHUB_OUTPUT
57
+ # Staging/other branches don't create PRs (staging->main handled separately)
58
+ else
59
+ echo "branch=" >> \\$GITHUB_OUTPUT
60
+ fi
52
61
 
53
62
  - name: Create deploy PR
63
+ if: steps.target.outputs.branch != ''
54
64
  uses: actions/github-script@v7
55
65
  with:
56
66
  script: |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panoptic-it-solutions/coolify-setup",
3
- "version": "1.1.34",
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",