new_contents: """Initial revision
  
  Revision ID: 075de24b065d
  Revises: 
  Create Date: 2017-09-25 15:24:04.717973
  
  """
  
  # revision identifiers, used by Alembic.
  revision = '075de24b065d'
  down_revision = None
  branch_labels = ('documents',)
  depends_on = '033d52604eac'
  
  from alembic import op
  import sqlalchemy as sa
  from sqlalchemy import FetchedValue
  from netprofile.db import ddl as npd
  from netprofile.db import fields as npf
  
  def upgrade():
      # ### commands auto generated by Alembic - please adjust! ###
      op.create_table('docs_bundles_def',
      sa.Column('dbid', npf.UInt32(), npd.Comment('Document bundle ID'), nullable=False, default=sa.Sequence('docs_bundles_def_dbid_seq')),
      sa.Column('name', sa.Unicode(length=255), npd.Comment('Document bundle name'), nullable=False),
      sa.PrimaryKeyConstraint('dbid', name=op.f('docs_bundles_def_pk')),
      mysql_charset='utf8',
      mysql_engine='InnoDB'
      )
      op.set_table_comment('docs_bundles_def', 'Document bundles')
      op.create_index('docs_bundles_def_u_name', 'docs_bundles_def', ['name'], unique=True)
      op.create_table('docs_def',
      sa.Column('docid', npf.UInt32(), npd.Comment('Document ID'), nullable=False, default=sa.Sequence('docs_def_docid_seq')),
      sa.Column('code', npf.ASCIIString(length=48), npd.Comment('Document code'), nullable=False),
      sa.Column('name', sa.Unicode(length=255), npd.Comment('Document name'), nullable=False),
      sa.Column('type', npf.DeclEnumType(name='DocumentType', values=['npdml', 'html-plain', 'html-ext']), npd.Comment('Template type'), server_default=sa.text("'npdml'"), nullable=False),
      sa.Column('external', npf.NPBoolean(), npd.Comment('Is externally stored?'), server_default=npf.npbool(False), nullable=False),
      sa.Column('body', sa.UnicodeText(), npd.Comment('Document body'), server_default=sa.text('NULL'), nullable=True),
      sa.Column('vars', npf.JSONData(), npd.Comment('List of variable templates'), server_default=sa.text('NULL'), nullable=True),
      sa.Column('descr', sa.UnicodeText(), npd.Comment('Description'), server_default=sa.text('NULL'), nullable=True),
      sa.PrimaryKeyConstraint('docid', name=op.f('docs_def_pk')),
      mysql_charset='utf8',
      mysql_engine='InnoDB'
      )
      op.set_table_comment('docs_def', 'Documents')
      op.create_index('docs_def_u_code', 'docs_def', ['code'], unique=True)
      op.create_index('docs_def_u_name', 'docs_def', ['name'], unique=True)
      op.create_table('docs_bundles_bits',
      sa.Column('dbbid', npf.UInt32(), npd.Comment('Document bundle bit ID'), nullable=False, default=sa.Sequence('docs_bundles_bits_dbbid_seq')),
      sa.Column('dbid', npf.UInt32(), npd.Comment('Document bundle ID'), nullable=False),
      sa.Column('docid', npf.UInt32(), npd.Comment('Document ID'), nullable=False),
      sa.Column('order', npf.UInt8(), npd.Comment('Order in bundle'), server_default=sa.text('1'), nullable=False),
      sa.Column('copies', npf.UInt8(), npd.Comment('Number of copies'), server_default=sa.text('1'), nullable=False),
      sa.ForeignKeyConstraint(['dbid'], ['docs_bundles_def.dbid'], name='docs_bundles_bits_fk_dbid', onupdate='CASCADE', ondelete='CASCADE'),
      sa.ForeignKeyConstraint(['docid'], ['docs_def.docid'], name='docs_bundles_bits_fk_docid', onupdate='CASCADE', ondelete='CASCADE'),
      sa.PrimaryKeyConstraint('dbbid', name=op.f('docs_bundles_bits_pk')),
      mysql_charset='utf8',
      mysql_engine='InnoDB'
      )
      op.set_table_comment('docs_bundles_bits', 'Document bundle contents')
      op.create_index('docs_bundles_bits_i_docid', 'docs_bundles_bits', ['docid'], unique=False)
      op.create_index('docs_bundles_bits_u_doc', 'docs_bundles_bits', ['dbid', 'docid'], unique=True)
      # ### end Alembic commands ###
  
  
  def downgrade():
      # ### commands auto generated by Alembic - please adjust! ###
      op.drop_index('docs_bundles_bits_u_doc', table_name='docs_bundles_bits')
      op.drop_index('docs_bundles_bits_i_docid', table_name='docs_bundles_bits')
      op.drop_table('docs_bundles_bits')
      op.drop_index('docs_def_u_name', table_name='docs_def')
      op.drop_index('docs_def_u_code', table_name='docs_def')
      op.drop_table('docs_def')
      op.drop_index('docs_bundles_def_u_name', table_name='docs_bundles_def')
      op.drop_table('docs_bundles_def')
      # ### end Alembic commands ###
  
  
subject: Add initial migration for documents module