I have a multi-tenancy nestjs app, where i have a public schema to keep track of the tenants and each tenant has their own schema ('tenant__*').
Is there a recommended way to migrate those schemas?
Do i have to create migration files for each tenant, or is there a way to manage them all through a template schema? Id like to try the template schema strategy but i cant run a template schema migration for multiple tenant-schemas because its static sql and without a dynamic schema reference.
Similar issue:
https://github.com/mikro-orm/mikro-orm/issues/681
Related
I am trying to speed up my resource management in the azure portal, and to do so I need to assign a role to a UserIdentity which will allow it to create and manage database's and containers, in both the SQL databases and the Gremlin database.
I can get it to work by manually adding permissions in the portal, and I can get the reading and writing of data work using custom roles, but I can't find what role definitions to use, as they seem to not be accessible in custom roles.
I was trying "Microsoft.DocumentDb/databaseAccounts/" which gives the error, The provided data action string [Microsoft.DocumentDb/databaseAccounts/] does not correspond to any valid SQL data action,even though its listed in the roles.
Any help would be appreciated.
I am developing a Saas based application which has hybrid DB architecture (Azure SQL Server and Azure Cosmos DB).
To manage SQL Server Tables, Stored procedures, triggers and functions we will create a SQLDB project (.sqlproj). Also we can generate .dacpac and deploy in the sql server.
As like SQL, we will have collections, stored procedures, triggers and functions in Azure CosmosDB.
How to manage CosmosDB collection, procedure, trigger? Is there any project templete available to manage? Suggest a solution to proceed.
Based on my experience with CosmosDb, I believe there is nothing sort of project templates available for CosmosDb. Because it is not as easy as SQL Db project.
I suggest you will have to store them as json files in local solution version control and version them accordingly.
You could write necessary programming logic to execute these scripts/cosmos DB logic using SQL API for .NET or another platform. This way you are controlling the collections, udf, triggers etc from your code, and you can version your code accordingly.
More references here: https://learn.microsoft.com/en-us/azure/cosmos-db/programming
Azure CosmosDBs can be managed through ARM templates. You can use these to version your databases/collections/etc. See Microsoft.DocumentDB resource types documentation.
I am trying to setup continuous deployment for a group of Azure databases that all share the same schema. In my situation, there are a number of dynamic databases that get created via copying and renaming a standard template. The software will make a copy of the CompanyTemplate database and rename it to Company_XXXX.
I would like to create a Task Group and/or a script in VSTS (hosted) that can query the master database, get a list of the company database names and then loop said Task Group in order to deploy the same schema and scripts to each of the Company databases that get created.
I have been Googling and testing odds and ends for days but I cannot find anything pertaining to how this can be done. Any thoughts? Is this possible?
There is no loop concept in the VSTS Build/Release environment.
There are a few workarounds that sprint to mind:
Run a powershell script and implement the logic there. Using the loop constructs in Powershell.
Run a powershell to trigger as many builds as you want using the REST API.
To begin with, I want to acknowledge that reading the answer from #jessehouwing triggered a few thoughts on my end.
As he mentions in his answer, there isn't anything that would directly do what you're asking. However, some techniques do come to mind, depending on how you want to deploy the databases.
ARM Templates -
Setup an ARM template that uses Resource Iteration to deploy multiple Azure SQL Databases. (See MS DOCS on how to do that). Configure the template to copy the schema of an existing DB to the new ones. You'll need that template DB deployed to Azure to act as the schema source. To configure the ARM template to create the new databases as a copy of the template, look at the createMode property of the SQL Database ARM template (SQL ARM Template documentation).
Run a Powershell script that queries the master DB to get the list of companies (Query DB from Powershell).
Output the results of the DB query to a VSTS variable and pass that variable into the ARM template to produce the databases.
DACPAC -
Create a DACPAC from a SQL DB Project in Visual Studio.
You can either create a DACPAC that defines just the DB schema and use the ARM template technique above to run the DACPAC for each database you need in something of a hybrid technique - or
You can create a dacpac that queries your main DB for the list of
companies and creates a database for each one based on the defined
schema. This options encapsulates the process of creating the schema
and querying the main DB for the ones to create all into a single
deployment artifact
Each option has its Pros and Cons. The ARM Template option is going to give you the most flexibility, but requires that you have a template DB in place to copy from.
The DACPAC option requires familiarity with using that technique for deploying databases and may still require an ARM template to make the process as flexible as possible. It does offer the potential to encapsulate all the DB deployment parts into a single step.
There are a fair number of variables here, but I think this should give you some options to consider that will take you in a workable direction.
When deploying a Cosmos Db database in GlobalDocumentDB mode using the Azure resource manager template there is no way to configure collections in the database during deployment that I can tell.
During a ARM template deployment is there any way to either (in order of preference)
Configure the collections in a Cosmos Db database directly in a way that I have overlooked.
Do a series of REST requests from within the template to configure the db.
Do a single REST request within the template to hit a Azure Function with a HttpTrigger that will configure the database.
You should be able to use these Templates.
Containers:
https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/2015-04-08/databaseaccounts/apis/databases/containers
Collections:
https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/2015-04-08/databaseaccounts/apis/databases/collections
All Microsoft.DocumentDB Resource Types:
https://learn.microsoft.com/en-us/azure/templates/microsoft.documentdb/allversions
These pages were published on 05/01/2019 & are for API version 2015-04-08.
ARM templates is used to create Azure resources, there is no way to configure collection during deploy ARM template. To configure collections, I suggest you use REST API. Before creating a collection, we need to create a database first. Following are documents which show us how to create DocumentDB databases and collections.
Create Database
Create Collection
I have created a database using a SPDatabase class.
How can i add a table to it?
and how to execute SQL queries in this database?
Thanx....
Create a seperate, additional database for your custom data to use in SharePoint and just connect it like you do with any ASP.NET database.