Blame alembic/versions/8a5d68f74beb_add_date_modified_for_project.py

Clement Verna cd6e30
"""Add date_modified for project
Clement Verna cd6e30
Clement Verna cd6e30
Revision ID: 8a5d68f74beb
Clement Verna cd6e30
Revises: 27a79ff0fb41
Clement Verna cd6e30
Create Date: 2017-07-18 19:28:09.566997
Clement Verna cd6e30
Clement Verna cd6e30
"""
Clement Verna cd6e30
from alembic import op
Clement Verna cd6e30
import sqlalchemy as sa
Clement Verna cd6e30
Clement Verna cd6e30
# revision identifiers, used by Alembic.
Clement Verna cd6e30
revision = '8a5d68f74beb'
Clement Verna cd6e30
down_revision = '27a79ff0fb41'
Clement Verna cd6e30
Clement Verna cd6e30
Clement Verna cd6e30
def upgrade():
Clement Verna cd6e30
    ''' Add the column date_modified to the table projects.
Clement Verna cd6e30
    '''
Clement Verna cd6e30
    op.add_column(
Clement Verna cd6e30
        'projects',
Clement Verna cd6e30
        sa.Column('date_modified', sa.DateTime, nullable=True,
Clement Verna cd6e30
                  default=sa.func.now())
Clement Verna cd6e30
    )
Clement Verna cd6e30
    op.execute("UPDATE projects SET date_modified=date_created;")
Clement Verna cd6e30
Clement Verna cd6e30
    op.alter_column(
Clement Verna cd6e30
        'projects',
Clement Verna cd6e30
        column_name='date_modified',
Clement Verna cd6e30
        nullable=False,
Pierre-Yves Chibon e44075
        existing_nullable=True)
Clement Verna cd6e30
Clement Verna cd6e30
Clement Verna cd6e30
def downgrade():
Clement Verna cd6e30
    ''' Remove the column date_modified from the table projects.
Clement Verna cd6e30
    '''
Clement Verna cd6e30
    op.drop_column('projects', 'date_modified')