From 2755fb7236347e72257dcdf7d3bbb12d15af01a0 Mon Sep 17 00:00:00 2001 From: Vijay Ramakrishnan Date: Wed, 24 Jun 2020 19:26:16 -0700 Subject: [PATCH] Support for automatic db migration & restore --- .../Controllers/PortsOfEntryController.cs | 1 + .../RepresentativeDataController.cs | 1 + .../ScreeningDataTableController.cs | 1 + .../local/cosmosdb1.arm.json | 69 +++++++++++++++++++ .../Properties/serviceDependencies.json | 3 + .../Properties/serviceDependencies.local.json | 5 +- 6 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/COVIDScreeningApi/Properties/ServiceDependencies/local/cosmosdb1.arm.json diff --git a/src/COVIDScreeningApi/Controllers/PortsOfEntryController.cs b/src/COVIDScreeningApi/Controllers/PortsOfEntryController.cs index 90d603f..2968824 100644 --- a/src/COVIDScreeningApi/Controllers/PortsOfEntryController.cs +++ b/src/COVIDScreeningApi/Controllers/PortsOfEntryController.cs @@ -18,6 +18,7 @@ public class PortsOfEntryController : ControllerBase private readonly DataContext dataContext; private readonly IConfiguration configuration; public PortsOfEntryController (DataContext dataContext, IConfiguration configuration) { + dataContext.Database.EnsureCreated(); this.configuration = configuration; this.dataContext = dataContext; } diff --git a/src/COVIDScreeningApi/Controllers/RepresentativeDataController.cs b/src/COVIDScreeningApi/Controllers/RepresentativeDataController.cs index d14f2c8..7cd1c98 100644 --- a/src/COVIDScreeningApi/Controllers/RepresentativeDataController.cs +++ b/src/COVIDScreeningApi/Controllers/RepresentativeDataController.cs @@ -16,6 +16,7 @@ public class RepresentativeDataController : ControllerBase { private readonly DataContext dataContext; private readonly IConfiguration configuration; public RepresentativeDataController (DataContext dataContext, IConfiguration configuration) { + dataContext.Database.EnsureCreated(); this.configuration = configuration; this.dataContext = dataContext; } diff --git a/src/COVIDScreeningApi/Controllers/ScreeningDataTableController.cs b/src/COVIDScreeningApi/Controllers/ScreeningDataTableController.cs index f87ada7..2fe6ba1 100644 --- a/src/COVIDScreeningApi/Controllers/ScreeningDataTableController.cs +++ b/src/COVIDScreeningApi/Controllers/ScreeningDataTableController.cs @@ -16,6 +16,7 @@ public class ScreeningDataTableController : ControllerBase { private readonly IConfiguration configuration; private readonly DataContext dataContext; public ScreeningDataTableController (DataContext dataContext, IConfiguration configuration) { + dataContext.Database.EnsureCreated(); this.dataContext = dataContext; this.configuration = configuration; } diff --git a/src/COVIDScreeningApi/Properties/ServiceDependencies/local/cosmosdb1.arm.json b/src/COVIDScreeningApi/Properties/ServiceDependencies/local/cosmosdb1.arm.json new file mode 100644 index 0000000..792e9f2 --- /dev/null +++ b/src/COVIDScreeningApi/Properties/ServiceDependencies/local/cosmosdb1.arm.json @@ -0,0 +1,69 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "resourceGroupName": { + "type": "string", + "defaultValue": "covidScreeningApi", + "metadata": { + "_parameterType": "resourceGroup", + "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." + } + }, + "resourceGroupLocation": { + "type": "string", + "defaultValue": "westcentralus", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource group. Resource groups could have different location than resources." + } + }, + "resourceLocation": { + "type": "string", + "defaultValue": "[parameters('resourceGroupLocation')]", + "metadata": { + "_parameterType": "location", + "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." + } + } + }, + "resources": [ + { + "type": "Microsoft.Resources/resourceGroups", + "name": "[parameters('resourceGroupName')]", + "location": "[parameters('resourceGroupLocation')]", + "apiVersion": "2019-10-01" + }, + { + "type": "Microsoft.Resources/deployments", + "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('covidScreeningApi', subscription().subscriptionId)))]", + "resourceGroup": "[parameters('resourceGroupName')]", + "apiVersion": "2019-10-01", + "dependsOn": [ + "[parameters('resourceGroupName')]" + ], + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [ + { + "name": "covidScreeningApi", + "location": "[parameters('resourceLocation')]", + "type": "Microsoft.DocumentDB/databaseAccounts", + "kind": "GlobalDocumentDB", + "properties": { + "databaseAccountOfferType": "Standard" + }, + "apiVersion": "2015-04-08" + } + ] + } + } + } + ], + "metadata": { + "_dependencyType": "cosmosdb.azure" + } +} \ No newline at end of file diff --git a/src/COVIDScreeningApi/Properties/serviceDependencies.json b/src/COVIDScreeningApi/Properties/serviceDependencies.json index 6e3c77e..8aaafc9 100644 --- a/src/COVIDScreeningApi/Properties/serviceDependencies.json +++ b/src/COVIDScreeningApi/Properties/serviceDependencies.json @@ -1,5 +1,8 @@ { "dependencies": { + "secrets1": { + "type": "secrets" + }, "cosmosdb1": { "type": "cosmosdb", "connectionId": "CosmosDbConnectionString" diff --git a/src/COVIDScreeningApi/Properties/serviceDependencies.local.json b/src/COVIDScreeningApi/Properties/serviceDependencies.local.json index 8e27748..d4c6cc9 100644 --- a/src/COVIDScreeningApi/Properties/serviceDependencies.local.json +++ b/src/COVIDScreeningApi/Properties/serviceDependencies.local.json @@ -1,7 +1,10 @@ { "dependencies": { + "secrets1": { + "type": "secrets.user" + }, "cosmosdb1": { - "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroup')]/providers/Microsoft.DocumentDB/databaseAccounts/covid-screening-data", + "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/Microsoft.DocumentDB/databaseAccounts/covidScreeningApi", "type": "cosmosdb.azure", "connectionId": "CosmosDbConnectionString", "secretStore": "LocalSecretsFile"