繁体   English   中英

来自 Azure CosmosDB 的数据库对象(存储过程、触发器、UDfs)的自动化

[英]Automation of Database objects (Stored Procs, Triggers, UDfs) from Azure CosmosDB

我的一个项目包括 Azure CosmosDB 中的存储过程、触发器、UDf。 我们希望将其自动化,以便轻松部署到不同的环境,例如 Dev QA、Prod,与使用基础架构即代码工具的效果相同,Terraform

一种可能的解决方案是将它们同步到 Azure Repo,但目前似乎不受支持。 下面连接GitHub被禁用,不支持Azure Repo。 在此处输入图像描述

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

更新:

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

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 模板文件中维护 function 代码会非常麻烦。

使用此命令,您可以将sproc.js文件的内容上传为 function 正文:

az cosmosdb sql stored-procedure create \
    --account-name myaccount \
    --body @sproc.js \
    --container-name mycontainer  \
    --database-name mydb \
    --name myfunc \
    --resource-group myrg

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM