@@ -358,10 +358,16 @@ multiple schemas, you can update the value of the ``SCHEMA_VERSION``
358
358
constant in subsequent model classes.
359
359
360
360
When creating your model, you can define the ``migrateSchema()`` method
361
- to specify a migration to the current schema version upon saving a
361
+ to specify a migration to the current schema version upon retrieving a
362
362
model. In this method, you can specify the changes to make to an older
363
363
model to update it to match the current schema version.
364
364
365
+ When you save a model that does not have a schema version
366
+ specified, Laravel assumes that it follows the latest schema version.
367
+ When you retrieve a model that does not contain the ``schema_version``
368
+ field, Laravel assumes that its schema version is ``0`` and performs the
369
+ migration.
370
+
365
371
Schema Versioning Example
366
372
~~~~~~~~~~~~~~~~~~~~~~~~~
367
373
@@ -387,15 +393,16 @@ You can define the new model class with the following behavior:
387
393
:emphasize-lines: 10,12,20
388
394
:dedent:
389
395
390
- When you save or retrieve a model that does not have a schema version
391
- specified, Laravel assumes that it follows the latest schema version.
396
+ In the ``"WASP-39 b"`` document in the following code, the
397
+ ``schema_version`` field value is less than ``2``. When you retrieve the
398
+ document, Laravel adds the ``galaxy`` field and updates the schema
399
+ version to the current version, ``2``.
392
400
393
- When you save or retrieve a model in which the ``schema_version`` field
394
- value is less than ``2``, Laravel adds the ``galaxy``
395
- field and updates the schema version to the current version (``2``).
401
+ The ``"Saturn"`` document does not contain the ``schema_version`` field,
402
+ so Laravel assigns it the current schema version upon saving.
396
403
397
- The following code inserts two instances of the ``Planet`` model, then
398
- retrieves the models from the collection to demonstrate the changes:
404
+ Finally, the code retrieves the models from the collection to
405
+ demonstrate the changes:
399
406
400
407
.. io-code-block::
401
408
:copyable: true
0 commit comments