from alembic import op
import sqlalchemy as sa


revision = '0245_archived_flag_jobs'
down_revision = '0244_another_letter_org'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('jobs', sa.Column('archived', sa.Boolean(), nullable=False, server_default=sa.false()))

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('jobs', 'archived')
    # ### end Alembic commands ###

from alembic import op
import sqlalchemy as sa


revision = '0245_archived_flag_jobs'
down_revision = '0244_another_letter_org'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('jobs', sa.Column('archived', sa.Boolean(), nullable=True))
    op.execute('update jobs set archived = false')
    op.alter_column('jobs', 'archived', nullable=False, server_default=sa.false())

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('jobs', 'archived')
    # ### end Alembic commands ###

Update jobs archived flag before setting the default value
Update jobs archived flag before setting the default value

Running an update before setting the column default value reduces
the time the table is locked (since most rows don't have a NULL
value anymore), but the migration takes slightly longer to run
overall.

  from alembic import op
  import sqlalchemy as sa
  
  
  revision = '0245_archived_flag_jobs'
  down_revision = '0244_another_letter_org'
  
  
  def upgrade():
      # ### commands auto generated by Alembic - please adjust! ###
+     op.add_column('jobs', sa.Column('archived', sa.Boolean(), nullable=True))
+     op.execute('update jobs set archived = false')
-     op.add_column('jobs', sa.Column('archived', sa.Boolean(), nullable=False, server_default=sa.false()))
+     op.alter_column('jobs', 'archived', nullable=False, server_default=sa.false())
  
      # ### end Alembic commands ###
  
  
  def downgrade():
      # ### commands auto generated by Alembic - please adjust! ###
      op.drop_column('jobs', 'archived')
      # ### end Alembic commands ###
  
Update jobs archived flag before setting the default value
## Code Before:
from alembic import op
import sqlalchemy as sa


revision = '0245_archived_flag_jobs'
down_revision = '0244_another_letter_org'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('jobs', sa.Column('archived', sa.Boolean(), nullable=False, server_default=sa.false()))

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('jobs', 'archived')
    # ### end Alembic commands ###

## Instruction:
Update jobs archived flag before setting the default value
## Code After:
from alembic import op
import sqlalchemy as sa


revision = '0245_archived_flag_jobs'
down_revision = '0244_another_letter_org'


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('jobs', sa.Column('archived', sa.Boolean(), nullable=True))
    op.execute('update jobs set archived = false')
    op.alter_column('jobs', 'archived', nullable=False, server_default=sa.false())

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('jobs', 'archived')
    # ### end Alembic commands ###
