Database models differs from migrations.

Bug #1292591 reported by Ilya Pekelny
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
Medium
Viktor Serhieiev

Bug Description

As models and migrations don't have any logical relation in code, so differences are possible. Furthermore in most of cases differences exists. The only way to solve this problem is using of specific test such as this https://review.openstack.org/#/c/74081/ .

This is a diff example form Keystone:

AssertionError: Models and migration scripts aren't in sync:
[ [ ( 'modify_nullable',
      None,
      'federation_protocol',
      'mapping_id',
      { 'existing_server_default': None,
        'existing_type': VARCHAR(length=64)},
      True,
      False)],
  [ ( 'modify_nullable',
      None,
      'region',
      'description',
      { 'existing_server_default': None,
        'existing_type': VARCHAR(length=255)},
      False,
      True)],
  ( 'remove_index',
    Index(u'ix_revocation_event_revoked_at', Column(u'revoked_at', DATETIME(), table=<revocation_event>, nullable=False))),
  [ ( 'modify_nullable',
      None,
      'token',
      'valid',
      { 'existing_server_default': None,
        'existing_type': INTEGER()},
      True,
      False)]]

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (master)

Fix proposed to branch: master
Review: https://review.openstack.org/80618

Changed in keystone:
assignee: nobody → Ilya Pekelny (i159)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/80630

Revision history for this message
Dolph Mathews (dolph) wrote :

I'm not sure what all the values in those tuples are intended to represent, but specific fixes to bring migrations and models back into sync would be interesting to see for RC1, even without the test approach from oslo.

Changed in keystone:
importance: Undecided → Medium
Revision history for this message
Ilya Pekelny (i159) wrote :

I can't do it without the test approach, because the test is the only way to determine differences, so and fix it. I'm focused on specific tests development.

Revision history for this message
Roman Podoliaka (rpodolyaka) wrote :

FYI, for other projects we've created blueprints rather than bugs, e.g. in cinder https://blueprints.launchpad.net/cinder/+spec/db-sync-models-with-migrations

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/84444

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/84445

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/84446

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/84447

Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : Fix merged to keystone (master)

Reviewed: https://review.openstack.org/84444
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=ba6705a731f8a80f9d01e88ae3425a93d70e4688
Submitter: Jenkins
Branch: master

commit ba6705a731f8a80f9d01e88ae3425a93d70e4688
Author: Ilya Pekelny <email address hidden>
Date: Tue Apr 1 12:17:10 2014 +0300

    Explicit foreign key indexes.

    Overview:
    MySQL requires indexes on foreign keys. Such an index is created on the
    referencing table automatically if it does not exist.

    Motivation:
    MySQL names foreign keys indexes differently dependent from itself
    version. Implicit fk indexes is MySQL specific behavior, so it should be
    ignored during comparision. We plan to use Alembic to compare models and
    migrations I0758c7e09d1d46ce870c3f94f76c2a177955e143. Alembic doesn't support
    5.5 naming convention. So we need consistent index name for all MySQL versions
    to be easily ignored.

    Solution:
    A new migration script renames incorrectly named fk indexes on MySQL.

    Reproduction:
    Stop execution when foregn keys will be initialized. See schema with
    your MySQL shell client. With 5.5, indexes which was not named
    explicitly, will have a name such as <tablename>_<columnname>_fk, with 5.1 it
    will be <columnname>.

    Change-Id: I01ba0c8856afbda59394395ac319bf83a55ee2be
    Partial-Bug: #1292591

Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote :

Reviewed: https://review.openstack.org/84445
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=52d1fbfbe1476c01685c86a0b91f3fe8b110eaa5
Submitter: Jenkins
Branch: master

commit 52d1fbfbe1476c01685c86a0b91f3fe8b110eaa5
Author: Ilya Pekelny <email address hidden>
Date: Tue Apr 1 14:46:33 2014 +0300

    Compatible server default value in the models.

    MySQL has no native boolean type. MySQL boolean type is just an alias
    to tiny int type field. So MySQL returns '"1"' for `true` value and
    '"0"' for false value. Instead of it, Postgres has native boolean type.
    Thus with Postgres, reflection of a boolean type column default value will
    return either 'true' or 'false'. Model must have compatible
    `server_default` argument in columns definition.

    Change-Id: Id0107d510dd7087e61ae851a1f3ff18334851a68
    Partial-Bug: #1292591

Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote :

Reviewed: https://review.openstack.org/84446
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=326f57c2713306f561dae01c4fc9a42e27d195eb
Submitter: Jenkins
Branch: master

commit 326f57c2713306f561dae01c4fc9a42e27d195eb
Author: Ilya Pekelny <email address hidden>
Date: Tue Apr 1 15:08:06 2014 +0300

    Correct `nullable` values in models and migrations

    * Region.description is declared as non-nullable in migration, so model nullable
    value changed to False too.

    * FederationProtocol.mapping_id must logically be not nullable. Provide a
    migration script to add the NOT NULL constraint to the column.

    Change-Id: I15a9e50b5461a112faca08f0ea68cbae2ce77d0d
    Partial-Bug: #1292591

Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote :

Reviewed: https://review.openstack.org/84447
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=ca370e2ac545ffbaf5b038274d26b954117392d0
Submitter: Jenkins
Branch: master

commit ca370e2ac545ffbaf5b038274d26b954117392d0
Author: Ilya Pekelny <email address hidden>
Date: Tue Apr 8 15:20:51 2014 +0300

    Redundant unique constraint

    federation extension have redundant unique constraint. The unique
    constraint is totally useless, as (id, idp_id) columns are
    columns of a composite primary key, which is unique by definition.

    Change-Id: I93648ab89b26d7e77875a1faa8575a146224232f
    Partial-Bug: #1292591

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to keystone (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/168003

Changed in keystone:
assignee: Ilya Pekelny (i159) → Victor Sergeyev (vsergeyev)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to keystone (master)

Reviewed: https://review.openstack.org/168003
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=12a9121e6e5bf85f0d12de7cc97e8196405c09ac
Submitter: Jenkins
Branch: master

commit 12a9121e6e5bf85f0d12de7cc97e8196405c09ac
Author: Victor Sergeyev <email address hidden>
Date: Thu Mar 26 15:57:04 2015 +0200

    Fix for migration 062 on MySQL

    MySQL creates indexes for foreign key columns automatically on InnoDB, so
    we should remove this index as well now that we have dropped the FK.

    Related-Bug: #1292591
    Change-Id: Ie8c69cc10ebdd805fc5cef82cb08c7d73c70b6e1

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Reviewed: https://review.openstack.org/137637
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=0a656a5a1b8412e6427f4a5bec78d97ef5cc2748
Submitter: Jenkins
Branch: master

commit 0a656a5a1b8412e6427f4a5bec78d97ef5cc2748
Author: Victor Sergeyev <email address hidden>
Date: Wed Nov 26 18:23:05 2014 +0200

    Fix index name the assignment.actor_id table.

    If we to generate DB schema from model description, it creates index
    named 'ix_assignment_actor_id' for 'actor_id' column 'assignment' table,
    but migration script 054 added index 'ix_actor_id' for this column.
    The simplest way to fix this difference is to add index name to model
    description obviously.

    Co-Authored-By: Ilya Pekelny <email address hidden>

    Related-Bug: #1292591
    Change-Id: I944b7d2db294af9e30f01ef16925e20265d19270

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to keystone (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/174388

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Related fix proposed to branch: master
Review: https://review.openstack.org/174871

Revision history for this message
Dolph Mathews (dolph) wrote :

I'm assuming this was fixed by the last patch. In the future, please use Closes-Bug on the final patch in your patch sequence -- not just Partial-Bug on all of them (which leaves the bug open).

Changed in keystone:
status: In Progress → Fix Committed
milestone: none → 2015.1.0
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on keystone (master)

Change abandoned by Victor Sergeyev (<email address hidden>) on branch: master
Review: https://review.openstack.org/168947

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Change abandoned by Victor Sergeyev (<email address hidden>) on branch: master
Review: https://review.openstack.org/174388

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Change abandoned by Victor Sergeyev (<email address hidden>) on branch: master
Review: https://review.openstack.org/174871

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Change abandoned by Steve Martinelli (<email address hidden>) on branch: master
Review: https://review.openstack.org/80630
Reason: Marking this patch as abandoned as part of a patch clean up. Lots of negative comments, no new revision in many months, and the bug is marked as fixed. Abandoning.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.