Calling Developers!
We are reenergizing our code contribution process! Learn More

What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello! Which is the best approach if I want to replace a unique constraint as group. For example in

Options
UKJKAFMMJ
UKJKAFMMJ Posts: 38 🧑🏻‍🚀 - Cadet
edited July 2019 in Help

Hello! Which is the best approach if I want to replace a unique constraint as group. For example in quote: name, customer_reference to be name, customer_reference and other column?

Comments

  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 🪐 - Explorer
    Options

    Did I got you right, you want to replace an existing unique constraint or better extend it with an additional field?

    If that’s the question, just add a file Pyz/Zed/Quote/Persistence/Propel/Schema/spy_quote.schema.xml with the follwing content:

    <?xml version=“1.0”?>
    ” name=“zed” xsi:noNamespaceSchemaLocation=“http://static.spryker.com/schema-01.xsd” namespace=“Orm\Zed\Quote\Persistence” package=“src.Orm.Zed.Quote.Persistence”>

    ” />

    See https://documentation.spryker.com/zed/persistence_layer/database_schema_definition.htm?Highlight=schema#schema-file-merge

  • UKJKAFMMJ
    UKJKAFMMJ Posts: 38 🧑🏻‍🚀 - Cadet
    Options

    I did that, but the old constraint is still there and works. My constraint is not applied....

  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 🪐 - Explorer
    Options

    And you did a console propel:schema:copy && propel:diff && propel:migrate && propel:model:build (or propel:install as alternative)?
    What’s in you generated migration file?

  • UKJKAFMMJ
    UKJKAFMMJ Posts: 38 🧑🏻‍🚀 - Cadet
    Options

    My contrait is created in DB, but not working. Is used the Spryker contraint

  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 🪐 - Explorer
    Options

    What DB do you use?
    Do you have null values in one of the columns (depending on the DB null values are ignored for constraints)?

    Did you already tested on a database level that the constraint isn’t working (e.g.: Inserting tho datasets with the same name, customer_reference and )?

  • UKJKAFMMJ
    UKJKAFMMJ Posts: 38 🧑🏻‍🚀 - Cadet
    Options

    Yes, duplicate key value violates unique constraint "spy_quote-unique-name-customer_reference"

  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 🪐 - Explorer
    Options

    Than I do not understand the problem, maybe you can give a better explanation what did you expect and what do you get instead.

    Maybe you expected that the name of the unique constraint will include your field, that would be a wrong assumption as defines the naming of the constraint. And as you try to overwrite an existing constraint, you shouldn’t change the name.

  • Unknown
    Options

    I never tested this so this is just a wild guess:
    Did you use the exact same name for the constraint as Spryker uses?

  • UKJKAFMMJ
    UKJKAFMMJ Posts: 38 🧑🏻‍🚀 - Cadet
    Options

    I added a new unique constraint and I want to use that. That's it!

  • UKJKAFMMJ
    UKJKAFMMJ Posts: 38 🧑🏻‍🚀 - Cadet
    Options

    In my schema: ```

    <unique name="spy_quote-unique-name-customer_reference-company_reference"> <unique-column name="name"/> <unique-column name="customer_reference"/> <unique-column name="company_reference"/> </unique> </table> ```
  • Unknown
    Options

    As far as I know you will not be able to remove a constraint that was added by Spryker in the core implementations. Schema files will get merged and unless you actually replace a constaint (hence the name suggestion) it will be there.

  • Unknown
    Options

    What's wrong with using the same name?