Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate exists sequences on truncate table #325

Open
wants to merge 1 commit into
base: 1.5.x
Choose a base branch
from

Conversation

vsychov
Copy link

@vsychov vsychov commented Oct 31, 2019

In case of sequences based auto-increment (for example in PgSQL), fixture loading not clean sequence.
This causes certain difficulties with testing, for example, when we need to link cross project entities.

This PR resolve that issue, by re-creating sequences, if fixtures loading requested with "truncate" flag.

@alcaeus
Copy link
Member

alcaeus commented Nov 2, 2019

TBH, I disagree here. If you need to rely on specific identifiers, sequences are the wrong solution anyways, so resetting them isn’t necessary. If you need to know what entity to reference, there’s a section in the readme that explains how to do that: https://github.com/doctrine/data-fixtures/blob/master/README.md

All in all, I don’t think this should be merged, but I’m happy to hear your argument for it.

@Ocramius
Copy link
Member

Ocramius commented Nov 2, 2019

I'd also add that requiring stable identifiers in a test suite is extremely dangerous: you are hardcoding assumption about sequence generation that should be details of the system, rather than features

@vsychov
Copy link
Author

vsychov commented Nov 6, 2019

@alcaeus README.md provides info, how to made connection between two entities in fixtures via the addReference method, this can only be used if fixtures are loaded through one project. But what if we have related fixtures in several projects with different code base? For example:

  1. we have a service that provides user authorization (for example, a JWT generator)
  2. a service that works with tokens provided by the first service, and contains in some of its entities a link to the user id from the first service

@alcaeus
Copy link
Member

alcaeus commented Nov 6, 2019

Then don't assume on the order of your sequence, but use special, hardcoded identifiers. Using sequences in such instances is extremely risky.

@vsychov
Copy link
Author

vsychov commented Nov 6, 2019

What is the risk, in using sequences? Using hardcoded identifiers is also way, but it more difficult, because in that case, I need to create custom doctrine generator, that will be check, if id set to entity or not.

@alcaeus
Copy link
Member

alcaeus commented Nov 6, 2019

You should not rely on the sequence assigning the same values on subsequent operations - the only thing you can count on is that they will assign sequential values without duplicates. If you are relying on hardcoded identifiers, you need to control both sides: the generation and the consumption of these identifiers.

Base automatically changed from master to 1.5.x January 23, 2021 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants