Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Migration: Rename tables error-prone #477

Closed
marcj opened this Issue · 21 comments

7 participants

Marc J. Schmidt Markus Staab Marc Scholten Mikael Paris tacman Marius Ghita William Durand
Marc J. Schmidt
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.

Marc J. Schmidt
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.

Markus Staab
Collaborator

But drop+create will loose the data?

Marc J. Schmidt
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.

Markus Staab
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

Marc J. Schmidt
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.

Marc J. Schmidt marcj referenced this issue
Merged

Bugfix for #473. #476

3 of 4 tasks complete
Marc J. Schmidt
Owner

@jaugustin @willdurand @hhamon any ideas about that?

Markus Staab
Collaborator

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

Marc J. Schmidt
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.

Marc J. Schmidt
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)

Marc J. Schmidt
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.

Marc Scholten
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?

Marc J. Schmidt
Owner

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

Mikael Paris

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
Marc J. Schmidt marcj modified the milestone: alpha-3, beta-1
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt 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
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt 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
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt 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
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt 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
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt 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
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt 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
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt 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
Marc J. Schmidt
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.

Marc J. Schmidt marcj changed the title from [PostgreSQL] Migration: Rename also Sequences to Migration: Rename tables
Marc J. Schmidt marcj changed the title from Migration: Rename tables to Migration: Rename tables error-prone
Marius Ghita

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"?

Marc J. Schmidt
Owner

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

Marc J. Schmidt
Owner

screen shot 2014-04-15 at 18 56 14

et voilà

Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt marcj Fixed #477, Fixed #607, Fixed #604 f01b891
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt marcj Fixed #477, Fixed #607, Fixed #604 d720f2a
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt marcj Fixed #477, Fixed #607, Fixed #604, Fixed #610 752bb48
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt marcj Fixed #477, Fixed #607, Fixed #604, Fixed #610 57e1c36
Marc J. Schmidt marcj referenced this issue from a commit in marcj/Propel2
Marc J. Schmidt marcj Fixed #477, Fixed #607, Fixed #604, Fixed #610 ef1e4eb
Marc J. Schmidt marcj self-assigned this
William Durand
Owner

Nice!

Marc J. Schmidt marcj closed this in #611
Marc Scholten
Collaborator

Very nice solution :+1:

Gregor Panek nymo referenced this issue from a commit
Marc J. Schmidt 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
Marc Scholten mpscholten referenced this issue from a commit in mpscholten/Propel2
Marc J. Schmidt 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
Marc Scholten mpscholten referenced this issue from a commit in mpscholten/Propel2
Marc J. Schmidt 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.