Extend the database schema

Edit on GitHub

This document shows how to extend the database schema.

Fields can be added to the existing database tables, but they cannot be removed (removing fields from the tables could break the functionalities implemented in Spryker Core).

Info

In addition, you can create a new database table:

console spryk:run AddZedPersistencePropelSchema

As an example, let’s add a description field to the spy_price_type table. The structure of this table is defined in the PriceProduct module, in the spy_price_product.schema.xml file as follows:

    ...
    <table name="spy_price_type">
        <column name="id_price_type" type="INTEGER" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="name" type="VARCHAR" size="255" required="true"/>
        <column name="price_mode_configuration" type="ENUM" valueSet="NET_MODE, GROSS_MODE, BOTH"/>

        <unique name="spy_price_type-name">
            <unique-column name="name"/>
        </unique>

        <id-method-parameter value="spy_price_type_pk_seq"/>
    </table>
    ...

To add a column to this table, follow these steps:

  1. On the project side, if it hasn’t been created yet, add a corresponding XML file ( follow the same folder structure and give it the same name)
mkdir -p src/Pyz/Zed/PriceProduct/Persistence/Propel/Schema
touch src/Pyz/Zed/PriceProduct/Persistence/Propel/Schema/spy_price_product.schema.xml

  1. Add the additional fields to the table definition:
<?xml version="1.0"?>
<database xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="zed"
    xsi:noNamespaceSchemaLocation="http://static.spryker.com/schema-01.xsd"
    namespace="Orm\Zed\Price\Persistence"
    package="src.Orm.Zed.Price.Persistence">

    <table name="spy_price_type">
        <column name="description" type="VARCHAR" size="255" required="false"/>
    </table>

</database>
  1. Update the database:
vendor/bin/console propel:install

Troubleshooting

If you stumble upon an exception Uncommitted migrations have been found, either execute or delete them before rerunning the diff task:

vendor/bin/console propel:migration:delete