Skip to content

Instantly share code, notes, and snippets.

@lovemyliwu
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lovemyliwu/9f33ba54fddbbd16564a to your computer and use it in GitHub Desktop.
Save lovemyliwu/9f33ba54fddbbd16564a to your computer and use it in GitHub Desktop.
a safe way to re-build empty_db for django
#prepare db for develop
1. ./update_db.sh
#prepare code
1. git checkout develop
2. git pull origin develop
3. python manage.py migrate
#merge code
1. git checkout hotfix
2. git merge develop
3. git checkout develop -- empty_db.sql
4. git rm {new migrate files in this hotfix}
5. python manage.py makemigrations
6. {select yes to create test db}
7. python manage.py migrate
#done
@lovemyliwu
Copy link
Author

with migrate rollback will faster

rollback db for develop

  1. python migrate {last migration on develop before hotfix }

prepare code

  1. git checkout develop
  2. git pull origin develop
  3. python manage.py migrate

merge code

  1. git checkout hotfix
  2. git merge develop
  3. git checkout develop -- empty_db.sql
  4. git rm {new migrate files in this hotfix}
  5. python manage.py makemigrations
  6. {select yes to create test db}
  7. python manage.py migrate

done

@lovemyliwu
Copy link
Author

a fast-est way:

direct use develop branch empty_db

  1. git merge develop
  2. git checkout develop -- empty_db.sql
  3. mysql -uroot -ppassword -Dcruise < empty_db.sql
  4. git rm {new migrate files in this hotfix}
  5. python manage.py makemigrations
  6. {select yes to create test db}

if you want test data in cruise db

  1. python manage.py devdata --action push --populate --settings=cruise2.settings.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment