
# 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'
    """)


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

from alembic import op


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

    conn = op.get_bind()
    res = conn.execute("SELECT * FROM frameworks WHERE slug = 'digital-outcomes-and-specialists'")
    results = res.fetchall()

    if not results:
        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'
    """)

Use `op` instead of `app` so that `list_migrations` still works
Use `op` instead of `app` so that `list_migrations` still works

By importing `app` the `list_migrations.py` script broke because it doesn't have the `app` context.

  
  # 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()
+     conn = op.get_bind()
+     res = conn.execute("SELECT * FROM frameworks WHERE slug = 'digital-outcomes-and-specialists'")
+     results = res.fetchall()
  
-     if not framework:
+     if not results:
          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'
      """)
  
Use `op` instead of `app` so that `list_migrations` still works
## Code Before:

# 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'
    """)

## Instruction:
Use `op` instead of `app` so that `list_migrations` still works
## Code After:

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

from alembic import op


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

    conn = op.get_bind()
    res = conn.execute("SELECT * FROM frameworks WHERE slug = 'digital-outcomes-and-specialists'")
    results = res.fetchall()

    if not results:
        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'
    """)
