Adding UUID to the DB model

Edit on GitHub

Spryker can automatically generate a UUID column based on row data. Expose only UUIDs through customer-facing APIs, such as the Storefront API and Glue API.

  1. Require the composer dependency:
composer require spryker/uuid-behavior
  1. Extend your <table-name> Propel model definition with:
        <column name="uuid" required="false" type="VARCHAR" size="36"/>

        <behavior name="uuid">
            <parameter
                name="key_columns"
                value="<column list, dot-separated, e.g. id_table_name.some_column.another_column>"
        />
        </behavior>

The column list must contain columns from the same table, separated by dots (.). The UUID is generated from a string that concatenates the dot-separated values of these columns. Include the primary key (id_…) in the list, because UUID version 5 (UUIDv5) generates the same UUID for the same combined key-column values.

Prerequisite

Add a uuid column of type string with a length of at least 36 characters. Otherwise, insert operations into this table fail.

  1. Update the database schema and regenerate PHP models:
console propel:install
  1. Verify that the uuid column is present in the database table. Insert a new entity to confirm that UUIDs are generated automatically.
For tables with existing data

If you are adding the column uuid into existing table, follow this guide to fill daata into existing columns.