简体   繁体   English

如何在不覆盖实时数据的情况下更新来自测试数据库的实时数据库中列内的表

[英]How to update tables inside a column in a live database coming from test database without overriding live data

Suppose I have a live website running on a live database and I have a dev website that is a duplicate of the live website. 假设我有一个在实时数据库上运行的实时网站,并且我有一个与该实时网站重复的开发网站。

The live database is where customer transactions are stored. 实时数据库是存储客户交易的地方。

What if I do some changes on the dev website and dev database like add another column in a table, how can I retain all of the customer transaction inside live but at the same time saving all the changes I did from the test website to the live website? 如果我在开发网站和开发数据库上进行了一些更改(例如在表中添加另一列),该如何在实时状态下保留所有客户交易,但同时又将我从测试网站所做的所有更改保存到实时状态该怎么办?网站?

I am using Laravel and Mysql in case it will help to come up with a solution specifically for this tech stack. 我正在使用Laravel和Mysql,以防出现专门针对该技术堆栈的解决方案。

Typically you would stage the deployment of each of these changes and the steps you use would be the same in dev as production. 通常,您将分阶段部署这些更改,并且在开发中使用的步骤与在生产中使用的步骤相同。 In the case you describe where you are adding a column these are the steps I would take first testing them in development then applying them in production 在您描述要添加列的位置的情况下,这些步骤是我将首先在开发中对其进行测试,然后在生产中应用它们的步骤

  1. Add the column to the table in the database allowing nulls 将列添加到数据库的表中,允许空值
  2. Update the application code to start writing to the new column 更新应用程序代码以开始写入新列
  3. If every row is expected to have data in that column then start running a background process/scripts/sql to backfill the missing data 如果期望每一行的该列中都有数据,则开始运行后台进程/脚本/ sql以回填丢失的数据
  4. Update the column in the table to not allow nulls 更新表中的列以不允许为空
  5. Updated the application code to start reading from the new column 更新了应用程序代码以开始从新列中读取

The above steps come with the following assumptions: None of the application code is completing any SELECT * queries. 上面的步骤带有以下假设:没有应用程序代码可以完成任何SELECT *查询。 These can break if you add new unknown columns in step 1 and it's generally considered bad practice to have SELECT * queries for this reason. 如果您在步骤1中添加了新的未知列,则这些操作可能会中断,因此,出于这种原因,使用SELECT *查询通常被认为是不好的做法。

I'm assuming you have a tool that manages deployment of the code and versions. 我假设您有一个管理代码和版本部署的工具。 You should also consider having a database change management tool to track, version and deploy these types of database changes. 您还应该考虑使用数据库变更管理工具来跟踪,版本化和部署这些类型的数据库变更。 I've used liquibase in the past for this. 我过去使用过liquibase

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

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