upgrade_db.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. Upgrade a database
  2. ==================
  3. Database schema migration are handled in two ways:
  4. * New tables
  5. For this we simply rely on the ``createdb`` script used when creating the
  6. database the first time.
  7. * Changes to existing tables
  8. For changes to existing tables, we rely on `Alembic <http://alembic.readthedocs.org/>`_.
  9. This allows us to do upgrade and downgrade of schema migration, kind of like
  10. one would do commits in a system like git.
  11. To upgrade the database to the latest version simply run:
  12. ::
  13. alembic upgrade head
  14. This may fail for different reasons:
  15. * The change was already made in the database
  16. This can be because the version of the database schema saved is incorrect.
  17. It can be debugged using the following commands:
  18. * Find the current revision: ``alembic current``
  19. * See the entire history: ``alembic history``
  20. Once the revision at which your database should be is found (in the history)
  21. you can declare that your database is at this given revision using:
  22. ``alembic stamp <revision id>``.
  23. Eventually, if you do not know where your database is or should be, you can
  24. do an iterative process stamping the database for every revision, one by one
  25. trying everytime to ``alembic upgrade`` until it works.
  26. * The database used does not support some of the changes
  27. SQLite is handy for development but does not support all the features of a
  28. real database server. Upgrading a SQLite database might therefore not work,
  29. depending on the changes done.
  30. In some cases, if you are using a SQLite database, you will have to destroy
  31. it and create a new one.