propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 398 forks source link

ArchivableBehavior archive table uses same index name as original table #1894

Closed felixgeyer closed 2 years ago

felixgeyer commented 2 years ago

Hi there,

we're experiencing an issue when using the ArchivableBehavior for tables with indices. The behavior copies the indices from the original table without modifying the index name. This leads to multiple indices with same name. At least in PostgreSQL this is not allowed and results in a failing migration:

[42P07] ERROR: relation "index-original_table-column" already exists

One of my colleagues introduced a workaround in our project by setting the copied index name to an empty string. This way a unique index name will be generated.

Related code: https://github.com/propelorm/Propel2/blame/master/src/Propel/Generator/Behavior/Archivable/ArchivableBehavior.php#L129-L132

Workaround:

foreach ($table->getIndices() as $index) {
   $copiedIndex = clone $index;
   $copiedIndex->setName('');
    $archiveTable->addIndex($copiedIndex);
}

I'd like to get rid of our custom workaround for this issue. We should discuss how we can solve this in Propel.

Some ideas:

If we can agree on a solution, I'll try to create a PR for this.