Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you manage databases in development, test, and production?

Tags:

mysql

svn

People also ask

What is a database in software testing?

Database Testing is a type of software testing that checks the schema, tables, triggers etc. of the database under test. It involves creating complex queries for performing the load or stress test on the database and check its responsiveness. It checks integrity and consistency of data.

What is used for database testing?

DbFit is an open-source database testing tool for performing unit and integration testing for database. It supports several databases such as Oracle, SQL Server, DB2, PostgreSQL, MySQL etc. It is a part of FitNesse and manages stored procedures and custom procedures.


There are a couple of good options. I wouldn't use the "restore a backup" strategy.

  1. Script all your schema changes, and have your CI server run those scripts on the database. Have a version table to keep track of the current database version, and only execute the scripts if they are for a newer version.

  2. Use a migration solution. These solutions vary by language, but for .NET I use Migrator.NET. This allows you to version your database and move up and down between versions. Your schema is specified in C# code.


Your developers need to write change scripts (schema and data change) for each bug/feature they work on, not just simply dump the entire database into source control. These scripts will upgrade the current production database to the new version in development.

Your build process can restore a copy of the production database into an appropriate environment and run all the scripts from source control on it, which will update the database to the current version. We do this on a daily basis to make sure all the scripts run correctly.


Have a look at how Ruby on Rails does this.

First there are so called migration files, that basically transform database schema and data from version N to version N+1 (or in case of downgrading from version N+1 to N). Database has table which tells current version.

Test databases are always wiped clean before unit-tests and populated with fixed data from files.


The book Refactoring Databases: Evolutionary Database Design might give you some ideas on how to manage the database. A short version is readable also at http://martinfowler.com/articles/evodb.html

In one PHP+MySQL project I've had the database revision number stored in the database, and when the program connects to the database, it will first check the revision. If the program requires a different revision, it will open a page for upgrading the database. Each upgrade is specified in PHP code, which will change the database schema and migrate all existing data.


You could also look at using a tool like SQL Compare to script the difference between various versions of a database, allowing you to quickly migrate between versions


  • Name your databases as follows - dev_<<db>> , tst_<<db>> , stg_<<db>> , prd_<<db>> (Obviously you never should hardcode db names
  • Thus you would be able to deploy even the different type of db's on same physical server ( I do not recommend that , but you may have to ... if resources are tight )
  • Ensure you would be able to move data between those automatically
  • Separate the db creation scripts from the population = It should be always possible to recreate the db from scratch and populate it ( from the old db version or external data source
  • do not use hardcode connection strings in the code ( even not in the config files ) - use in the config files connection string templates , which you do populate dynamically , each reconfiguration of the application_layer which does need recompile is BAD
  • do use database versioning and db objects versioning - if you can afford it use ready products , if not develop something on your own
  • track each DDL change and save it into some history table ( example here )
  • DAILY backups ! Test how fast you would be able to restore something lost from a backup (use automathic restore scripts
  • even your DEV database and the PROD have exactly the same creation script you will have problems with the data, so allow developers to create the exact copy of prod and play with it ( I know I will receive minuses for this one , but change in the mindset and the business process will cost you much less when shit hits the fan - so force the coders to subscript legally whatever it makes , but ensure this one