"""DOS is coming

Revision ID: 420
Revises: 410_remove_empty_drafts
Create Date: 2015-11-16 14:10:35.814066

"""

# revision identifiers, used by Alembic.
revision = '420'
down_revision = '410_remove_empty_drafts'

from alembic import op
import sqlalchemy as sa
from app.models import Framework


def upgrade():
    op.execute("COMMIT")
    op.execute("ALTER TYPE framework_enum ADD VALUE IF NOT EXISTS 'dos' after 'gcloud'")

    framework = Framework.query.filter(Framework.slug == 'digital-outcomes-and-specialists').first()

    if not framework:
        op.execute("""
            INSERT INTO frameworks (name, framework, status, slug)
                values('Digital Outcomes and Specialists', 'dos', 'coming', 'digital-outcomes-and-specialists')
        """)


def downgrade():
    op.execute("""
        DELETE FROM frameworks where slug='digital-outcomes-and-specialists'
    """)

Add Digital Outcomes and Specialists to frameworks
Add Digital Outcomes and Specialists to frameworks

This commit checks to see if:
- the framework exists in the enum before trying to add it
- the framework exists in the table before trying to add

This means that it won’t fall over on enviroments where DOS has already been
created (eg local dev machines, preview).

The downgrade will fail if data associated with a framework has been created (eg
a supplier has registered interest). We made this trade off because:
- can rollback production if anything goes wrong if we deploy this
- no framework-related data will be created on production until the framework
  is open—by which time it will be way too late to rollback this far

_Paired with @TheDoubleK_
