feat: Install sqlx-cli if not present and run database migrations during setup

This commit is contained in:
2026-02-25 22:26:02 +08:00
parent d0b6e37ae5
commit 5d7eef29e8

View File

@@ -238,9 +238,14 @@ RestartSec=5
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
# 运行数据库迁移 # 安装 sqlx-cli若未安装运行数据库迁移
export PATH="$HOME/.cargo/bin:$PATH"
if ! command -v sqlx &> /dev/null; then
cargo install sqlx-cli --no-default-features --features postgres
fi
cd $INSTALL_DIR/src/server cd $INSTALL_DIR/src/server
DATABASE_URL="postgres://funmc:${DB_PASSWORD}@localhost/funmc" cargo sqlx migrate run export DATABASE_URL="postgres://funmc:${DB_PASSWORD}@localhost/funmc"
sqlx migrate run
# 启动服务 # 启动服务
systemctl daemon-reload systemctl daemon-reload