Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Migration: Rename tables error-prone #477

Closed
marcj opened this Issue · 21 comments

7 participants

@marcj
Owner

As seen in https://travis-ci.org/propelorm/Propel2/jobs/13457004.

PostgreSQL does not rename the autoIncrement sequences for us when we rename a table through the migration.

@marcj
Owner

We should remove the 'feature' that automatically renames tables through the ALTER TABLE way.
That produces actually more problems than it solves. A simple DROP and CREATE is way less error-prone than the ALTER TABLE RENAME statement as we can not guarantee without much work that all sequences and other information are renamed as well.

@staabm
Collaborator

But drop+create will loose the data?

@marcj
Owner

True, but that renaming is heavily error-prone.

  • there is no guaranteed way to detect which tables should be renamed to which (if you remove two and add two new)
  • if you drop a table (not rename) and add a complete new one it can be that the new one has entries from the dropped - which is wrong
  • not all information are moved/merged to the new one (sequences)

If you want to keep all entries you can still overwrite the generated migration file.

@staabm
Collaborator

Maybe we could create+move data+drop.

Another problem afair: meta changes are not transactional (at least in mysql), so rename is more like all or nothing while several statements could lead to various intermediate results

@marcj
Owner

What do you mean? The thing is, we could definitely create and then copy the data from old to the new created one so the third point above is eliminated but then you still have the first two to solve.

@marcj marcj referenced this issue
Merged

Bugfix for #473. #476

3 of 4 tasks complete
@marcj
Owner

@jaugustin @willdurand @hhamon any ideas about that?

@staabm
Collaborator

Migrations goal is to migrate structure&data from revision to revision. Migrations without data is not an option IMO

@marcj
Owner

I think you didn't get the point. We're talking not about removing the data migration at all. Only for table name changes respectively removing&adding a table with same columns, because we have no way to detect if it's only a renaming.

@marcj
Owner

And if we would have a way to detect it, we would have to implement another way of renaming tables (drop+create+copy-data)

@marcj
Owner

Another problem afair: meta changes are not transactional (at least in mysql), so rename is more like all or nothing while several statements could lead to various intermediate results

That is not a problem as we already build DDL with multiple statements. There's no way to combine all of those into one single.

@mpscholten
Collaborator

PostgreSQL does not rename the autoIncrement sequences for us when we rename a table through the migration.

Can't we just disable table renaming for PostgreSQL?

@marcj
Owner

No, please not. And that wouldn't solve all other issues. :(

@stood

I'm not understand because when I have renamed my table in pgsql I have no problem. The sequence is called when you add new row and is called by

nextval('author_id_seq'::regclass)

The name of sequence not changed.

My version of pgsql is : 9.2 for travis ?

@tacman
@marcj marcj modified the milestone: alpha-3, beta-1
@marcj marcj referenced this issue from a commit
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
262c1d7
@marcj marcj referenced this issue from a commit
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
d857a9d
@marcj marcj referenced this issue from a commit
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
9b9f52a
@marcj marcj referenced this issue from a commit
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
4758177
@marcj marcj referenced this issue from a commit
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
b9821dd
@marcj marcj referenced this issue from a commit
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
d16b1e8
@marcj marcj referenced this issue from a commit
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
e9e8b3d
@marcj
Owner

Ok, I guess the only solution here is to make this renaming optional through configuration. It makes no sense to me to have a heavily error-prone component per default activated. I believe making it active through a flag/option is the best solution for those guys who want to use this feature and are able to double-check the outcome of the diffcommand.
At the moment it has been completely removed by PR #476. This issue should now represent the task of making it optional possible again.

@marcj marcj changed the title from [PostgreSQL] Migration: Rename also Sequences to Migration: Rename tables
@marcj marcj changed the title from Migration: Rename tables to Migration: Rename tables error-prone
@mhitza

Would it be an option to check when a drop/create takes place upon tables with similar fields to issue a warning in the diff task, along the lines "Droping table x creating table y, revise migration file in case a rename is required"?

@marcj
Owner

@mhitza yes would be possible, good idea. :+1:

@marcj
Owner

screen shot 2014-04-15 at 18 56 14

et voilà

@marcj marcj referenced this issue from a commit
@marcj marcj Fixed #477, Fixed #607, Fixed #604 f01b891
@marcj marcj referenced this issue from a commit
@marcj marcj Fixed #477, Fixed #607, Fixed #604 d720f2a
@marcj marcj self-assigned this
@willdurand
Owner

Nice!

@marcj marcj closed this in #611
@mpscholten
Collaborator

Very nice solution :+1:

@nymo nymo referenced this issue from a commit
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
082255e
@mpscholten mpscholten referenced this issue from a commit in mpscholten/Propel2
@marcj marcj Fixed relation handling. Fixed #473, #518, #262.
Fixed bug: crossTable with at least one FK with multiple local columns
Fixed bug: crossTable with more than two FKs
Fixed bug: crossTable with two PK-FK and one PK-nonFK
Fixed bug: crossTable: setRelations(Collection),
removeRelation($rel), save() doesn’t remove $rel.
Added Partial-checking also to CrossFK getter.
Fixed bug: wrong "if ($obj->isNew())” check in getRelation() methods.
Improved performance of hashCode.
Improved ObjectCollection checks
Modified clearAllReferences as in PHP 5.4 there's no workaround like
that necessary anymore.
Fixed internal object relation reference tracking, especially
unlinking back-references.

Added also the table rename fix for #477, so we do not rename tables
anymore. This was necessary because otherwise with this new incoming
tests for relations the test suite won't be green.
f2be2d3
@mpscholten mpscholten referenced this issue from a commit in mpscholten/Propel2
@marcj marcj Fixed #477, Fixed #607, Fixed #604, Fixed #610 eb1e1a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.