text: """empty message
  
  Revision ID: 8cf04343f0d7
  Revises: 37bdbcac8251
  Create Date: 2018-01-23 14:36:26.746751
  
  """
  from alembic import op
  import sqlalchemy as sa
  
  
  # revision identifiers, used by Alembic.
  revision = '8cf04343f0d7'
  down_revision = '37bdbcac8251'
  branch_labels = None
  depends_on = None
  
  
  def upgrade():
      # ### commands auto generated by Alembic - please adjust! ###
  
      op.add_column('page', sa.Column('frequency_id', sa.Integer()))
      op.add_column('page', sa.Column('frequency_other', sa.String(length=255), nullable=True))
  
      op.create_table('frequency_of_release',
          sa.Column('id', sa.Integer(), nullable=False),
          sa.Column('description', sa.String(), nullable=True),
          sa.Column('position', sa.Integer(), nullable=False),
          sa.PrimaryKeyConstraint('id')
      )
  
      op.get_bind()
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (1, 1, 'Monthly');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (2, 2, 'Quarterly');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (3, 3, '3 times a year');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (4, 4, 'Twice a year');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (5, 5, 'Yearly');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (6, 6, 'Every 2 years');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (7, 7, 'Every 3 years');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (8, 8, 'Every 4 years');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (9, 9, 'Every 5 years');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (10, 10, 'Ad-hoc');")
      op.execute("INSERT INTO frequency_of_release (id, position, description) VALUES (11, 11, 'Other');")
  
      # update existing data
      op.execute("UPDATE page SET frequency_id = 1 WHERE frequency = 'Monthly';")
  
      op.execute("UPDATE page SET frequency_id = 2 WHERE frequency = 'Quarterly';")
  
      op.execute("UPDATE page SET frequency_id = 3 WHERE frequency IN ('3 times a year', '3 times per year');")
  
      op.execute("UPDATE page SET frequency_id = 4 WHERE frequency IN ('Every six months', 'Every 6 months', 'Biannual');")
  
      op.execute("UPDATE page SET frequency_id = 5 WHERE frequency IN ('Annually', 'Annual');")
  
      op.execute("UPDATE page SET frequency_id =  6  WHERE frequency = 'Every 2 years';")
  
      op.execute("UPDATE page SET frequency_id = 10 WHERE frequency IN ('Ad-hoc', 'Ad hoc');")
  
      op.execute('''
               UPDATE page SET 
                 frequency_id = 11, 
                 frequency_other = 'Every 7 years (further publications dependent on further surveys being commissioned)'
               WHERE frequency = 'Every 7 years (further publications dependent on further surveys being commissioned)';
               ''')
  
      op.execute("UPDATE page SET frequency_id = 11, frequency_other = 'Term' WHERE frequency = 'Term';")
      op.execute(
          "UPDATE page SET frequency_id = 11, frequency_other = 'Every 10 years' WHERE frequency = 'Every 10 years';")
      op.execute(
          "UPDATE page SET frequency_id = 11, frequency_other = 'Every 4 to 5 years' WHERE frequency = 'Every 4 to 5 years';")
      op.execute(
          "UPDATE page SET frequency_id = 11, frequency_other = 'Every 3 to 4 years' WHERE frequency = 'Every 3 to 4 years';")
      op.execute("UPDATE page SET frequency_id = 11, frequency_other = 'Unconfirmed' WHERE frequency = 'Unconfirmed';")
  
      op.execute("UPDATE page SET frequency_id = NULL WHERE TRIM(frequency) = '';")
  
      op.create_foreign_key('frequency_of_release_fkey', 'page', 'frequency_of_release', ['frequency_id'], ['id'])
      # ### end Alembic commands ###
  
  
  def downgrade():
      # ### commands auto generated by Alembic - please adjust! ###
      op.drop_constraint('frequency_of_release_fkey', 'page', type_='foreignkey')
      op.drop_column('page', 'frequency_other')
      op.drop_column('page', 'frequency_id')
      op.drop_table('frequency_of_release')
      # ### end Alembic commands ###
  