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

Registered by Ann Taraday

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 are mistakes in current ceilometer 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 mistekes 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 inexes and make work with db more clean.

Blueprint information

Status:
Complete
Approver:
Julien Danjou
Priority:
Undefined
Drafter:
Ann Taraday
Direction:
Approved
Assignee:
Ann Taraday
Definition:
Obsolete
Series goal:
None
Implementation:
Good progress
Milestone target:
milestone icon next
Started by
Julien Danjou
Completed by
gordon chung

Related branches

Sprints

Whiteboard

List of models:

⚒alarm
⚒event
⚒meter
⚒project
⚒resource
source
sourceassoc
trait
unique_name
user

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

Addressed by: https://review.openstack.org/36610
    Sync SQLAlchemy models with migrations

Addressed by: https://review.openstack.org/36621
    Sync SQLAlchemy models with migrations

Addressed by: https://review.openstack.org/37880
    Sync models with migrations.

Addressed by: https://review.openstack.org/37881
    Sync models with migrations.

Addressed by: https://review.openstack.org/37883
    Add cleanup migration for indexes.

Addressed by: https://review.openstack.org/37885
    Fix missing foreign keys.

Addressed by: https://review.openstack.org/37887
    Remove extra unique key.

Addressed by: https://review.openstack.org/37890
    Add test for migrations.

Addressed by: https://review.openstack.org/42715
    Fix wrong UniqueConstraint name

Addressed by: https://review.openstack.org/42716
    Extra indexes cleanup

NOTE (herndon)- the events/traits models are changing to include EventType/TraitType, and the unique_name table is going away.
Relevant reviews:
https://review.openstack.org/#/c/42407/
https://review.openstack.org/#/c/41316/14

Addressed by: https://review.openstack.org/43872
    Add test for checking models with migrations

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

Addressed by: https://review.openstack.org/44539
    Fix wrong migrations

Addressed by: https://review.openstack.org/44809
    Implement testing of migrations

inactive. not worth time. -- gordc

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.