azure - Azure CosmosDB 中的数据库对象(存储过程、触发器、UDf)自动化

标签 azure azure-cosmosdb azure-repos

我的一个项目由 Azure CosmosDB 中的存储过程、触发器、UDf 组成。我们希望将其自动化,以便轻松部署到不同的环境,例如开发 QA、生产,与使用基础设施即代码工具 Terraform 具有相同的效果

可能的解决方案之一是将它们同步到 Azure Repo,但目前似乎不支持。下面连接 GitHub 已禁用,并且不支持 Azure Repo。 enter image description here

任何其他解决方案的想法。

更新:

这是另一种解决方案,但仍然不是最好的。

https://learn.microsoft.com/en-us/azure/cosmos-db/sql/how-to-use-stored-procedures-triggers-udfs#stored-procedures

最佳答案

您可以使用 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
}

我会尝试使用与您已经使用的工具相同的工具来维护数据库容器。如果这在您的项目中没有意义,那么在这种特定情况下,我可能更喜欢 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/

相关文章:

git - 私有(private) GIT 存储库是否可用于 Microsoft TFS?

azure - 如何使用 REST API 禁用 Azure DevOps 中的分支策略?

Azure 培训套件旋转木马

c# - 同一线程可以在 Azure Functions 中同时运行多个函数吗?

c# - "MaxAutoRenewDuration"在azure服务总线中的作用是什么?

c# - 将文档添加到 Azure Cosmos DB 时缺少属性

nosql - 宇宙数据库 : collection & atomic counter

Azure VM无法连接到AWS s3

azure-cosmosdb - 带有 "ORDER BY"的 Azure 文档 DB 查询突然停止工作

azure - 如何将分支策略与Azure Repos中的工作项连接?