简体   繁体   English

如何在数据库中的连接字符串处触发迁移

[英]How to fire migration where connection string is in database

In my application, there are multiple tenants and for each tenant we have created new database. 在我的应用程序中,有多个租户,并且为每个租户创建了新数据库。 So for new development, when we need to change some table structure we need to fire migration commands for each tenant db. 因此,对于新开发,当我们需要更改某些表结构时,我们需要为每个租户数据库触发迁移命令。

Is there any way to execute migration command on dynamic connection strings in one shot? 一口气可以对动态连接字符串执行迁移命令吗? Our connection string is in DB. 我们的连接字符串在DB中。

Thanks in advance. 提前致谢。

I think it is not possible to execute migrations on several databases in one shot. 我认为不可能一口气在多个数据库上执行迁移。 You have to call the migration command for every single connection string in a loop. 您必须为循环中的每个单个连接字符串调用迁移命令。

You can either call it programatically with C# or create a Powershell script that runs migrate.exe. 您可以使用C#以编程方式调用它,也可以创建运行migration.exe的Powershell脚本。

We use the second option in our deployment, so that database migrations are an explicit step in the release pipeline. 我们在部署中使用第二个选项,因此数据库迁移是发布管道中的明确步骤。

Migrate.exe has a parameter to provide the connection string. Migrate.exe具有提供连接字符串的参数。 See here for more details. 请参阅此处了解更多详细信息。

暂无
暂无

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

相关问题 如何在命令行上更改连接字符串以在迁移到Entity Framework Core中的新数据库时更新数据库 - How to change connection string on command line to update database on migration to a new database in Entity Framework Core 如何强制迁移使用客户端上下文的连接字符串触发了迁移 - How to force the migration to use connection string of the client context triggered the migration 我应该在哪里放置我的数据库连接字符串以及如何处理连接池? - Where should I place my database connection string and how do I handle connection pooling? 迁移如何将连接字符串传递到库项目(.netStandard) - Migration How to pass Connection String into Library Project (.netStandard) 如何在实体框架迁移中获取当前连接字符串? - How to get the current connection string inside an Entity Framework migration? 无法运行在运行时设置 DbContext 连接字符串并将项目与应用程序分开的 EF 迁移 - Can't run EF migration where DbContext connection string is set at runtime and separate project from application EntityFramework在哪里获得到本地数据库的连接字符串? - Where does EntityFramework get the connection string to my local database? 找不到我的数据库文件和连接字符串所在的位置? - Unable to find where my database file and connection string is located? 将数据库代码移动到单独的程序集时将连接字符串放在哪里 - Where to put connection string when moving database code to separate assembly 多数据库连接字符串:将其存储在我的应用程序中的位置 - Multi-database connection string: where store it in my application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM