"""lower case production

Revision ID: fa2cd0ecc30f
Revises: 1693a9b29733
Create Date: 2019-04-23 10:01:13.744020

"""

# revision identifiers, used by Alembic.
revision = 'fa2cd0ecc30f'
down_revision = '1693a9b29733'
branch_labels = None
depends_on = None

from alembic import op
import sqlalchemy as sa


def upgrade():
    bind = op.get_bind()
    bind.execute("""
        BEGIN;
        ALTER TABLE toggles disable TRIGGER ALL;
        UPDATE toggles SET env='production' where env='Production';
        UPDATE environments set name='production' where name='Production';
        ALTER TABLE toggles enable trigger all; 
        COMMIT;
    """)


def downgrade():
    bind = op.get_bind()
    bind.execute("""
            BEGIN;
            ALTER TABLE toggles disable TRIGGER ALL;
            UPDATE toggles SET env='Production' where env='production';
            UPDATE environments set name='Production' where name='production';
            ALTER TABLE toggles enable trigger all;
            COMMIT; 
        """)

@@ -373,62 +373,138 @@
     
-BEGIN;%0A        ALTER TABLE toggles disable TRIGGER ALL
+ALTER TABLE toggles ALTER CONSTRAINT toggles_env_fkey DEFERRABLE;%0A        BEGIN;%0A        SET CONSTRAINTS toggles_env_fkey DEFERRED
 ;%0A  
@@ -648,57 +648,8 @@
 n';%0A
-        ALTER TABLE toggles enable trigger all; %0A
     
@@ -745,32 +745,87 @@
          BEGIN;%0A
+            SET CONSTRAINTS toggles_env_fkey DEFERRED;%0A
             ALTE
@@ -925,32 +925,32 @@
 v='production';%0A
+
             UPDA
@@ -1016,60 +1016,8 @@
 n';%0A
-            ALTER TABLE toggles enable trigger all;%0A
     

Fix the migration to defer instead of disable constraint (#35)