Models should be the same as the state in DB after migration

Registered by Alexander Gordeev

We are using declarative_base in heat.db.sqlalchemy.models just for reflection, not for db creation.
For creation we are using migrations.
We don't have any tests that checks, that our models are up-to-date. Also we are testing it only on sqlite, which couldn't test such things as nullable constraints.

So We should:

1) Use always explicit nullable parameter for columns. There is a lot of mistakes in current heat models implementation. (sometimes in schema is nullable=True and in model nullable=False and vise versa). Also at this moment when you see Column description without nullable, you couldn't be sure that is author forget to set nullable='False' or it is really nullable='True'. So the easiest way to track all this and to fix and to avoid such things is to have one rule "always use explicit nullable".
2) Add in __table_args__ indexes and unique constraints
3) Fix all mistakes in models
4) Fix all mistakes in migrations
5) Sync effects of migrations in different backends.
6) Add tests that ensures that models are up-to-date.

This will allow us to find probably some mistake, or missing indexes and make work with db more clean.

Blueprint information

Status:
Complete
Approver:
Steven Hardy
Priority:
Undefined
Drafter:
Alexander Gordeev
Direction:
Approved
Assignee:
Alexander Gordeev
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Alexander Gordeev
Completed by
Steven Hardy

Related branches

Sprints

Whiteboard

Gerrit topic: https://review.openstack.org/#q,topic:bp/db-sync-models-with-migrations,n,z

Addressed by: https://review.openstack.org/47357
    Add testing of migration from oslo

Addressed by: https://review.openstack.org/47358
    Fix sqlalchemy models

Addressed by: https://review.openstack.org/47359
    Fix sqlalchemy migrations

Addressed by: https://review.openstack.org/47360
    Add initial test for db migrations

(stevebaker) is this blueprint still valid?

(stevebaker) Moving to i-3. I still don't know if this blueprint should remain open, be mark Implemented, or Obsoleted.

Addressed by: https://review.openstack.org/127535
    Alter models and add migration

Addressed by: https://review.openstack.org/127536
    Add ModelSMigrationSync classes

This should be marked as implemented -- viktors

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.