-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
71 lines (56 loc) · 2.24 KB
/
Copy pathdeploy.py
File metadata and controls
71 lines (56 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
"""
Deploy workflow JSON to n8n SQLite database.
Usage:
python deploy.py # Deploy v2 (default)
python deploy.py telegram-notion-router.json # Deploy specific file
n8n reads active workflow from workflow_history table, NOT workflow_entity.
This script updates BOTH tables.
"""
import json, sqlite3, sys, os
WORKFLOW_DIR = os.path.dirname(os.path.abspath(__file__))
DB_PATH = os.path.expanduser('~/.n8n/database.sqlite')
ACTIVE_WF_ID = 'tFgnbVcc5hTGcRi1'
OTHER_WF_IDS = ['mR4M974piDwhNnCl', 'fYTIOwF7jb3wXqDp']
def deploy(workflow_file):
path = os.path.join(WORKFLOW_DIR, workflow_file)
if not os.path.exists(path):
print(f'ERROR: {path} not found')
sys.exit(1)
with open(path) as f:
wf = json.load(f)
nodes = json.dumps(wf['nodes'])
connections = json.dumps(wf['connections'])
name = wf.get('name', 'Telegram → Notion Todo Router v2')
conn = sqlite3.connect(DB_PATH)
# Update workflow_entity
conn.execute(
'UPDATE workflow_entity SET nodes=?, connections=?, active=1, name=? WHERE id=?',
(nodes, connections, name, ACTIVE_WF_ID)
)
# Update workflow_history (n8n reads from THIS table for execution)
conn.execute(
'UPDATE workflow_history SET nodes=?, connections=? WHERE workflowId=?',
(nodes, connections, ACTIVE_WF_ID)
)
# Deactivate other Telegram workflows
for oid in OTHER_WF_IDS:
conn.execute('UPDATE workflow_entity SET active=0 WHERE id=?', (oid,))
conn.commit()
# Verify
print('=== workflow_entity ===')
cur = conn.execute('SELECT id, name, active FROM workflow_entity ORDER BY active DESC, name')
for row in cur:
print(f' {"ON" if row[2] else "off"} | {row[0]} | {row[1]}')
print('\n=== workflow_history (latest) ===')
cur = conn.execute(
'SELECT workflowId, updatedAt FROM workflow_history WHERE workflowId=? ORDER BY updatedAt DESC LIMIT 1',
(ACTIVE_WF_ID,)
)
for row in cur:
print(f' {row[0]} | {row[1]}')
conn.close()
print(f'\nDeployed: {workflow_file} → {ACTIVE_WF_ID}')
if __name__ == '__main__':
wf_file = sys.argv[1] if len(sys.argv) > 1 else 'telegram-notion-router-v2.json'
deploy(wf_file)