Skip to content

Commit 720071e

Browse files
ImTotemclaude
andcommitted
refactor(infra): remove internal API, n8n connects PG directly
- Delete sync/router.py (dump + expire-links endpoints) - Remove SYNC_TOKEN from config, deploy, docker-compose, .env.example - Rewrite workflows: Postgres node queries PG directly - Tables fetched dynamically via information_schema - Link expiration via direct UPDATE query - Remove broken credential auto-setup from init_n8n.sh - Validated workflows via n8n MCP (typeVersion 2.6/4.7) Credentials (Postgres + Google Sheets) set up manually in n8n UI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3c0fda1 commit 720071e

9 files changed

Lines changed: 73 additions & 505 deletions

File tree

.env.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ POSTGRES_HOST=postgres
3030
POSTGRES_PORT=5432
3131
POSTGRES_VOLUME_PATH=/home/ubuntu/bcsd-data/postgres
3232

33-
# 내부 API 인증 (n8n → API 동기화용)
34-
SYNC_TOKEN=change-me-random-string
35-
3633
REDIS_PASSWORD=change-me
3734
REDIS_PORT=6379
3835
REDIS_VOLUME_PATH=/home/ubuntu/bcsd-data/redis

infra/docker/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ services:
3535
N8N_BASIC_AUTH_USER: "${N8N_AUTH_USER}"
3636
N8N_BASIC_AUTH_PASSWORD: "${N8N_AUTH_PASSWORD}"
3737
N8N_ENCRYPTION_KEY: "${N8N_ENCRYPTION_KEY}"
38-
SYNC_TOKEN: "${SYNC_TOKEN}"
3938
GOOGLE_SHEETS_ID: "${GOOGLE_SHEETS_ID}"
4039
N8N_BLOCK_ENV_ACCESS_IN_NODE: "false"
4140
volumes:

infra/scripts/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ENVSUBST_VARS='${API_BLUE_PORT} ${API_GREEN_PORT} ${N8N_PORT} ${FRONTEND_PORT} $
1414
REQUIRED_VARS=(
1515
POSTGRES_USER POSTGRES_PASSWORD POSTGRES_DB
1616
GOOGLE_SERVICE_ACCOUNT_FILE GOOGLE_SHEETS_ID
17-
SYNC_TOKEN JWT_SECRET GOOGLE_CLIENT_ID
17+
JWT_SECRET GOOGLE_CLIENT_ID
1818
API_BLUE_PORT API_GREEN_PORT N8N_PORT
1919
)
2020

infra/scripts/init_n8n.sh

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# n8n workflow import + Google Sheets credential setup
5-
# Idempotent: skips if workflows already exist
4+
# n8n workflow import + owner setup
5+
# Idempotent: skips if already configured
6+
# Credentials (Postgres, Google Sheets) must be set up manually in n8n UI
67

78
COMPOSE="sudo docker compose -p bcsd-app --env-file .env -f infra/docker/docker-compose.yml"
8-
N8N_CONTAINER="bcsd-app-n8n-1"
99
MAX_RETRIES=15
1010

1111
wait_n8n() {
@@ -24,7 +24,7 @@ wait_n8n() {
2424
workflow_exists() {
2525
local name="$1"
2626
local count
27-
count=$($COMPOSE exec -T n8n n8n list:workflow 2>/dev/null | grep -c "$name" || true)
27+
count=$($COMPOSE exec -T n8n n8n list:workflow 2>&1 | grep -c "$name" || true)
2828
[ "$count" -gt 0 ]
2929
}
3030

@@ -39,45 +39,6 @@ import_workflow() {
3939
$COMPOSE exec -T n8n n8n import:workflow --input="$file"
4040
}
4141

42-
activate_workflow() {
43-
local name="$1"
44-
local wf_id
45-
wf_id=$($COMPOSE exec -T n8n n8n list:workflow 2>/dev/null | grep "$name" | awk -F'|' '{print $1}')
46-
if [ -z "$wf_id" ]; then
47-
echo " WARNING: Could not find workflow '$name' to activate"
48-
return 1
49-
fi
50-
$COMPOSE exec -T n8n n8n publish:workflow --id="$wf_id"
51-
echo " Activated '$name' (id: $wf_id)"
52-
}
53-
54-
setup_credential() {
55-
local existing
56-
existing=$($COMPOSE exec -T n8n n8n list:credential 2>&1 | grep -c "Google Sheets SA" || true)
57-
if [ "$existing" -gt 0 ]; then
58-
echo " Google Sheets credential already exists ($existing found) — skipping"
59-
return 0
60-
fi
61-
echo " Creating Google Sheets service account credential..."
62-
local cred_json
63-
cred_json=$(python3 -c "
64-
import json, sys
65-
sa = json.load(open('$GOOGLE_SERVICE_ACCOUNT_FILE'))
66-
cred = [{
67-
'id': str(__import__('uuid').uuid4()),
68-
'name': 'Google Sheets SA',
69-
'type': 'googleApi',
70-
'data': {
71-
'email': sa['client_email'],
72-
'privateKey': sa['private_key'],
73-
'impersonateUser': ''
74-
}
75-
}]
76-
json.dump(cred, sys.stdout)
77-
")
78-
echo "$cred_json" | $COMPOSE exec -T n8n n8n import:credentials --input=/dev/stdin
79-
}
80-
8142
setup_owner() {
8243
set -a; source .env; set +a
8344
local port
@@ -123,12 +84,5 @@ echo "4. Importing workflows..."
12384
import_workflow "/workflows/pg_sheets_sync.json" "PG → Sheets Sync (5min)"
12485
import_workflow "/workflows/link_auto_expire.json" "Link Auto-Expiration (hourly)"
12586

126-
echo "5. Setting up Google Sheets credential..."
127-
set -a; source .env; set +a
128-
setup_credential
129-
130-
echo "6. Activating workflows..."
131-
activate_workflow "PG → Sheets Sync"
132-
activate_workflow "Link Auto-Expiration"
133-
13487
echo "=== n8n Init complete ==="
88+
echo "NOTE: Set up Postgres + Google Sheets credentials in n8n UI if first deploy"

src/bcsd_api/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Settings(BaseSettings):
2323
postgres_db: str = "bcsd"
2424
postgres_host: str = "postgres"
2525
postgres_port: int = 5432
26-
sync_token: str = ""
2726
model_config = {"env_file": ".env", "extra": "ignore"}
2827

2928
@property

src/bcsd_api/main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from .member.router import router as member_router
1313
from .redirect import router as redirect_router
1414
from .shorten.router import router as shorten_router
15-
from .sync.router import router as sync_router
1615
from .track import router as track_router
1716

1817
logger = logging.getLogger(__name__)
@@ -75,7 +74,6 @@ def create_app() -> FastAPI:
7574
app.include_router(member_router)
7675
app.include_router(track_router)
7776
app.include_router(shorten_router)
78-
app.include_router(sync_router)
7977
app.include_router(redirect_router)
8078
return app
8179

src/bcsd_api/sync/router.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)