Add order_retry_tasks migration per latest model
After the retry feature was implemented changes were made to the OrderRetryTask model (in particular extending ModelBase) that added new attributes to the entity. This CR formally adds those new attributes via an Alembic migration module. Change-Id: I73d54ce734f416322247efc72d51b3844d0c1afc
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""Update order_retry_tasks table
|
||||
|
||||
Revision ID: 30dba269cc64
|
||||
Revises: 3041b53b95d7
|
||||
Create Date: 2015-04-01 17:53:25.447919
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '30dba269cc64'
|
||||
down_revision = '3041b53b95d7'
|
||||
|
||||
from alembic import op
|
||||
from barbican.openstack.common import timeutils
|
||||
from barbican.model import models as m
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column(
|
||||
'order_retry_tasks',
|
||||
sa.Column(
|
||||
'created_at',
|
||||
sa.DateTime(),
|
||||
nullable=False,
|
||||
server_default=str(timeutils.utcnow())))
|
||||
op.add_column(
|
||||
'order_retry_tasks',
|
||||
sa.Column(
|
||||
'deleted',
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default='0'))
|
||||
op.add_column(
|
||||
'order_retry_tasks',
|
||||
sa.Column('deleted_at', sa.DateTime(), nullable=True))
|
||||
op.add_column(
|
||||
'order_retry_tasks',
|
||||
sa.Column(
|
||||
'status',
|
||||
sa.String(length=20),
|
||||
nullable=False,
|
||||
server_default=m.States.PENDING))
|
||||
op.add_column(
|
||||
'order_retry_tasks',
|
||||
sa.Column(
|
||||
'updated_at',
|
||||
sa.DateTime(),
|
||||
nullable=False,
|
||||
server_default=str(timeutils.utcnow())))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('order_retry_tasks', 'created_at')
|
||||
op.drop_column('order_retry_tasks', 'deleted')
|
||||
op.drop_column('order_retry_tasks', 'deleted_at')
|
||||
op.drop_column('order_retry_tasks', 'status')
|
||||
op.drop_column('order_retry_tasks', 'updated_at')
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1267,7 +1267,8 @@ MODELS = [ProjectSecret, Project, Secret, EncryptedDatum, Order, Container,
|
||||
SecretStoreMetadatum, OrderPluginMetadatum, OrderBarbicanMetadatum,
|
||||
KEKDatum, CertificateAuthority, CertificateAuthorityMetadatum,
|
||||
ProjectCertificateAuthority, PreferredCertificateAuthority,
|
||||
SecretACL, ContainerACL, SecretACLUser, ContainerACLUser]
|
||||
SecretACL, ContainerACL, SecretACLUser, ContainerACLUser,
|
||||
OrderRetryTask]
|
||||
|
||||
|
||||
def register_models(engine):
|
||||
|
||||
@@ -110,7 +110,27 @@ instructions).
|
||||
|
||||
a. **Verify generated update/rollback steps, especially for modifications
|
||||
to existing columns/tables**
|
||||
b. **If you added new tables, follow this guidance**:
|
||||
b. Remove autogenerated comments such as:
|
||||
``### commands auto generated by Alembic - please adjust! ###``
|
||||
c. **If you added new columns, follow this guideance**:
|
||||
|
||||
1. For non-nullable columns you will need to add default values for the
|
||||
records already in the table, per what you configured in the
|
||||
``barbican.model.models.py`` module. You can add the
|
||||
``server_default`` keyword argument for the SQLAlchemy ``Column`` call
|
||||
per `SQLAlchemy's server_default`_. For boolean attributes, use
|
||||
`server_default='0'` for False, or `server_default='1'` for True. For
|
||||
DateTime attributes, use `server_default=str(timeutils.utcnow())` to
|
||||
default to the current time.
|
||||
2. If you add `any` constraint, please always `always` name them in the
|
||||
barbican.model.models.py module, and also in the Alembic version
|
||||
modules when creating/dropping constraints, otherwise MySQL migrations
|
||||
might crash.
|
||||
3. If only columns were added with no uniqueness constraints, you should
|
||||
consider reordering the ``downgrade()`` lines to place them in the
|
||||
same order as the ``upgrade()`` lines.
|
||||
|
||||
d. **If you added new tables, follow this guidance**:
|
||||
|
||||
1. Make sure you added your new table to the ``MODELS`` element of the
|
||||
``barbican/model/models.py`` module.
|
||||
@@ -229,3 +249,4 @@ TODO Items
|
||||
.. _Need to alter column types in production database: http://stackoverflow.com/questions/5329255/need-to-alter-column-types-in-production-database-sql-server-2005
|
||||
.. _OpenStack and SQLAlchemy: https://wiki.openstack.org/wiki/OpenStack_and_SQLAlchemy#Migrations
|
||||
.. _What does Autogenerate Detect: http://alembic.readthedocs.org/en/latest/autogenerate.html#what-does-autogenerate-detect-and-what-does-it-not-detect
|
||||
.. _SQLAlchemy's server_default: http://docs.sqlalchemy.org/en/latest/core/metadata.html?highlight=column#sqlalchemy.schema.Column.params.server_default
|
||||
|
||||
Reference in New Issue
Block a user