Skip to content

Commit 5951813

Browse files
Merge: fix agents/claw_agents table collision with n8n core Agents (#35)
Verified live on the n8n-claw instance: 009 rename applied, claw_agents holds 19 app rows, public.agents is now n8n's core table (projectId, 0 rows), agent execution 136652 loaded config from claw_agents successfully. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2 parents 09f01d9 + 41e2a12 commit 5951813

10 files changed

Lines changed: 117 additions & 34 deletions

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,15 @@ docker compose up -d
13331333
13341334
</summary>
13351335
1336+
**n8n won't start after `docker compose pull` (logs show `column "projectId" does not exist` / `CreateAgentTables1783000000000`)?**
1337+
→ n8n 2.21.4 and newer ship a built-in *Agents* feature that creates its own `agents` table. Older n8n-claw installs already had an app table named `agents` in the same database, so n8n's migration collides and the instance crash-loops on boot. Your data is safe (the failed migration rolls back cleanly). The fix renames the app table to `claw_agents`, freeing the name for n8n:
1338+
1339+
```bash
1340+
cd n8n-claw && git pull && ./setup.sh --force
1341+
```
1342+
1343+
This applies migration `009_agents_rename.sql` (renames the table, keeping all your personas and tool config), lets n8n boot, and re-imports the workflows so they point at `claw_agents`. No version pin needed: you can stay on current n8n.
1344+
13361345
**Agent not responding to Telegram messages?**
13371346
→ Check all workflows are **activated** in n8n UI
13381347

setup.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,20 @@ if [ -n "$FITNESS_ERRORS" ]; then
680680
fi
681681
echo " ✅ Fitness Buddy schema applied"
682682

683+
# Rename app table agents -> claw_agents (Issue #35: avoids collision with
684+
# n8n >= 2.21.4 core Agents feature). Idempotent: only renames n8n-claw's
685+
# table (identified by its `key` column) and only if not already renamed.
686+
# Must run before n8n migrates so it can create its own public.agents.
687+
echo " Applying agents->claw_agents rename migration..."
688+
RENAME_OUTPUT=$(LANG=C LC_ALL=C PGPASSWORD=$POSTGRES_PASSWORD psql -h localhost -U postgres -d postgres \
689+
-f supabase/migrations/009_agents_rename.sql 2>&1)
690+
RENAME_ERRORS=$(echo "$RENAME_OUTPUT" | grep -i "error" | head -5)
691+
if [ -n "$RENAME_ERRORS" ]; then
692+
echo -e " ${YELLOW}⚠️ Rename migration warnings:${NC}"
693+
echo "$RENAME_ERRORS" | while read line; do echo " $line"; done
694+
fi
695+
echo " ✅ agents->claw_agents rename applied"
696+
683697
# Reload PostgREST schema cache so new tables are immediately available via API
684698
docker kill --signal=SIGUSR1 $(docker ps -q --filter name=rest) 2>/dev/null || true
685699

@@ -2296,7 +2310,7 @@ user = '${USER_DISPLAY}'.replace("'", "''")
22962310
ctx = '${CTX}'.replace("'", "''")
22972311
22982312
sql = f"""
2299-
INSERT INTO public.agents (key, content) VALUES
2313+
INSERT INTO public.claw_agents (key, content) VALUES
23002314
('mcp_instructions', 'You have MCP Skills — installable capabilities powered by the Model Context Protocol (MCP):
23012315
23022316
## MCP Client (mcp_client tool)
@@ -2760,7 +2774,7 @@ pw = os.environ.get('POSTGRES_PASSWORD', '')
27602774
env = {**os.environ, 'PGPASSWORD': pw, 'LANG': 'C', 'LC_ALL': 'C'}
27612775
27622776
sql = """
2763-
INSERT INTO public.agents (key, content) VALUES
2777+
INSERT INTO public.claw_agents (key, content) VALUES
27642778
('persona:research-expert', '# Research Expert
27652779
27662780
## Expertise

supabase/migrations/001_schema.sql

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,27 @@ SET default_tablespace = '';
121121
SET default_table_access_method = heap;
122122

123123
--
124-
-- Name: agents; Type: TABLE; Schema: public; Owner: postgres
124+
-- Name: claw_agents; Type: TABLE; Schema: public; Owner: postgres
125+
--
126+
-- Renamed from `agents` (Issue #35): n8n >= 2.21.4 ships a core
127+
-- "Agents" feature that creates its own public.agents table.
125128
--
126129

127-
CREATE TABLE public.agents (
130+
CREATE TABLE public.claw_agents (
128131
id integer NOT NULL,
129132
key text NOT NULL,
130133
content text NOT NULL,
131134
updated_at timestamp with time zone DEFAULT now()
132135
);
133136

134137

135-
ALTER TABLE public.agents OWNER TO postgres;
138+
ALTER TABLE public.claw_agents OWNER TO postgres;
136139

137140
--
138-
-- Name: agents_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
141+
-- Name: claw_agents_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
139142
--
140143

141-
CREATE SEQUENCE public.agents_id_seq
144+
CREATE SEQUENCE public.claw_agents_id_seq
142145
AS integer
143146
START WITH 1
144147
INCREMENT BY 1
@@ -147,13 +150,13 @@ CREATE SEQUENCE public.agents_id_seq
147150
CACHE 1;
148151

149152

150-
ALTER TABLE public.agents_id_seq OWNER TO postgres;
153+
ALTER TABLE public.claw_agents_id_seq OWNER TO postgres;
151154

152155
--
153-
-- Name: agents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
156+
-- Name: claw_agents_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
154157
--
155158

156-
ALTER SEQUENCE public.agents_id_seq OWNED BY public.agents.id;
159+
ALTER SEQUENCE public.claw_agents_id_seq OWNED BY public.claw_agents.id;
157160

158161

159162
--
@@ -548,10 +551,10 @@ ALTER SEQUENCE public.reminders_id_seq OWNED BY public.reminders.id;
548551

549552

550553
--
551-
-- Name: agents id; Type: DEFAULT; Schema: public; Owner: postgres
554+
-- Name: claw_agents id; Type: DEFAULT; Schema: public; Owner: postgres
552555
--
553556

554-
ALTER TABLE ONLY public.agents ALTER COLUMN id SET DEFAULT nextval('public.agents_id_seq'::regclass);
557+
ALTER TABLE ONLY public.claw_agents ALTER COLUMN id SET DEFAULT nextval('public.claw_agents_id_seq'::regclass);
555558

556559

557560
--
@@ -625,19 +628,19 @@ ALTER TABLE ONLY public.reminders ALTER COLUMN id SET DEFAULT nextval('public.re
625628

626629

627630
--
628-
-- Name: agents agents_key_key; Type: CONSTRAINT; Schema: public; Owner: postgres
631+
-- Name: claw_agents claw_agents_key_key; Type: CONSTRAINT; Schema: public; Owner: postgres
629632
--
630633

631-
ALTER TABLE ONLY public.agents
632-
ADD CONSTRAINT agents_key_key UNIQUE (key);
634+
ALTER TABLE ONLY public.claw_agents
635+
ADD CONSTRAINT claw_agents_key_key UNIQUE (key);
633636

634637

635638
--
636-
-- Name: agents agents_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
639+
-- Name: claw_agents claw_agents_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
637640
--
638641

639-
ALTER TABLE ONLY public.agents
640-
ADD CONSTRAINT agents_pkey PRIMARY KEY (id);
642+
ALTER TABLE ONLY public.claw_agents
643+
ADD CONSTRAINT claw_agents_pkey PRIMARY KEY (id);
641644

642645

643646
--
@@ -903,12 +906,12 @@ GRANT ALL ON FUNCTION public.search_memory_keyword(search_query text, match_coun
903906

904907

905908
--
906-
-- Name: TABLE agents; Type: ACL; Schema: public; Owner: postgres
909+
-- Name: TABLE claw_agents; Type: ACL; Schema: public; Owner: postgres
907910
--
908911

909-
GRANT ALL ON TABLE public.agents TO anon;
910-
GRANT ALL ON TABLE public.agents TO authenticated;
911-
GRANT ALL ON TABLE public.agents TO service_role;
912+
GRANT ALL ON TABLE public.claw_agents TO anon;
913+
GRANT ALL ON TABLE public.claw_agents TO authenticated;
914+
GRANT ALL ON TABLE public.claw_agents TO service_role;
912915

913916

914917
--
@@ -921,12 +924,12 @@ GRANT ALL ON TABLE public.file_refs TO service_role;
921924

922925

923926
--
924-
-- Name: SEQUENCE agents_id_seq; Type: ACL; Schema: public; Owner: postgres
927+
-- Name: SEQUENCE claw_agents_id_seq; Type: ACL; Schema: public; Owner: postgres
925928
--
926929

927-
GRANT ALL ON SEQUENCE public.agents_id_seq TO anon;
928-
GRANT ALL ON SEQUENCE public.agents_id_seq TO authenticated;
929-
GRANT ALL ON SEQUENCE public.agents_id_seq TO service_role;
930+
GRANT ALL ON SEQUENCE public.claw_agents_id_seq TO anon;
931+
GRANT ALL ON SEQUENCE public.claw_agents_id_seq TO authenticated;
932+
GRANT ALL ON SEQUENCE public.claw_agents_id_seq TO service_role;
930933

931934

932935
--

supabase/migrations/002_seed.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ INSERT INTO public.soul (key, content) VALUES
1111
('communication', 'Du kommunizierst mit dem User über Telegram. Die Chat-ID ist in der Nachricht enthalten. Du KANNST dem User direkt antworten – deine Antwort wird automatisch als Telegram-Nachricht gesendet. Du brauchst keinen extra Kanal.')
1212
ON CONFLICT (key) DO UPDATE SET content = EXCLUDED.content;
1313

14-
-- Agents: Tool instructions & config
15-
INSERT INTO public.agents (key, content) VALUES
14+
-- Agents: Tool instructions & config (table renamed agents -> claw_agents, Issue #35)
15+
INSERT INTO public.claw_agents (key, content) VALUES
1616
('mcp_instructions', 'Du hast MCP (Model Context Protocol) Fähigkeiten:
1717
1818
## MCP Client (mcp_client tool)
@@ -42,7 +42,7 @@ ON CONFLICT (path) DO UPDATE SET active = true;
4242

4343
-- Expert Agent Personas (default agents shipped with setup.sh)
4444
-- These are also seeded by setup.sh — this SQL serves as reference/backup
45-
INSERT INTO public.agents (key, content) VALUES
45+
INSERT INTO public.claw_agents (key, content) VALUES
4646
('persona:research-expert', '# Research Expert
4747
4848
## Expertise
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
-- ============================================================
2+
-- 009_agents_rename.sql — rename app table agents -> claw_agents
3+
-- ============================================================
4+
-- Fixes Issue #35: n8n >= 2.21.4 ships a core "Agents" feature whose
5+
-- migration CreateAgentTables1783000000000 creates a table named
6+
-- `agents` and indexes its `projectId` column. n8n-claw already owns
7+
-- `public.agents` (persona/config table) in the SAME database, so
8+
-- n8n's createTable no-ops, the createIndex on projectId fails, and
9+
-- n8n never boots.
10+
--
11+
-- Fix: move the n8n-claw data to `claw_agents`, freeing the `agents`
12+
-- name for n8n's own table.
13+
--
14+
-- Data-preserving, idempotent, and safe by design:
15+
-- * Only ever touches a public.agents table that has a `key` column.
16+
-- That uniquely identifies n8n-claw's table and NEVER matches
17+
-- n8n's core `agents` (which has no `key`). If n8n already created
18+
-- its own `agents`, the whole block is a no-op.
19+
-- * Two paths, because 001_schema.sql (which creates `claw_agents`)
20+
-- runs BEFORE this migration in setup.sh:
21+
-- - claw_agents does NOT exist yet -> plain RENAME (carries data).
22+
-- - claw_agents already exists (empty shell created by 001 on an
23+
-- upgrade) -> copy the legacy rows over, then DROP the legacy
24+
-- table to free the `agents` name.
25+
-- * Re-runs are no-ops once the legacy table is gone.
26+
-- ============================================================
27+
28+
DO $$
29+
BEGIN
30+
-- Act only if the LEGACY n8n-claw table (identified by `key`) still
31+
-- exists under the old name `agents`.
32+
IF EXISTS (
33+
SELECT 1 FROM information_schema.columns
34+
WHERE table_schema = 'public'
35+
AND table_name = 'agents'
36+
AND column_name = 'key'
37+
)
38+
THEN
39+
IF NOT EXISTS (
40+
SELECT 1 FROM information_schema.tables
41+
WHERE table_schema = 'public'
42+
AND table_name = 'claw_agents'
43+
)
44+
THEN
45+
-- claw_agents does not exist yet: rename in place (keeps all data).
46+
ALTER TABLE public.agents RENAME TO claw_agents;
47+
ALTER SEQUENCE IF EXISTS public.agents_id_seq RENAME TO claw_agents_id_seq;
48+
ELSE
49+
-- claw_agents already exists (created empty by 001 on an upgrade):
50+
-- move legacy rows over, then drop the legacy table to free `agents`.
51+
INSERT INTO public.claw_agents (key, content, updated_at)
52+
SELECT key, content, updated_at FROM public.agents
53+
ON CONFLICT (key) DO NOTHING;
54+
DROP TABLE public.agents;
55+
END IF;
56+
END IF;
57+
END $$;

workflows/agent-library-manager.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

workflows/mcp-builder.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@
568568
{
569569
"parameters": {
570570
"method": "PATCH",
571-
"url": "{{SUPABASE_URL}}/rest/v1/agents?key=eq.mcp_instructions",
571+
"url": "{{SUPABASE_URL}}/rest/v1/claw_agents?key=eq.mcp_instructions",
572572
"sendHeaders": true,
573573
"headerParameters": {
574574
"parameters": [

workflows/mcp-library-manager.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

workflows/n8n-claw-agent.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@
11191119
{
11201120
"parameters": {
11211121
"operation": "executeQuery",
1122-
"query": "SELECT key, content FROM agents WHERE key NOT LIKE 'persona:%' ORDER BY key",
1122+
"query": "SELECT key, content FROM claw_agents WHERE key NOT LIKE 'persona:%' ORDER BY key",
11231123
"options": {
11241124
"queryBatching": "independently"
11251125
}

workflows/sub-agent-runner.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
],
156156
"parameters": {
157157
"operation": "executeQuery",
158-
"query": "SELECT content FROM agents WHERE key = 'persona:' || '{{ $json.agent }}' LIMIT 1",
158+
"query": "SELECT content FROM claw_agents WHERE key = 'persona:' || '{{ $json.agent }}' LIMIT 1",
159159
"options": {
160160
"queryBatching": "independently"
161161
}

0 commit comments

Comments
 (0)