Skip to content

Commit 29ac366

Browse files
ImTotemclaude
andcommitted
fix(infra): simplify n8n init — import overwrites by ID, then publish
delete:workflow doesn't exist in n8n CLI. Import with same ID overwrites existing workflow. Use publish:workflow to activate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 018cf23 commit 29ac366

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

infra/scripts/init_n8n.sh

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
set -euo pipefail
33

44
# n8n workflow import + owner setup
5-
# Idempotent: skips if already configured
65
# Credentials (Postgres, Google Sheets) must be set up manually in n8n UI
76

87
COMPOSE="sudo docker compose -p bcsd-app --env-file .env -f infra/docker/docker-compose.yml"
@@ -21,24 +20,6 @@ wait_n8n() {
2120
return 1
2221
}
2322

24-
workflow_exists() {
25-
local name="$1"
26-
local count
27-
count=$($COMPOSE exec -T n8n n8n list:workflow 2>&1 | grep -c "$name" || true)
28-
[ "$count" -gt 0 ]
29-
}
30-
31-
delete_workflow() {
32-
local name="$1"
33-
if ! workflow_exists "$name"; then
34-
return 0
35-
fi
36-
local wf_id
37-
wf_id=$($COMPOSE exec -T n8n n8n list:workflow 2>&1 | grep "$name" | awk -F'|' '{print $1}')
38-
echo " Deleting old workflow '$name' (id: $wf_id)..."
39-
$COMPOSE exec -T n8n n8n delete:workflow --id="$wf_id" 2>&1 || true
40-
}
41-
4223
setup_owner() {
4324
set -a; source .env; set +a
4425
local port
@@ -80,14 +61,13 @@ fi
8061
echo "3. Setting up owner account..."
8162
setup_owner
8263

83-
echo "4. Replacing workflows..."
84-
delete_workflow "Link Auto-Expiration (hourly)"
85-
delete_workflow "Link Auto-Expiration (1min)"
86-
delete_workflow "PG → Sheets Sync (5min)"
87-
88-
echo "5. Importing workflows..."
64+
echo "4. Importing workflows (overwrites by ID)..."
8965
$COMPOSE exec -T n8n n8n import:workflow --input="/workflows/pg_sheets_sync.json" 2>&1
9066
$COMPOSE exec -T n8n n8n import:workflow --input="/workflows/link_auto_expire.json" 2>&1
9167

68+
echo "5. Publishing workflows..."
69+
$COMPOSE exec -T n8n n8n publish:workflow --id="pg-sheets-sync" 2>&1 || true
70+
$COMPOSE exec -T n8n n8n publish:workflow --id="link-auto-expire" 2>&1 || true
71+
9272
echo "=== n8n Init complete ==="
9373
echo "NOTE: Set up Postgres + Google Sheets credentials in n8n UI if first deploy"

0 commit comments

Comments
 (0)