version-numbers.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. Version Numbers
  2. ===============
  3. When :doc:`Generating Migrations <generating-migrations>` the newly created
  4. classes are generated with the name ``Version{date}`` with ``{date}`` having a
  5. ``YmdHis`` `format <http://php.net/manual/en/function.date.php>`_. This format
  6. is important as it allows the migrations to be correctly ordered.
  7. .. note::
  8. Starting with version 1.5 when loading migration classes, Doctrine does a
  9. ``sort($versions, SORT_STRING)`` on version numbers. This can cause
  10. problems with custom version numbers:
  11. .. code-block:: php
  12. <?php
  13. $versions = [
  14. 'Version1',
  15. 'Version2',
  16. // ...
  17. 'Version10',
  18. ];
  19. sort($versions, SORT_STRING);
  20. var_dump($versions);
  21. /*
  22. array(3) {
  23. [0] =>
  24. string(8) "Version1"
  25. [1] =>
  26. string(9) "Version10"
  27. [2] =>
  28. string(8) "Version2"
  29. }
  30. */
  31. The custom version numbers above end up out of order which may cause damage to a database.
  32. It is **strongly recommended** that the ``Version{date}`` migration class name format is used and that the various
  33. :doc:`tools for generating migrations <generating-migrations>` are used.
  34. Should some custom migration numbers be necessary, keeping the version number the same length as the date format
  35. (14 total characters) and padding it to the left with zeros should work.
  36. .. code-block:: php
  37. <?php
  38. $versions = [
  39. 'Version00000000000001',
  40. 'Version00000000000002',
  41. // ...
  42. 'Version00000000000010',
  43. 'Version20180107070000', // generated version
  44. ];
  45. sort($versions, SORT_STRING);
  46. var_dump($versions);
  47. /*
  48. array(4) {
  49. [0] =>
  50. string(21) "Version00000000000001"
  51. [1] =>
  52. string(21) "Version00000000000002"
  53. [2] =>
  54. string(21) "Version00000000000010"
  55. [3] =>
  56. string(21) "Version20180107070000"
  57. }
  58. */
  59. Please note that migrating to this new, zero-padded format may require
  60. :ref:`manual version table intervention <managing-migrations#managing-the-version-table>` if the
  61. versions have previously been applied.
  62. :ref:`Next Chapter: Integrations <integrations>`