old_contents: """add Attachment element
  
  Revision ID: 93bd528a83
  Revises: 51d6e03ecba
  Create Date: 2015-06-04 22:02:36.082013
  
  """
  
  # revision identifiers, used by Alembic.
  revision = '93bd528a83'
  down_revision = '51d6e03ecba'
  
  from alembic import op
  import sqlalchemy as sa
  
  
  from redwind import create_app
  from redwind import util
  from redwind import admin
  from redwind.models import Post, Attachment
  from redwind.extensions import db
  import os
  import datetime
  import random
  import string
  import mimetypes
  import shutil
  from flask import current_app
  
  
  def upgrade():
      # commands auto generated by Alembic - please adjust! ###
      op.create_table(
          'attachment',
          sa.Column('id', sa.Integer(), nullable=False, index=True),
          sa.Column('filename', sa.String(length=256), nullable=True),
          sa.Column('mimetype', sa.String(length=256), nullable=True),
          sa.Column('storage_path', sa.String(length=256), nullable=True),
          sa.Column('post_id', sa.Integer(), nullable=True),
          sa.ForeignKeyConstraint(['post_id'], ['post.id'], ),
          sa.PrimaryKeyConstraint('id'))
      # end Alembic commands ###
  
      convert_files_to_attachments()
  
  
  def downgrade():
      # commands auto generated by Alembic - please adjust! ###
      op.drop_table('attachment')
      # end Alembic commands ###
  
  
  def convert_file_to_attachment(post, filename):
      _, ext = os.path.splitext(filename)
      fullpath = os.path.join(current_app.root_path, '_data',
                              post.path, 'files', filename)
      if not os.path.exists(fullpath):
          print('could not find', fullpath)
          return
      now = post.published
      storage_path = '{}/{:02d}/{:02d}/{}'.format(
          now.year, now.month, now.day,
          ''.join(random.choice(string.ascii_letters + string.digits)
                  for _ in range(8)) + '-' + filename)
      mimetype, _ = mimetypes.guess_type(filename)
      attachment = Attachment(filename=filename,
                              mimetype=mimetype,
                              storage_path=storage_path)
  
      print(attachment.disk_path)
      os.makedirs(os.path.dirname(attachment.disk_path), exist_ok=True)
      shutil.copy2(fullpath, attachment.disk_path)
      post.attachments.append(attachment)
  
  
  def convert_files_to_attachments():
      app = create_app()
      with app.app_context():
          for post in Post.query.all():
              for a in post.attachments:
                  if os.path.exists(a.disk_path):
                      os.remove(a.disk_path)
                  db.session.delete(a)
  
              if not post.photos:
                  # check for files
                  filedir = os.path.join(
                      current_app.root_path, '_data', post.path, 'files')
                  if os.path.exists(filedir):
                      for filename in os.listdir(filedir):
                          convert_file_to_attachment(post, filename)
              else:
                  for photo in (post.photos or []):
                      filename = photo.get('filename')
                      convert_file_to_attachment(post, filename)
          db.session.commit()
  
new_contents: """add Attachment element
  
  Revision ID: 93bd528a83
  Revises: 51d6e03ecba
  Create Date: 2015-06-04 22:02:36.082013
  
  """
  
  # revision identifiers, used by Alembic.
  revision = '93bd528a83'
  down_revision = '51d6e03ecba'
  
  from alembic import op
  import sqlalchemy as sa
  
  
  from redwind import create_app
  from redwind import util
  from redwind import admin
  from redwind.models import Post, Attachment
  from redwind.extensions import db
  import os
  import datetime
  import random
  import string
  import mimetypes
  import shutil
  from flask import current_app
  
  
  def upgrade():
      # commands auto generated by Alembic - please adjust! ###
      op.create_table(
          'attachment',
          sa.Column('id', sa.Integer(), nullable=False, index=True),
          sa.Column('filename', sa.String(length=256), nullable=True),
          sa.Column('mimetype', sa.String(length=256), nullable=True),
          sa.Column('storage_path', sa.String(length=256), nullable=True),
          sa.Column('post_id', sa.Integer(), nullable=True),
          sa.ForeignKeyConstraint(['post_id'], ['post.id'], ),
          sa.PrimaryKeyConstraint('id'))
      # end Alembic commands ###
  
  
  def downgrade():
      # commands auto generated by Alembic - please adjust! ###
      op.drop_table('attachment')
      # end Alembic commands ###
  
  
subject: remove migration stuff from the alembic script, apparently I don't know how that works yet