Last active
January 10, 2023 13:19
-
-
Save joshowen/a0cb87a156f659ad99c0 to your computer and use it in GitHub Desktop.
CircleCI hack for saving keeping databases in build cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Notes: | |
# - Replace <DB_NAME> with your database | |
# - Replace <SOME_PROJECT_WITH_A_TEST> with an appname that has an integration test, this will run your migrations | |
database: | |
override: | |
# Preserve Postgres in cache | |
- sudo service postgresql stop || exit 0 | |
- "if [ -d ~/postgres/ ]; then sudo cp -r ~/postgres/* /var/lib/postgresql/9.4; sudo chown -R postgres:postgres /var/lib/postgresql/9.4/*; fi" | |
- sudo service postgresql start || exit 0 | |
- if [ `psql -t -c "SELECT 1 FROM pg_database WHERE datname = '<DB_NAME>'"` -eq 1 ] ; then echo "Database already exists"; else psql -c 'create database <DB_NAME>;'; fi | |
- python manage.py migrate --noinput --verbosity 2 | |
# Create test DBs | |
- python manage.py test <SOME_PROJECT_WITH_A_TEST> --keepdb --noinput | |
# Preserve Postgres in cache | |
- "[ -d ~/postgres ] || mkdir ~/postgres" | |
- sudo service postgresql stop || exit 0 | |
- "sudo cp -r /var/lib/postgresql/9.4/* ~/postgres/" | |
- sudo service postgresql start || exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment