fix: enum 写入 PG 用 value 而非 name
Source/SourceKind、UserRole、SubscriptionMatch 三个 enum 改用 values_callable 保证 PG 看到 'rss' / 'owner' / 'any' 等小写 value,而非 'RSS' 大写 name。 seed_sources 同步改为显式字符串。
This commit is contained in:
@@ -32,7 +32,11 @@ class Source(Base):
|
|||||||
name: Mapped[str] = mapped_column(String(128), nullable=False)
|
name: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||||
slug: Mapped[str] = mapped_column(String(128), unique=True, index=True, nullable=False)
|
slug: Mapped[str] = mapped_column(String(128), unique=True, index=True, nullable=False)
|
||||||
kind: Mapped[SourceKind] = mapped_column(
|
kind: Mapped[SourceKind] = mapped_column(
|
||||||
Enum(SourceKind, name="source_kind"),
|
Enum(
|
||||||
|
SourceKind,
|
||||||
|
name="source_kind",
|
||||||
|
values_callable=lambda x: [e.value for e in x],
|
||||||
|
),
|
||||||
default=SourceKind.RSS,
|
default=SourceKind.RSS,
|
||||||
nullable=False,
|
nullable=False,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,7 +34,11 @@ class Subscription(Base):
|
|||||||
keyword: Mapped[str] = mapped_column(String(255), nullable=False)
|
keyword: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||||
# 简单关键词,匹配走 ILIKE '%kw%';后续可加 regex/lucene
|
# 简单关键词,匹配走 ILIKE '%kw%';后续可加 regex/lucene
|
||||||
match_in: Mapped[SubscriptionMatch] = mapped_column(
|
match_in: Mapped[SubscriptionMatch] = mapped_column(
|
||||||
Enum(SubscriptionMatch, name="subscription_match"),
|
Enum(
|
||||||
|
SubscriptionMatch,
|
||||||
|
name="subscription_match",
|
||||||
|
values_callable=lambda x: [e.value for e in x],
|
||||||
|
),
|
||||||
default=SubscriptionMatch.ANY,
|
default=SubscriptionMatch.ANY,
|
||||||
nullable=False,
|
nullable=False,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -26,7 +26,11 @@ class User(Base):
|
|||||||
email: Mapped[str | None] = mapped_column(String(255), unique=True, index=True)
|
email: Mapped[str | None] = mapped_column(String(255), unique=True, index=True)
|
||||||
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||||
role: Mapped[UserRole] = mapped_column(
|
role: Mapped[UserRole] = mapped_column(
|
||||||
Enum(UserRole, name="user_role"),
|
Enum(
|
||||||
|
UserRole,
|
||||||
|
name="user_role",
|
||||||
|
values_callable=lambda x: [e.value for e in x],
|
||||||
|
),
|
||||||
default=UserRole.MEMBER,
|
default=UserRole.MEMBER,
|
||||||
nullable=False,
|
nullable=False,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,13 +18,14 @@ from sqlalchemy.dialects.postgresql import insert as pg_insert
|
|||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
from app.database import AsyncSessionLocal
|
from app.database import AsyncSessionLocal
|
||||||
from app.models.source import Source, SourceKind
|
from app.models.source import Source
|
||||||
|
|
||||||
|
# 用字符串避免 SQLAlchemy 把 enum 写成 name(大写)而非 value(小写)
|
||||||
SEEDS = [
|
SEEDS = [
|
||||||
{
|
{
|
||||||
"name": "Reuters World",
|
"name": "Reuters World",
|
||||||
"slug": "reuters-world",
|
"slug": "reuters-world",
|
||||||
"kind": SourceKind.RSS,
|
"kind": "rss",
|
||||||
"url": "https://feeds.reuters.com/Reuters/worldNews",
|
"url": "https://feeds.reuters.com/Reuters/worldNews",
|
||||||
"region": "global",
|
"region": "global",
|
||||||
"language_src": "en",
|
"language_src": "en",
|
||||||
@@ -36,7 +37,7 @@ SEEDS = [
|
|||||||
{
|
{
|
||||||
"name": "BBC World",
|
"name": "BBC World",
|
||||||
"slug": "bbc-world",
|
"slug": "bbc-world",
|
||||||
"kind": SourceKind.RSS,
|
"kind": "rss",
|
||||||
"url": "https://feeds.bbci.co.uk/news/world/rss.xml",
|
"url": "https://feeds.bbci.co.uk/news/world/rss.xml",
|
||||||
"region": "global",
|
"region": "global",
|
||||||
"language_src": "en",
|
"language_src": "en",
|
||||||
@@ -48,7 +49,7 @@ SEEDS = [
|
|||||||
{
|
{
|
||||||
"name": "Al Jazeera",
|
"name": "Al Jazeera",
|
||||||
"slug": "aljazeera",
|
"slug": "aljazeera",
|
||||||
"kind": SourceKind.RSS,
|
"kind": "rss",
|
||||||
"url": "https://www.aljazeera.com/xml/rss/all.xml",
|
"url": "https://www.aljazeera.com/xml/rss/all.xml",
|
||||||
"region": "mena",
|
"region": "mena",
|
||||||
"language_src": "en",
|
"language_src": "en",
|
||||||
@@ -60,7 +61,7 @@ SEEDS = [
|
|||||||
{
|
{
|
||||||
"name": "NHK World",
|
"name": "NHK World",
|
||||||
"slug": "nhk-world",
|
"slug": "nhk-world",
|
||||||
"kind": SourceKind.RSS,
|
"kind": "rss",
|
||||||
"url": "https://www3.nhk.or.jp/rss/news/cat0.xml",
|
"url": "https://www3.nhk.or.jp/rss/news/cat0.xml",
|
||||||
"region": "asia",
|
"region": "asia",
|
||||||
"language_src": "en",
|
"language_src": "en",
|
||||||
@@ -72,7 +73,7 @@ SEEDS = [
|
|||||||
{
|
{
|
||||||
"name": "DW (Deutsche Welle)",
|
"name": "DW (Deutsche Welle)",
|
||||||
"slug": "dw",
|
"slug": "dw",
|
||||||
"kind": SourceKind.RSS,
|
"kind": "rss",
|
||||||
"url": "https://rss.dw.com/xml/rss-en-all",
|
"url": "https://rss.dw.com/xml/rss-en-all",
|
||||||
"region": "eu",
|
"region": "eu",
|
||||||
"language_src": "en",
|
"language_src": "en",
|
||||||
|
|||||||
@@ -1,23 +1,24 @@
|
|||||||
import os, paramiko
|
import os, paramiko
|
||||||
HOST, PORT, USER = "207.57.129.228", 19717, "root"
|
|
||||||
PW = os.environ["REMOTE_PASS"]
|
PW = os.environ["REMOTE_PASS"]
|
||||||
c = paramiko.SSHClient()
|
c = paramiko.SSHClient()
|
||||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
c.connect(HOST, port=PORT, username=USER, password=PW, timeout=15, allow_agent=False, look_for_keys=False)
|
c.connect("207.57.129.228", port=19717, username="root", password=PW, timeout=15, allow_agent=False, look_for_keys=False)
|
||||||
|
|
||||||
# 1) 推更新后的部署脚本
|
def run(cmd, t=30):
|
||||||
sftp = c.open_sftp()
|
si, so, se = c.exec_command(cmd, timeout=t)
|
||||||
sftp.put("D:/selftools/diary-news/scripts/deploy_remote.sh", "/root/deploy_news.sh")
|
out = so.read().decode("utf-8", "replace")
|
||||||
sftp.chmod("/root/deploy_news.sh", 0o755)
|
err = se.read().decode("utf-8", "replace")
|
||||||
sftp.close()
|
rc = so.channel.recv_exit_status()
|
||||||
print("[ok] script pushed")
|
print(f"$ {cmd}")
|
||||||
|
if out: print(out, end="")
|
||||||
|
if err: print("[err]", err, end="", file=__import__("sys").stderr)
|
||||||
|
print(f" rc={rc}")
|
||||||
|
|
||||||
# 2) 杀掉旧进程(若有)
|
# 1) 服务器 git pull
|
||||||
si, so, se = c.exec_command("pkill -f deploy_news.sh 2>/dev/null; sleep 2; echo done")
|
run("cd /srv/news && sudo -u news git pull --rebase 2>&1 | tail -10")
|
||||||
print(so.read().decode().strip())
|
|
||||||
|
|
||||||
# 3) 后台启动,设 SSHD_PORT=19717
|
# 2) 重跑部署脚本(直接重跑,前面的 docker 镜像已构建缓存)
|
||||||
|
run("pkill -f deploy_news.sh 2>/dev/null; sleep 2; rm -f /root/deploy_news.log; echo ===restart===")
|
||||||
si, so, se = c.exec_command("nohup env SSHD_PORT=19717 bash /root/deploy_news.sh > /root/deploy_news.log 2>&1 & echo $!", timeout=10)
|
si, so, se = c.exec_command("nohup env SSHD_PORT=19717 bash /root/deploy_news.sh > /root/deploy_news.log 2>&1 & echo $!", timeout=10)
|
||||||
pid = so.read().decode().strip()
|
print(f"deploy started, PID={so.read().decode().strip()}")
|
||||||
print(f"[ok] deploy started, PID={pid}")
|
|
||||||
c.close()
|
c.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user