# Separating Testa Data from Production Data

**URL:** <https://forum.liquibase.org/t/separating-testa-data-from-production-data/5819>\
**Category:** Community Answers\
**Created:** [August 20, 2021, 7:54am UTC](https://forum.liquibase.org/t/separating-testa-data-from-production-data/5819 "2021-08-20T07:54:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soffermann](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@soffermann](https://forum.liquibase.org/u/soffermann)\
**Post date:** [August 20, 2021, 7:54am UTC](https://forum.liquibase.org/t/separating-testa-data-from-production-data/5819/1 "2021-08-20T07:54:15Z")

</div>

We need a way to unit-test the database layer and make sure the test data stored in the database is up-to-date with the latest database schema.

[This article](https://www.liquibase.org/blog/unit-testing-database-access-layer) suggests to use the Liquibase [execution context](https://docs.liquibase.com/concepts/contexts.html? __hstc=128893969.6b892e787015414107733320e6188237.1612171832688.1624510616341.1629444374271.8&__ hssc=128893969.1.1629444374271&__hsfp=2230120939&_ga=2.10557492.1451558365.1629444372-457649775.1601016527) feature for that purpose, but unfortunately that feature, in its current state, is not usable for us, because there does not seem to be a way to make sure that the test data is ONLY loaded when the test context is provided explicitly. If you omit the context, EVERYTHING, including the data tagged with the test context, is loaded by default.

How do you guys tackle this problem?

Thanks for any input,  
Steffen

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [August 20, 2021, 11:33am UTC](https://forum.liquibase.org/t/separating-testa-data-from-production-data/5819/2 "2021-08-20T11:33:15Z")

</div>

Once you start using Liquibase contexts, you need to ensure that a context is provided for all environments at runtime, in order to prevent the scenario that you described from occurring.

Scenario: you have 3 environments (“dev”,“test”,“prod”). You have a changeset that is “test” only, so you code context “test” into that changeset. Even though you are only using context “test”, you will still need to provide the proper context at runtime for all environments (“dev”, “test”, and “prod”). This will prevent the “test” changeset from deploying to “dev” and “prod”.

Examples:

–dev deployment  
liquibase --changeLogFile=changelog.xml --contexts=“dev” update

–test deployment  
liquibase --changeLogFile=changelog.xml --contexts=“test” update

–prod deployment  
liquibase --changeLogFile=changelog.xml --contexts=“prod” update

---

<div class="post-metadata">

**Author:** ![soffermann](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@soffermann](https://forum.liquibase.org/u/soffermann)\
**Post date:** [August 20, 2021, 11:35am UTC](https://forum.liquibase.org/t/separating-testa-data-from-production-data/5819/3 "2021-08-20T11:35:28Z")

</div>

Thanks for your response. That’s bad, because that means we cannot use this feature (the existing changesets are run by our users in production). ☹

---

<div class="post-metadata">

**Author:** ![rgrzegorczyk](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@rgrzegorczyk](https://forum.liquibase.org/u/rgrzegorczyk)\
**Post date:** [August 25, 2021, 2:15pm UTC](https://forum.liquibase.org/t/separating-testa-data-from-production-data/5819/4 "2021-08-25T14:15:29Z")

</div>

@soffermann  
In my projects we sometimes do that way:

- add preConditions to changesets and check the existence of some value e.g SELECT environment FROM parameters.
- and check the value of this column
- if it’s TEST then execute sth, if PROD then do sth else or do not execute

---

<div class="post-metadata">

**Author:** ![soffermann](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@soffermann](https://forum.liquibase.org/u/soffermann)\
**Post date:** [August 26, 2021, 5:20am UTC](https://forum.liquibase.org/t/separating-testa-data-from-production-data/5819/5 "2021-08-26T05:20:14Z")

</div>

Thanks! Yes, that’s very similar to the solution we came up with, but we are using a custom precondition and check for the value of a Java system property. 🙂

[See this thread, too](https://forum.liquibase.org/t/changeset-with-context-executied-even-though-no-context-was-specified/2151)!
