"""email_templates_counter

Revision: 0166
Revision ID: 46d38eb71ef6
Revises: f5482137635
Create Date: 2019-06-20 13:58:29.594346

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic.
revision = '46d38eb71ef6'
down_revision = 'f5482137635'
branch_labels = None
depends_on = None


def upgrade():
    op.add_column('email_templates', sa.Column('counter', sa.Integer(), nullable=True))
    op.add_column('email_templates', sa.Column('last_sent_at', sa.DateTime(), nullable=True))
    op.add_column('organizations', sa.Column('email_templates_send_counter', sa.Integer(), nullable=True))
    op.execute("UPDATE email_templates SET counter = 0")
    op.execute("UPDATE organizations SET email_templates_send_counter = 0")


def downgrade():
    op.drop_column('email_templates', 'counter')
    op.drop_column('email_templates', 'last_sent_at')
    op.drop_column('organizations', 'email_templates_counter')
