SuperAPI AI 工具集

github-actions-for-sql

数据与分析

查看项目

更新于 10-16 00:32

技能介绍

用途:从 GitHub Actions 工作流把数据库架构发布到 Azure SQL Database,使用 azure/sql-action(资料核对至 v2.4)。它负责流水线本身:工作流、登录、防火墙与门禁,不负责数据库项目、变更顺序、数据库侧授权或应用部署。

主要能力:该 action 实际组合三条命令。先做防火墙探测:sqlcmd -S <server>.database.windows.net,1433 -d master --authentication-method=ActiveDirectoryDefault -Q "SELECT 'Validating connection from GitHub SQL Action'",先对 master 再对目标库执行。若路径为 .sqlproj 则构建:dotnet build "./db/ShopDb.sqlproj" -p:NetCoreBuild=true。随后部署:sqlpackage /Action:Publish /TargetConnectionString:"..." /SourceFile:"./db/bin/Debug/ShopDb.dacpac"。输入包括 connection-string、path(.sql、.dacpac 或 .sqlproj,glob 须恰好匹配一个文件)、action(.dacpac/.sqlproj 必填,仅支持 Publish、Script、DriftReport、DeployReport)、arguments、build-arguments、skip-firewall-check、sqlpackage-path。

使用方式:连接字符串用 Active Directory Default 等基于身份的写法避免数据库密码;用工作流令牌联合身份避免客户端密钥,需 permissions: id-token: write。subject 不要自行拼接,先用 gh api repos/OWNER/REPO/actions/oidc/customization/sub 读取 sub_claim_prefix,再追加 :ref:refs/heads/<branch>、:ref:refs/tags/<tag>、:environment:<name> 或 :pull_request,并用 az identity federated-credential create 创建凭据。托管运行器需能写服务器防火墙规则,action 会临时添加 ClientIPAddress_ 规则并在 finally 中删除。

限制与注意:不支持 macOS 运行器(dacpac 与项目路径);Extract、Import、Export 被拒绝;运行器自带 sqlcmd 但不含 SqlPackage,Linux 上需 dotnet tool install -g microsoft.sqlpackage。登录失败常被报成防火墙失败,应向上读 AADSTS700213 行;不要因登录步骤末尾的 auth-type 提示而改配置或回退到密钥。环境审批只约束命名该环境的作业,凭据 subject 才是真正绑定。部署可能较慢,Basic 层单表发布实测约 3 分 16 秒。其余细节资料未提供。