Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""Force-run db migration on server"""
|
|
import paramiko
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
VENV_PY = "/opt/douyinWEB/backend/.venv/bin/python"
|
|
|
|
MIGRATE_PY = r"""
|
|
import sys
|
|
sys.path.insert(0, '/opt/douyinWEB/backend')
|
|
from app import db
|
|
db.init_db()
|
|
print("init_db DONE")
|
|
|
|
import sqlite3
|
|
conn = sqlite3.connect('/opt/douyinWEB/backend/data/monitor.db')
|
|
for tbl in ['rooms','sessions','events','channel_groups']:
|
|
cols = [r[1] for r in conn.execute(f'PRAGMA table_info({tbl})')]
|
|
print(f'{tbl}: {cols}')
|
|
conn.close()
|
|
"""
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
sftp = c.open_sftp()
|
|
with sftp.open("/tmp/_migrate.py", "w") as f:
|
|
f.write(MIGRATE_PY)
|
|
sftp.close()
|
|
|
|
_s, out, err = c.exec_command(f"cd /opt/douyinWEB/backend && {VENV_PY} /tmp/_migrate.py 2>&1", timeout=60)
|
|
print(out.read().decode("utf-8","replace").strip())
|
|
|
|
# restart
|
|
_s, out, err = c.exec_command("systemctl restart douyinweb-api; sleep 6; systemctl is-active douyinweb-api", timeout=20)
|
|
print("API:", out.read().decode().strip())
|
|
|
|
c.close()
|