Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Staging database predicament

Suppose that there are 3 databases for

  • Production
  • Staging
  • Dev

As far as I know, Staging database need to be in sync with Production database But,

When we are developing, we can do whatever we want with Dev database and change schema. Now here comes the Chicken & Egg problem.

To test in Staging, Staging database schema need to be changed according to changes made in Dev database. But the Staging database need to be in sync with Production.

How do you guys get around this problem?

like image 624
dance2die Avatar asked Jan 16 '09 18:01

dance2die


People also ask

What is staging in database?

A staging database is a user-created PDW database that stores data temporarily while it is loaded into the appliance.

What is the benefit of staging database?

A Staging database assists in getting your source data into structures equivalent with your data warehouse FACT and DIMENSION destinations. It also decouples your warehouse and warehouse ETL process from your source data.

What is staging database in ETL?

A temporary storage area in which data is processed during an extract, transform and load procedure.

Should staging use production database?

The staging environment must be isolated with no connections to any part of the production environment, including the production database.


1 Answers

You need to write all of you changes to the dev database as SQL migration scripts that get run in a certain order. Do not change the database structure unless it is in a script. Do not update, insert or delete any rows unless it is in a script.

Ideally have a way to track which scripts have been run against any version of the database you find.

Then you can update stage as follows.

  • Dump production database
  • Populate stage database with production dump
  • Run migrations in stage
  • Check migration worked (unit tests, manual checks)

Once everything works ...

  • Dump prod database with mysqldump command (as it may have changed) keeping backup on server
  • Run migrations on prod
  • Test migration has worked on prod
  • Drink beer (while watching error logs)
like image 108
RichH Avatar answered Sep 21 '22 10:09

RichH