我的一个项目由 Azure CosmosDB 中的存储过程、触发器、UDf 组成。我们希望将其自动化,以便轻松部署到不同的环境,例如开发 QA、生产,与使用基础设施即代码工具 Terraform 具有相同的效果
可能的解决方案之一是将它们同步到 Azure Repo,但目前似乎不支持。下面连接 GitHub 已禁用,并且不支持 Azure Repo。
任何其他解决方案的想法。
更新:
这是另一种解决方案,但仍然不是最好的。
最佳答案
您可以使用 ARM/Bicep 模板、AzureCLI、Azure Powershell 和各种 SDK 来管理 SQL 资源。您甚至可以使用 Terraform:
resource "azurerm_cosmosdb_sql_stored_procedure" "example" {
name = "test-stored-proc"
resource_group_name = azurerm_cosmosdb_account.example.resource_group_name
account_name = azurerm_cosmosdb_account.example.name
database_name = azurerm_cosmosdb_sql_database.example.name
container_name = azurerm_cosmosdb_sql_container.example.name
body = <<BODY
function () { var context = getContext(); var response = context.getResponse(); response.setBody('Hello, World'); }
BODY
}
- ARM 模板:Azure Cosmos DB container with server-side functionality
- Azure CLI:
az cosmosdb sql stored-procedure create
我会尝试使用与您已经使用的工具相同的工具来维护数据库容器。如果这在您的项目中没有意义,那么在这种特定情况下,我可能更喜欢 AzureCLI 而不是 ARM 模板,因为在 ARM 模板文件中维护函数代码非常麻烦。
使用此命令,您可以上传 sproc.js
文件的内容作为函数体:
az cosmosdb sql stored-procedure create \
--account-name myaccount \
--body @sproc.js \
--container-name mycontainer \
--database-name mydb \
--name myfunc \
--resource-group myrg
关于azure - Azure CosmosDB 中的数据库对象(存储过程、触发器、UDf)自动化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71157976/