def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('categories',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id'),
    # sa.UniqueConstraint('name')
    )
    op.create_table('roles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('default', sa.Boolean(), nullable=True),
    sa.Column('permissions', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_index(op.f('ix_roles_default'), 'roles', ['default'], unique=False)
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=64), nullable=True),
    sa.Column('username', sa.String(length=64), nullable=True),
    sa.Column('password_hash', sa.String(length=128), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.Column('confirmed', sa.Boolean(), nullable=True),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('location', sa.String(length=64), nullable=True),
    sa.Column('about_me', sa.Text(), nullable=True),
    sa.Column('member_since', sa.DateTime(), nullable=True),
    sa.Column('last_seen', sa.DateTime(), nullable=True),
    sa.Column('avatar_hash', sa.String(length=32), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('follows',
    sa.Column('follower_id', sa.Integer(), nullable=False),
    sa.Column('followed_id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['followed_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['follower_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('follower_id', 'followed_id')
    )
    op.create_table('posts',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.Column('title', sa.String(length=64), nullable=True),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('body_html', sa.Text(), nullable=True),
    sa.Column('summury', sa.Text(), nullable=True),
    sa.Column('summury_html', sa.Text(), nullable=True),
    sa.Column('category_id', sa.Integer(), nullable=True),
    sa.Column('is_public_disabled', sa.Boolean(), nullable=True),
    sa.Column('is_commented_disabled', sa.Boolean(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_posts_timestamp'), 'posts', ['timestamp'], unique=False)
    op.create_table('comments',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('body', sa.Text(), nullable=True),
    sa.Column('body_html', sa.Text(), nullable=True),
    sa.Column('timestamp', sa.DateTime(), nullable=True),
    sa.Column('disabled', sa.Boolean(), nullable=True),
    sa.Column('author_id', sa.Integer(), nullable=True),
    sa.Column('post_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['post_id'], ['posts.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_comments_timestamp'), 'comments', ['timestamp'], unique=False)
Exemple #2
0
    def _test_get_unique_constraints(self, schema=None):
        # SQLite dialect needs to parse the names of the constraints
        # separately from what it gets from PRAGMA index_list(), and
        # then matches them up.  so same set of column_names in two
        # constraints will confuse it.    Perhaps we should no longer
        # bother with index_list() here since we have the whole
        # CREATE TABLE?
        uniques = sorted(
            [
                {
                    "name": "unique_a",
                    "column_names": ["a"]
                },
                {
                    "name": "unique_a_b_c",
                    "column_names": ["a", "b", "c"]
                },
                {
                    "name": "unique_c_a_b",
                    "column_names": ["c", "a", "b"]
                },
                {
                    "name": "unique_asc_key",
                    "column_names": ["asc", "key"]
                },
                {
                    "name": "i.have.dots",
                    "column_names": ["b"]
                },
                {
                    "name": "i have spaces",
                    "column_names": ["c"]
                },
            ],
            key=operator.itemgetter("name"),
        )
        orig_meta = self.metadata
        table = Table(
            "testtbl",
            orig_meta,
            Column("a", sa.String(20)),
            Column("b", sa.String(30)),
            Column("c", sa.Integer),
            # reserved identifiers
            Column("asc", sa.String(30)),
            Column("key", sa.String(30)),
            schema=schema,
        )
        for uc in uniques:
            table.append_constraint(
                sa.UniqueConstraint(*uc["column_names"], name=uc["name"]))
        orig_meta.create_all()

        inspector = inspect(orig_meta.bind)
        reflected = sorted(
            inspector.get_unique_constraints("testtbl", schema=schema),
            key=operator.itemgetter("name"),
        )

        names_that_duplicate_index = set()

        for orig, refl in zip(uniques, reflected):
            # Different dialects handle duplicate index and constraints
            # differently, so ignore this flag
            dupe = refl.pop("duplicates_index", None)
            if dupe:
                names_that_duplicate_index.add(dupe)
            eq_(orig, refl)

        reflected_metadata = MetaData()
        reflected = Table(
            "testtbl",
            reflected_metadata,
            autoload_with=orig_meta.bind,
            schema=schema,
        )

        # test "deduplicates for index" logic.   MySQL and Oracle
        # "unique constraints" are actually unique indexes (with possible
        # exception of a unique that is a dupe of another one in the case
        # of Oracle).  make sure # they aren't duplicated.
        idx_names = set([idx.name for idx in reflected.indexes])
        uq_names = set([
            uq.name for uq in reflected.constraints
            if isinstance(uq, sa.UniqueConstraint)
        ]).difference(["unique_c_a_b"])

        assert not idx_names.intersection(uq_names)
        if names_that_duplicate_index:
            eq_(names_that_duplicate_index, idx_names)
            eq_(uq_names, set())
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'corona__person',
        sa.Column('uuid',
                  postgresql.UUID(as_uuid=True),
                  server_default=sa.text('uuid_generate_v4()'),
                  nullable=True), sa.Column('id', sa.Integer(),
                                            nullable=False),
        sa.Column('name', sa.String(length=64), nullable=False),
        sa.Column('gender', sa.String(length=10), nullable=False),
        sa.Column('age', sa.Integer(), nullable=False),
        sa.Column('address', sa.String(length=128), nullable=False),
        sa.Column('town', sa.String(length=40), nullable=False),
        sa.Column('phone', sa.Unicode(length=20), nullable=False),
        sa.Column('location', sa.String(length=64), nullable=False),
        sa.Column('coordinates',
                  postgresql.JSON(astext_type=sa.Text()),
                  nullable=False),
        sa.Column('type_of_person', sa.String(length=15), nullable=False),
        sa.Column('created_at',
                  sa.DateTime(),
                  server_default=sa.text('now()'),
                  nullable=True),
        sa.Column('updated_at',
                  sa.DateTime(),
                  server_default=sa.text('now()'),
                  nullable=True), sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('uuid'))
    op.create_index(op.f('ix_corona__person_created_at'),
                    'corona__person', ['created_at'],
                    unique=False)
    op.create_index(op.f('ix_corona__person_gender'),
                    'corona__person', ['gender'],
                    unique=False)
    op.create_index(op.f('ix_corona__person_id'),
                    'corona__person', ['id'],
                    unique=False)
    op.create_index(op.f('ix_corona__person_name'),
                    'corona__person', ['name'],
                    unique=False)
    op.create_index(op.f('ix_corona__person_type_of_person'),
                    'corona__person', ['type_of_person'],
                    unique=False)
    op.create_index(op.f('ix_corona__person_updated_at'),
                    'corona__person', ['updated_at'],
                    unique=False)
    op.create_table(
        'corona__association',
        sa.Column('uuid',
                  postgresql.UUID(as_uuid=True),
                  server_default=sa.text('uuid_generate_v4()'),
                  nullable=True),
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('patient_id', sa.Integer(), nullable=False),
        sa.Column('suspect_id', sa.Integer(), nullable=False),
        sa.Column('start_date', sa.DateTime(), nullable=False),
        sa.Column('end_date', sa.DateTime(), nullable=False),
        sa.Column('category_of_suspect', sa.Integer(), nullable=False),
        sa.Column('severity', sa.Integer(), nullable=False),
        sa.Column('created_at',
                  sa.DateTime(),
                  server_default=sa.text('now()'),
                  nullable=True),
        sa.Column('updated_at',
                  sa.DateTime(),
                  server_default=sa.text('now()'),
                  nullable=True),
        sa.ForeignKeyConstraint(
            ['patient_id'],
            ['corona__person.id'],
        ), sa.ForeignKeyConstraint(
            ['suspect_id'],
            ['corona__person.id'],
        ), sa.PrimaryKeyConstraint('id', 'patient_id', 'suspect_id'),
        sa.UniqueConstraint('uuid'))
    op.create_index(op.f('ix_corona__association_created_at'),
                    'corona__association', ['created_at'],
                    unique=False)
    op.create_index(op.f('ix_corona__association_id'),
                    'corona__association', ['id'],
                    unique=False)
    op.create_index(op.f('ix_corona__association_updated_at'),
                    'corona__association', ['updated_at'],
                    unique=False)
def upgrade():
    op.create_table(
        'group',
        sa.Column('group_id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=10), nullable=False),
        sa.PrimaryKeyConstraint('group_id'),
        sa.UniqueConstraint('name')
    )
    op.create_table(
        'role',
        sa.Column('role_id', sa.Integer(), nullable=False),
        sa.Column('role_name', sa.String(length=10), nullable=True),
        sa.PrimaryKeyConstraint('role_id')
    )
    op.create_table(
        'user',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('username', sa.String(length=20), nullable=False),
        sa.Column('email', sa.String(length=40), nullable=False),
        sa.Column('name', sa.String(length=50), nullable=False),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('password', sa.String(length=100), nullable=True),
        sa.Column('role', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['role'], ['role.role_id'], ),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('email'),
        sa.UniqueConstraint('username')
    )
    op.create_table(
        'course',
        sa.Column('course_id', sa.Integer(), nullable=False),
        sa.Column('course_name', sa.String(length=50), nullable=False),
        sa.Column('course_shortened', sa.String(length=10), nullable=False),
        sa.Column('course_tutor', sa.Integer(), nullable=True),
        sa.Column('labs_amount', sa.Integer(), nullable=False),
        sa.Column('lab_max_score', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['course_tutor'], ['user.id'], ),
        sa.PrimaryKeyConstraint('course_id')
    )
    op.create_table(
        'user_groups',
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('group_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['group_id'], ['group.group_id'], ),
        sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
    )
    op.create_table(
        'user_roles',
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('role_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['role_id'], ['role.role_id'], ),
        sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
    )
    op.create_table(
        'group_courses',
        sa.Column('group_id', sa.Integer(), nullable=True),
        sa.Column('course_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['course_id'], ['course.course_id'], ),
        sa.ForeignKeyConstraint(['group_id'], ['group.group_id'], )
    )
    op.create_table(
        'report',
        sa.Column('report_id', sa.Integer(), nullable=False),
        sa.Column('report_course', sa.Integer(), nullable=True),
        sa.Column('report_student', sa.Integer(), nullable=True),
        sa.Column('report_num', sa.Integer(), nullable=False),
        sa.Column('report_mark', sa.Integer(), nullable=True),
        sa.Column('report_uploaded', sa.DateTime(), nullable=False),
        sa.Column('report_checked', sa.DateTime(), nullable=True),
        sa.Column('report_stu_comment', sa.Text(), nullable=True),
        sa.Column('report_tut_comment', sa.Text(), nullable=True),
        sa.Column('report_hash', sa.String(length=32), nullable=False),
        sa.ForeignKeyConstraint(['report_course'], ['course.course_id'], ),
        sa.ForeignKeyConstraint(['report_student'], ['user.id'], ),
        sa.PrimaryKeyConstraint('report_id')
    )
Exemple #5
0
class Generator(db.Table):
  id_t = _GeneratorId
  __tablename__ = "generators"

  # Columns.
  id: int = sql.Column(id_t, primary_key=True)
  date_added: datetime.datetime = sql.Column(
    sql.DateTime().with_variant(mysql.DATETIME(fsp=3), "mysql"),
    nullable=False,
    default=labdate.GetUtcMillisecondsNow,
  )
  # MySQL maximum key length is 3072, with 3 bytes per character. We must
  # preserve 16 bytes for the unique constraint.
  name: str = sql.Column(
    sql.String(4096).with_variant(sql.String((3072 - 16) // 3), "mysql"),
    nullable=False,
  )
  optset_id: bytes = sql.Column(_GeneratorOptSetId, nullable=False)

  # Relationships.
  testcases: typing.List["Testcase"] = orm.relationship(
    "Testcase", back_populates="generator"
  )
  optset: typing.List["GeneratorOpt"] = orm.relationship(
    "GeneratorOpt",
    secondary="generator_optsets",
    primaryjoin="GeneratorOptSet.id == Generator.optset_id",
    secondaryjoin="GeneratorOptSet.opt_id == GeneratorOpt.id",
  )

  # Constraints.
  __table_args__ = (
    sql.UniqueConstraint("name", "optset_id", name="unique_generator"),
  )

  @property
  def opts(self) -> typing.Dict[str, str]:
    """Get the generator options.

    Returns:
      A map of generator options.
    """
    return {opt.name.string: opt.value.string for opt in self.optset}

  def SetProto(self, proto: deepsmith_pb2.Generator) -> deepsmith_pb2.Generator:
    """Set a protocol buffer representation.

    Args:
      proto: A protocol buffer message.

    Returns:
      A Generator message.
    """
    proto.name = self.name
    for opt in self.optset:
      proto.opts[opt.name.string] = opt.value.string
    return proto

  def ToProto(self) -> deepsmith_pb2.Generator:
    """Create protocol buffer representation.

    Returns:
      A Generator message.
    """
    proto = deepsmith_pb2.Generator()
    return self.SetProto(proto)

  @classmethod
  def GetOrAdd(
    cls, session: db.session_t, proto: deepsmith_pb2.Generator
  ) -> "Generator":

    # Build the list of options, and md5sum the key value strings.
    opts = []
    md5 = hashlib.md5()
    for proto_opt_name in sorted(proto.opts):
      proto_opt_value = proto.opts[proto_opt_name]
      md5.update((proto_opt_name + proto_opt_value).encode("utf-8"))
      opt = labm8.py.sqlutil.GetOrAdd(
        session,
        GeneratorOpt,
        name=GeneratorOptName.GetOrAdd(session, proto_opt_name),
        value=GeneratorOptValue.GetOrAdd(session, proto_opt_value),
      )
      opts.append(opt)

    # Create optset table entries.
    optset_id = md5.digest()
    for opt in opts:
      labm8.py.sqlutil.GetOrAdd(session, GeneratorOptSet, id=optset_id, opt=opt)

    return labm8.py.sqlutil.GetOrAdd(
      session, cls, name=proto.name, optset_id=optset_id,
    )
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'Passwords',
        sa.Column('password_id', mysql.INTEGER(unsigned=True), nullable=False),
        sa.Column('hashed_password', sa.BINARY(length=128), nullable=False),
        sa.PrimaryKeyConstraint('password_id'))
    op.create_index(op.f('ix_Passwords_hashed_password'),
                    'Passwords', ['hashed_password'],
                    unique=False)
    op.create_table(
        'Roles',
        sa.Column('role_id', mysql.INTEGER(unsigned=True), nullable=False),
        sa.Column('name', sa.VARCHAR(length=30), nullable=False),
        sa.PrimaryKeyConstraint('role_id'), sa.UniqueConstraint('name'))
    op.create_table(
        'UserGroups',
        sa.Column('group_id', mysql.INTEGER(unsigned=True), nullable=False),
        sa.Column('name', sa.VARCHAR(length=30), nullable=False),
        sa.PrimaryKeyConstraint('group_id'), sa.UniqueConstraint('name'))
    op.create_table(
        'Users',
        sa.Column('user_id', mysql.INTEGER(unsigned=True), nullable=False),
        sa.Column('time', mysql.DATETIME(), nullable=False),
        sa.Column('timestamp', mysql.DATETIME(), nullable=False),
        sa.Column('username', sa.VARCHAR(length=128), nullable=False),
        sa.Column('password_salt', sa.BINARY(length=32), nullable=False),
        sa.PrimaryKeyConstraint('user_id'), sa.UniqueConstraint('username'))
    op.create_index(op.f('ix_Users_password_salt'),
                    'Users', ['password_salt'],
                    unique=False)
    op.create_index(op.f('ix_Users_time'), 'Users', ['time'], unique=False)
    op.create_index(op.f('ix_Users_timestamp'),
                    'Users', ['timestamp'],
                    unique=False)
    op.create_table(
        'ApiKeys',
        sa.Column('api_key_id', mysql.INTEGER(unsigned=True), nullable=False),
        sa.Column('user_id', mysql.INTEGER(unsigned=True), nullable=False),
        sa.Column('api_key', sa.BINARY(length=16), nullable=False),
        sa.Column('description', sa.VARCHAR(length=255), nullable=True),
        sa.Column('created', mysql.DATETIME(), nullable=False),
        sa.ForeignKeyConstraint(
            ['user_id'],
            ['Users.user_id'],
        ), sa.PrimaryKeyConstraint('api_key_id'),
        sa.UniqueConstraint('api_key'))
    op.create_index(op.f('ix_ApiKeys_created'),
                    'ApiKeys', ['created'],
                    unique=False)
    op.create_table(
        'UserGroupsToRoles',
        sa.Column('user_group_id', mysql.INTEGER(unsigned=True),
                  nullable=True),
        sa.Column('role_id', mysql.INTEGER(unsigned=True), nullable=True),
        sa.ForeignKeyConstraint(
            ['role_id'],
            ['Roles.role_id'],
        ), sa.ForeignKeyConstraint(
            ['user_group_id'],
            ['UserGroups.group_id'],
        ))
    op.create_table(
        'UsersToUserGroups',
        sa.Column('user_id', mysql.INTEGER(unsigned=True), nullable=True),
        sa.Column('user_group_id', mysql.INTEGER(unsigned=True),
                  nullable=True),
        sa.ForeignKeyConstraint(
            ['user_group_id'],
            ['UserGroups.group_id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['Users.user_id'],
        ))
    ### end Alembic commands ###

    session = User._session

    # Create a few base Roles
    roles = ["admin", "read_all", "hue_rw", "nest_rw"]
    for role in roles:
        Role.insert(name=role)

    # Create a few base groups
    groups = {
        "administrator": ['admin'],
        "user": ['read_all'],
        "google": ['hue_rw', 'nest_rw']
    }

    # Create group/role mappings in the DB
    for group, roles in groups.iteritems():
        g = UserGroup.insert(name=group)

        for role in roles:
            r = Role.filter_by(name=role).first()
            g.roles.append(r)

    session.commit()

    # Grant `administrator` group the `admin` role
    admin_role = Role.filter_by(name='admin').first()
    admin_group = UserGroup.filter_by(name="administrator").first()
    admin_group.roles.append(admin_role)
    session.commit()

    # Create our admin/admin user
    now = datetime.datetime.utcnow()
    u = User.insert(username='******', time=now, timestamp=now)
    session.commit()
    session.flush()

    # This create a default password of `admin` for our admin user, with hard coded time complexity values
    # These hard-coded values are used during login if the admin user appears to be initiating a first-login
    p = Password.insert(hashed_password=bytearray(
        argon2_hash("admin", u.password_salt, t=2000, m=1024)))
    session.commit()

    # Add admin user to `administrator` group
    u.user_groups.append(admin_group)
    session.commit()
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('admin',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=30), nullable=True),
    sa.Column('password', sa.Integer(), nullable=True),
    sa.Column('is_super', sa.SmallInteger(), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_index(op.f('ix_admin_addtime'), 'admin', ['addtime'], unique=False)
    op.create_table('auth',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=True),
    sa.Column('url', sa.String(length=255), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name'),
    sa.UniqueConstraint('url')
    )
    op.create_index(op.f('ix_auth_addtime'), 'auth', ['addtime'], unique=False)
    op.create_table('preview',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('title', sa.String(length=255), nullable=True),
    sa.Column('logo', sa.String(length=255), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('title')
    )
    op.create_index(op.f('ix_preview_addtime'), 'preview', ['addtime'], unique=False)
    op.create_table('tag',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=255), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_index(op.f('ix_tag_addtime'), 'tag', ['addtime'], unique=False)
    op.create_table('user',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(length=30), nullable=True),
    sa.Column('password', sa.Integer(), nullable=True),
    sa.Column('email', sa.String(length=100), nullable=True),
    sa.Column('phone', sa.String(length=11), nullable=True),
    sa.Column('info', sa.Text(), nullable=True),
    sa.Column('face', sa.String(length=255), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.Column('uuid', sa.String(length=255), nullable=True),
    sa.Column('isdelete', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email'),
    sa.UniqueConstraint('name'),
    sa.UniqueConstraint('uuid')
    )
    op.create_index(op.f('ix_user_addtime'), 'user', ['addtime'], unique=False)
    op.create_table('adminlog',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('ip', sa.String(length=255), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.Column('admin_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['admin_id'], ['admin.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_adminlog_addtime'), 'adminlog', ['addtime'], unique=False)
    op.create_table('movie',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('title', sa.String(length=255), nullable=True),
    sa.Column('url', sa.String(length=255), nullable=True),
    sa.Column('info', sa.Text(), nullable=True),
    sa.Column('logo', sa.String(length=255), nullable=True),
    sa.Column('star', sa.SmallInteger(), nullable=True),
    sa.Column('playnum', sa.BigInteger(), nullable=True),
    sa.Column('commentnum', sa.BigInteger(), nullable=True),
    sa.Column('release_time', sa.Date(), nullable=True),
    sa.Column('alength', sa.String(length=255), nullable=True),
    sa.Column('area', sa.String(length=255), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.Column('tag_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('title'),
    sa.UniqueConstraint('url')
    )
    op.create_index(op.f('ix_movie_addtime'), 'movie', ['addtime'], unique=False)
    op.create_table('oplog',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('ip', sa.String(length=255), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.Column('reason', sa.String(length=255), nullable=True),
    sa.Column('admin_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['admin_id'], ['admin.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_oplog_addtime'), 'oplog', ['addtime'], unique=False)
    op.create_table('userlog',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('ip', sa.String(length=255), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_userlog_addtime'), 'userlog', ['addtime'], unique=False)
    op.create_table('comment',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('content', sa.Text(), nullable=True),
    sa.Column('movie_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['movie_id'], ['movie.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_comment_addtime'), 'comment', ['addtime'], unique=False)
    op.create_table('moviecol',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('movie_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['movie_id'], ['movie.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_moviecol_addtime'), 'moviecol', ['addtime'], unique=False)
Exemple #8
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "environment_build",
        sa.Column("build_uuid", sa.String(length=36), nullable=False),
        sa.Column("project_uuid", sa.String(length=36), nullable=False),
        sa.Column("environment_uuid", sa.String(length=36), nullable=False),
        sa.Column("project_path", sa.String(length=4096), nullable=False),
        sa.Column("requested_time", sa.DateTime(), nullable=False),
        sa.Column("started_time", sa.DateTime(), nullable=True),
        sa.Column("finished_time", sa.DateTime(), nullable=True),
        sa.Column("status", sa.String(length=15), nullable=True),
        sa.PrimaryKeyConstraint("build_uuid", name=op.f("pk_environment_build")),
        sa.UniqueConstraint("build_uuid", name=op.f("uq_environment_build_build_uuid")),
    )
    op.create_index(
        op.f("ix_environment_build_environment_uuid"),
        "environment_build",
        ["environment_uuid"],
        unique=False,
    )
    op.create_index(
        op.f("ix_environment_build_project_path"),
        "environment_build",
        ["project_path"],
        unique=False,
    )
    op.create_index(
        op.f("ix_environment_build_project_uuid"),
        "environment_build",
        ["project_uuid"],
        unique=False,
    )
    op.create_index(
        "uuid_proj_env_index",
        "environment_build",
        ["project_uuid", "environment_uuid"],
        unique=False,
    )
    op.create_table(
        "experiments",
        sa.Column("experiment_uuid", sa.String(length=36), nullable=False),
        sa.Column("project_uuid", sa.String(length=36), nullable=True),
        sa.Column("pipeline_uuid", sa.String(length=36), nullable=True),
        sa.Column("total_number_of_pipeline_runs", sa.Integer(), nullable=False),
        sa.Column("scheduled_start", sa.DateTime(), nullable=False),
        sa.Column(
            "completed_pipeline_runs",
            sa.Integer(),
            server_default=sa.text("0"),
            nullable=True,
        ),
        sa.PrimaryKeyConstraint("experiment_uuid", name=op.f("pk_experiments")),
    )
    op.create_table(
        "interactive_sessions",
        sa.Column("project_uuid", sa.String(length=36), nullable=False),
        sa.Column("pipeline_uuid", sa.String(length=36), nullable=False),
        sa.Column("status", sa.String(length=10), nullable=True),
        sa.Column("jupyter_server_ip", sa.String(length=15), nullable=True),
        sa.Column(
            "notebook_server_info",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=True,
        ),
        sa.Column(
            "container_ids", postgresql.JSONB(astext_type=sa.Text()), nullable=True
        ),
        sa.PrimaryKeyConstraint(
            "project_uuid", "pipeline_uuid", name=op.f("pk_interactive_sessions")
        ),
        sa.UniqueConstraint(
            "jupyter_server_ip", name=op.f("uq_interactive_sessions_jupyter_server_ip")
        ),
        sa.UniqueConstraint(
            "notebook_server_info",
            name=op.f("uq_interactive_sessions_notebook_server_info"),
        ),
    )
    op.create_table(
        "pipeline_runs",
        sa.Column("project_uuid", sa.String(length=36), nullable=True),
        sa.Column("pipeline_uuid", sa.String(length=36), nullable=False),
        sa.Column("run_uuid", sa.String(length=36), nullable=False),
        sa.Column("status", sa.String(length=15), nullable=True),
        sa.Column("started_time", sa.DateTime(), nullable=True),
        sa.Column("finished_time", sa.DateTime(), nullable=True),
        sa.Column("type", sa.String(length=50), nullable=True),
        sa.Column("experiment_uuid", sa.String(length=36), nullable=True),
        sa.Column("pipeline_run_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["experiment_uuid"],
            ["experiments.experiment_uuid"],
            name=op.f("fk_pipeline_runs_experiment_uuid_experiments"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("run_uuid", name=op.f("pk_pipeline_runs")),
    )
    op.create_table(
        "pipeline_run_image_mappings",
        sa.Column("run_uuid", sa.String(length=36), nullable=False),
        sa.Column("orchest_environment_uuid", sa.String(length=36), nullable=False),
        sa.Column("docker_img_id", sa.String(), nullable=False),
        sa.ForeignKeyConstraint(
            ["run_uuid"],
            ["pipeline_runs.run_uuid"],
            name=op.f("fk_pipeline_run_image_mappings_run_uuid_pipeline_runs"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint(
            "run_uuid",
            "orchest_environment_uuid",
            "docker_img_id",
            name=op.f("pk_pipeline_run_image_mappings"),
        ),
        sa.UniqueConstraint(
            "run_uuid",
            "docker_img_id",
            name=op.f("uq_pipeline_run_image_mappings_run_uuid_docker_img_id"),
        ),
        sa.UniqueConstraint(
            "run_uuid",
            "orchest_environment_uuid",
            name=op.f(
                "uq_pipeline_run_image_mappings_run_uuid_orchest_environment_uuid"
            ),
        ),
    )
    op.create_index(
        op.f("ix_pipeline_run_image_mappings_docker_img_id"),
        "pipeline_run_image_mappings",
        ["docker_img_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_pipeline_run_image_mappings_orchest_environment_uuid"),
        "pipeline_run_image_mappings",
        ["orchest_environment_uuid"],
        unique=False,
    )
    op.create_index(
        op.f("ix_pipeline_run_image_mappings_run_uuid"),
        "pipeline_run_image_mappings",
        ["run_uuid"],
        unique=False,
    )
    op.create_table(
        "pipeline_run_steps",
        sa.Column("run_uuid", sa.String(length=36), nullable=False),
        sa.Column("step_uuid", sa.String(length=36), nullable=False),
        sa.Column("status", sa.String(length=15), nullable=True),
        sa.Column("started_time", sa.DateTime(), nullable=True),
        sa.Column("finished_time", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["run_uuid"],
            ["pipeline_runs.run_uuid"],
            name=op.f("fk_pipeline_run_steps_run_uuid_pipeline_runs"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint(
            "run_uuid", "step_uuid", name=op.f("pk_pipeline_run_steps")
        ),
    )
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'app_tokens', sa.Column('creation_date', sa.Integer(), nullable=False),
        sa.Column('modification_date', sa.Integer(), nullable=True),
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('version', sa.Integer(), nullable=True),
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True),
        sa.Column('creator', sa.String(), nullable=True),
        sa.Column('modifier', sa.String(), nullable=True),
        sa.Column('username', sa.String(), nullable=False),
        sa.Column('expiration_date', sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tb_app_tokens')),
        sa.UniqueConstraint('id', name=op.f('app_tokens_id_key')))
    op.create_table(
        'persons', sa.Column('creation_date', sa.Integer(), nullable=False),
        sa.Column('modification_date', sa.Integer(), nullable=True),
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('version', sa.Integer(), nullable=True),
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True),
        sa.Column('creator', sa.String(), nullable=True),
        sa.Column('modifier', sa.String(), nullable=True),
        sa.Column('name', sa.String(), nullable=False),
        sa.Column('last_name', sa.String(), nullable=True),
        sa.Column('full_name', sa.String(), nullable=True),
        sa.Column('address', sa.String(), nullable=True),
        sa.Column('phone', sa.String(), nullable=True),
        sa.Column('image', postgresql.UUID(), nullable=True),
        sa.Column('email', sa.String(), nullable=True),
        sa.Column('cell_no', sa.String(), nullable=True),
        sa.Column('current_book_id', postgresql.UUID(), nullable=True),
        sa.Column('bio', sa.String(), nullable=True),
        sa.Column('is_legal', sa.Boolean(), nullable=True),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tb_persons')),
        sa.UniqueConstraint('cell_no', name=op.f('personcells_id_key')),
        sa.UniqueConstraint('email', name=op.f('personemails_id_key')),
        sa.UniqueConstraint('id', name=op.f('persons_id_key')))
    op.create_table(
        'stores', sa.Column('creation_date', sa.Integer(), nullable=False),
        sa.Column('modification_date', sa.Integer(), nullable=True),
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('version', sa.Integer(), nullable=True),
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True),
        sa.Column('creator', sa.String(), nullable=True),
        sa.Column('modifier', sa.String(), nullable=True),
        sa.Column('name', sa.String(), nullable=False),
        sa.Column('address', sa.String(), nullable=True),
        sa.Column('phone', sa.String(), nullable=True),
        sa.Column('image', postgresql.UUID(), nullable=True),
        sa.Column('email', sa.String(), nullable=True),
        sa.Column('store_code', sa.String(), nullable=False),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tb_stores')),
        sa.UniqueConstraint('email', name=op.f('stores_id_key')),
        sa.UniqueConstraint('id', name=op.f('stores_id_key')),
        sa.UniqueConstraint('store_code', name=op.f('storescode_id_key')))
    op.create_table(
        'accounts', sa.Column('creation_date', sa.Integer(), nullable=False),
        sa.Column('modification_date', sa.Integer(), nullable=True),
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('version', sa.Integer(), nullable=True),
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True),
        sa.Column('creator', sa.String(), nullable=True),
        sa.Column('modifier', sa.String(), nullable=True),
        sa.Column('person_id', postgresql.UUID(), nullable=False),
        sa.Column('value', sa.Float(), nullable=True),
        sa.Column('type',
                  postgresql.ENUM('Main',
                                  'Star',
                                  'Discount',
                                  'Postpaid',
                                  'Prepaid',
                                  name='accounttypes'),
                  nullable=False),
        sa.ForeignKeyConstraint(['person_id'], ['persons.id'],
                                name=op.f('fk_tb_accounts_col_person_id')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tb_accounts')),
        sa.UniqueConstraint('id', name=op.f('accounts_id_key')))
    op.create_table(
        'payments', sa.Column('creation_date', sa.Integer(), nullable=False),
        sa.Column('modification_date', sa.Integer(), nullable=True),
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('version', sa.Integer(), nullable=True),
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True),
        sa.Column('creator', sa.String(), nullable=True),
        sa.Column('modifier', sa.String(), nullable=True),
        sa.Column('person_id', postgresql.UUID(), nullable=True),
        sa.Column('amount', sa.Float(), nullable=False),
        sa.Column('shopping_key', sa.String(), nullable=True),
        sa.Column('reference_code', sa.String(), nullable=True),
        sa.Column('details', sa.JSON(), nullable=True),
        sa.Column('order_details', sa.JSON(), nullable=True),
        sa.Column('agent', sa.String(), nullable=True),
        sa.Column('used', sa.Boolean(), nullable=True),
        sa.Column('status', sa.String(), nullable=True),
        sa.ForeignKeyConstraint(['person_id'], ['persons.id'],
                                name=op.f('fk_tb_payments_col_person_id')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tb_payments')),
        sa.UniqueConstraint('id', name=op.f('payments_id_key')))
    op.create_table(
        'receipts', sa.Column('creation_date', sa.Integer(), nullable=False),
        sa.Column('modification_date', sa.Integer(), nullable=True),
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('version', sa.Integer(), nullable=True),
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True),
        sa.Column('creator', sa.String(), nullable=True),
        sa.Column('modifier', sa.String(), nullable=True),
        sa.Column('title', sa.String(), nullable=False),
        sa.Column('payee_id', postgresql.UUID(), nullable=False),
        sa.Column('payer_id', postgresql.UUID(), nullable=True),
        sa.Column('payer_name', sa.String(), nullable=True),
        sa.Column('body', sa.JSON(), nullable=False),
        sa.Column('total_payment', sa.Integer(), nullable=True),
        sa.Column('details', sa.JSON(), nullable=True),
        sa.Column('status', sa.String(), nullable=False),
        sa.ForeignKeyConstraint(['payee_id'], ['stores.id'],
                                name=op.f('fk_tb_receipts_col_payee_id')),
        sa.ForeignKeyConstraint(['payer_id'], ['persons.id'],
                                name=op.f('fk_tb_receipts_col_payer_id')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tb_receipts')),
        sa.UniqueConstraint('id', name=op.f('receipts_id_key')))
    op.create_table(
        'users', sa.Column('creation_date', sa.Integer(), nullable=False),
        sa.Column('modification_date', sa.Integer(), nullable=True),
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('version', sa.Integer(), nullable=True),
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True),
        sa.Column('creator', sa.String(), nullable=True),
        sa.Column('modifier', sa.String(), nullable=True),
        sa.Column('username', sa.String(), nullable=False),
        sa.Column('password', sa.String(), nullable=False),
        sa.Column('person_id', postgresql.UUID(), nullable=True),
        sa.ForeignKeyConstraint(['person_id'], ['persons.id'],
                                name=op.f('fk_tb_users_col_person_id')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tb_users')),
        sa.UniqueConstraint('id', name=op.f('users_id_key')),
        sa.UniqueConstraint('username', name=op.f('username_id_key')))
    op.create_table(
        'transactions', sa.Column('creation_date',
                                  sa.Integer(),
                                  nullable=False),
        sa.Column('modification_date', sa.Integer(), nullable=True),
        sa.Column('id', postgresql.UUID(), nullable=False),
        sa.Column('version', sa.Integer(), nullable=True),
        sa.Column('tags', sa.ARRAY(sa.String()), nullable=True),
        sa.Column('creator', sa.String(), nullable=True),
        sa.Column('modifier', sa.String(), nullable=True),
        sa.Column('account_id', postgresql.UUID(), nullable=True),
        sa.Column('receipt_id', postgresql.UUID(), nullable=True),
        sa.Column('credit', sa.Float(), nullable=True),
        sa.Column('debit', sa.Float(), nullable=True),
        sa.Column('payment_id', postgresql.UUID(), nullable=True),
        sa.Column('details', sa.JSON(), nullable=True),
        sa.ForeignKeyConstraint(
            ['account_id'], ['accounts.id'],
            name=op.f('fk_tb_transactions_col_account_id')),
        sa.ForeignKeyConstraint(
            ['payment_id'], ['payments.id'],
            name=op.f('fk_tb_transactions_col_payment_id')),
        sa.ForeignKeyConstraint(
            ['receipt_id'], ['receipts.id'],
            name=op.f('fk_tb_transactions_col_receipt_id')),
        sa.PrimaryKeyConstraint('id', name=op.f('pk_tb_transactions')),
        sa.UniqueConstraint('id', name=op.f('transactions_id_key')))
import sqlalchemy as sa

from modmod.models.base import (
    Base,
)

user_library = sa.Table(
    'user_library',
    Base.metadata,
    sa.Column('id', sa.Integer, primary_key=True),
    sa.Column('user_id', sa.Integer, sa.ForeignKey('user.id'), nullable=False),
    sa.Column('library_id', sa.Integer, sa.ForeignKey('library.id'), nullable=False),
    sa.UniqueConstraint('user_id', 'library_id', name='user_id_library_id')
)
def upgrade():

    op.create_table(
        'aim_vmm_policies', sa.Column('type', sa.String(64), nullable=False),
        sa.Column('aim_id', sa.Integer, autoincrement=True),
        sa.Column('display_name', sa.String(256), nullable=False, default=''),
        sa.Column('monitored', sa.Boolean, nullable=False, default=False),
        sa.PrimaryKeyConstraint('aim_id'))

    session = api.get_session(expire_on_commit=True)
    old_vmm_table = sa.Table('aim_vmm_domains', sa.MetaData(),
                             sa.Column('type', sa.String(64), nullable=False),
                             sa.Column('name', sa.String(64), nullable=False))
    old_phys_table = sa.Table('aim_physical_domains', sa.MetaData(),
                              sa.Column('name', sa.String(64), nullable=False))

    mgr = aim_manager.AimManager()
    ctx = context.AimContext(db_session=session)
    new_vmms = []
    new_phys = []
    with session.begin(subtransactions=True):
        for vmm in session.query(old_vmm_table).all():
            new_vmms.append(
                resource.VMMDomain(type=vmm.type,
                                   name=vmm.name,
                                   monitored=True))
        for phys in session.query(old_phys_table).all():
            new_phys.append(
                resource.PhysicalDomain(name=phys.name, monitored=True))

    op.drop_table('aim_vmm_domains')
    op.drop_table('aim_physical_domains')

    op.create_table(
        'aim_vmm_domains', sa.Column('type', sa.String(64), nullable=False),
        sa.Column('name', sa.String(64), nullable=False),
        sa.Column('aim_id', sa.Integer, autoincrement=True),
        sa.Column('display_name', sa.String(256), nullable=False, default=''),
        sa.Column('monitored', sa.Boolean, nullable=False, default=False),
        sa.Column('enforcement_pref', sa.Enum('sw', 'hw', 'unknown')),
        sa.Column('mode', sa.Enum('default', 'n1kv', 'unknown', 'ovs', 'k8s')),
        sa.Column('mcast_address', sa.String(64)),
        sa.Column('encap_mode', sa.Enum('unknown', 'vlan', 'vxlan')),
        sa.Column('pref_encap_mode', sa.Enum('unspecified', 'vlan', 'vxlan')),
        sa.Column('vlan_pool_name', sa.String(64)),
        sa.Column('vlan_pool_type', sa.Enum('static', 'dynamic')),
        sa.Column('mcast_addr_pool_name', sa.String(64)),
        sa.PrimaryKeyConstraint('aim_id'),
        sa.UniqueConstraint('type',
                            'name',
                            name='uniq_aim_vmm_domains_identity'),
        sa.Index('idx_aim_vmm_domains_identity', 'type', 'name'))

    op.create_table(
        'aim_physical_domains', sa.Column('name',
                                          sa.String(64),
                                          nullable=False),
        sa.Column('aim_id', sa.Integer, autoincrement=True),
        sa.Column('display_name', sa.String(256), nullable=False, default=''),
        sa.Column('monitored', sa.Boolean, nullable=False, default=False),
        sa.PrimaryKeyConstraint('aim_id'))

    with session.begin(subtransactions=True):
        for obj in new_vmms + new_phys:
            mgr.create(ctx, obj)
Exemple #12
0
def upgrade():
    op.create_table(
        "journalists",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("username", sa.String(length=255), nullable=False),
        sa.Column("pw_salt", sa.Binary(), nullable=True),
        sa.Column("pw_hash", sa.Binary(), nullable=True),
        sa.Column("is_admin", sa.Boolean(), nullable=True),
        sa.Column("otp_secret", sa.String(length=16), nullable=True),
        sa.Column("is_totp", sa.Boolean(), nullable=True),
        sa.Column("hotp_counter", sa.Integer(), nullable=True),
        sa.Column("last_token", sa.String(length=6), nullable=True),
        sa.Column("created_on", sa.DateTime(), nullable=True),
        sa.Column("last_access", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("username"),
    )
    op.create_table(
        "sources",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("filesystem_id", sa.String(length=96), nullable=True),
        sa.Column("journalist_designation",
                  sa.String(length=255),
                  nullable=False),
        sa.Column("flagged", sa.Boolean(), nullable=True),
        sa.Column("last_updated", sa.DateTime(), nullable=True),
        sa.Column("pending", sa.Boolean(), nullable=True),
        sa.Column("interaction_count", sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("filesystem_id"),
    )
    op.create_table(
        "journalist_login_attempt",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("timestamp", sa.DateTime(), nullable=True),
        sa.Column("journalist_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["journalist_id"], ["journalists.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "replies",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("journalist_id", sa.Integer(), nullable=True),
        sa.Column("source_id", sa.Integer(), nullable=True),
        sa.Column("filename", sa.String(length=255), nullable=False),
        sa.Column("size", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["journalist_id"], ["journalists.id"]),
        sa.ForeignKeyConstraint(["source_id"], ["sources.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "source_stars",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("source_id", sa.Integer(), nullable=True),
        sa.Column("starred", sa.Boolean(), nullable=True),
        sa.ForeignKeyConstraint(["source_id"], ["sources.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "submissions",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("source_id", sa.Integer(), nullable=True),
        sa.Column("filename", sa.String(length=255), nullable=False),
        sa.Column("size", sa.Integer(), nullable=False),
        sa.Column("downloaded", sa.Boolean(), nullable=True),
        sa.ForeignKeyConstraint(["source_id"], ["sources.id"]),
        sa.PrimaryKeyConstraint("id"),
    )
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('offer',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('offer_name', sa.String(length=255), nullable=False),
    sa.Column('offer_start_date', sa.DateTime(), nullable=False),
    sa.Column('offer_end_date', sa.DateTime(), nullable=True),
    sa.Column('description', sa.Text(), nullable=False),
    sa.Column('discount_amount', sa.Numeric(precision=8, scale=2), nullable=True),
    sa.Column('discount_percentage', sa.Numeric(precision=5, scale=2), nullable=True),
    sa.Column('duration_months', sa.Integer(), nullable=True),
    sa.Column('duration_end_date', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('option',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('option_name', sa.String(length=255), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('software',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('software_name', sa.String(length=255), nullable=False),
    sa.Column('details', sa.Text(), nullable=True),
    sa.Column('access_link', sa.Text(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('user_account',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('first_name', sa.String(length=64), nullable=False),
    sa.Column('last_name', sa.String(length=64), nullable=False),
    sa.Column('user_name', sa.String(length=64), nullable=False),
    sa.Column('password_hash', sa.String(length=255), nullable=False),
    sa.Column('email', sa.String(length=128), nullable=False),
    sa.Column('confirmation_code', sa.String(length=255), nullable=False),
    sa.Column('confirmation_time', sa.DateTime(), nullable=True),
    sa.Column('insert_ts', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email'),
    sa.UniqueConstraint('user_name')
    )
    op.create_table('user_group_type',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('type_name', sa.String(length=128), nullable=False),
    sa.Column('members_min', sa.Integer(), nullable=False),
    sa.Column('members_max', sa.Integer(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('plan',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('plan_name', sa.String(length=255), nullable=False),
    sa.Column('software_id', sa.Integer(), nullable=False),
    sa.Column('user_group_type_id', sa.Integer(), nullable=False),
    sa.Column('current_price', sa.Boolean(), nullable=False),
    sa.Column('insert_ts', sa.DateTime(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.ForeignKeyConstraint(['software_id'], ['software.id'], ),
    sa.ForeignKeyConstraint(['user_group_type_id'], ['user_group_type.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('user_group',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_group_type_id', sa.Integer(), nullable=False),
    sa.Column('customer_invoice_data', sa.Text(), nullable=False),
    sa.Column('insert_ts', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['user_group_type_id'], ['user_group_type.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('in_group',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_group_id', sa.Integer(), nullable=False),
    sa.Column('user_account_id', sa.Integer(), nullable=False),
    sa.Column('time_added', sa.DateTime(), nullable=False),
    sa.Column('time_removed', sa.DateTime(), nullable=True),
    sa.Column('group_admin', sa.Boolean(), nullable=False),
    sa.ForeignKeyConstraint(['user_account_id'], ['user_account.id'], ),
    sa.ForeignKeyConstraint(['user_group_id'], ['user_group.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('include',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('offer_id', sa.Integer(), nullable=False),
    sa.Column('plan_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['offer_id'], ['offer.id'], ),
    sa.ForeignKeyConstraint(['plan_id'], ['plan.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('option_included',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('plan_id', sa.Integer(), nullable=False),
    sa.Column('option_id', sa.Integer(), nullable=False),
    sa.Column('date_added', sa.DateTime(), nullable=False),
    sa.Column('date_removed', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['option_id'], ['option.id'], ),
    sa.ForeignKeyConstraint(['plan_id'], ['plan.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('prerequisite',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('offer_id', sa.Integer(), nullable=False),
    sa.Column('plan_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['offer_id'], ['offer.id'], ),
    sa.ForeignKeyConstraint(['plan_id'], ['plan.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('subscription',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_group_id', sa.Integer(), nullable=False),
    sa.Column('trial_period_start_date', sa.DateTime(), nullable=True),
    sa.Column('trial_period_end_date', sa.DateTime(), nullable=True),
    sa.Column('subscribe_after_trial', sa.Boolean(), nullable=False),
    sa.Column('current_plan_id', sa.Integer(), nullable=False),
    sa.Column('offer_id', sa.Integer(), nullable=True),
    sa.Column('offer_start_date', sa.DateTime(), nullable=True),
    sa.Column('offer_end_date', sa.DateTime(), nullable=True),
    sa.Column('date_subscribed', sa.DateTime(), nullable=False),
    sa.Column('valid_to', sa.DateTime(), nullable=False),
    sa.Column('date_unsubscribed', sa.DateTime(), nullable=True),
    sa.Column('insert_ts', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['current_plan_id'], ['plan.id'], ),
    sa.ForeignKeyConstraint(['offer_id'], ['offer.id'], ),
    sa.ForeignKeyConstraint(['user_group_id'], ['user_group.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('deactivated_users',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_account_id', sa.Integer(), nullable=False),
    sa.Column('in_group_id', sa.Integer(), nullable=True),
    sa.Column('first_name', sa.String(length=64), nullable=False),
    sa.Column('last_name', sa.String(length=64), nullable=False),
    sa.Column('user_name', sa.String(length=64), nullable=False),
    sa.Column('password', sa.String(length=255), nullable=False),
    sa.Column('email', sa.String(length=128), nullable=False),
    sa.Column('deleted_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['in_group_id'], ['in_group.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email'),
    sa.UniqueConstraint('user_name')
    )
    op.create_table('plan_history',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('subscription_id', sa.Integer(), nullable=False),
    sa.Column('plan_id', sa.Integer(), nullable=False),
    sa.Column('date_start', sa.DateTime(), nullable=False),
    sa.Column('date_end', sa.DateTime(), nullable=False),
    sa.Column('insert_ts', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['plan_id'], ['plan.id'], ),
    sa.ForeignKeyConstraint(['subscription_id'], ['subscription.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('invoice',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('customer_invoice_data', sa.Text(), nullable=False),
    sa.Column('subscription_id', sa.Integer(), nullable=False),
    sa.Column('plan_history_id', sa.Integer(), nullable=False),
    sa.Column('invoice_period_start_date', sa.DateTime(), nullable=False),
    sa.Column('invoice_period_end_date', sa.DateTime(), nullable=False),
    sa.Column('invoice_description', sa.String(length=255), nullable=False),
    sa.Column('invoice_amount', sa.Numeric(precision=8, scale=2), nullable=False),
    sa.Column('invoice_created_ts', sa.DateTime(), nullable=False),
    sa.Column('invoice_due_ts', sa.DateTime(), nullable=False),
    sa.Column('invoice_paid_ts', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['plan_history_id'], ['plan_history.id'], ),
    sa.ForeignKeyConstraint(['subscription_id'], ['subscription.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('email', sa.String(length=80), nullable=False),
    sa.Column('mobile_login', sa.String(length=15), nullable=True),
    sa.Column('password', sa.String(length=256), nullable=False),
    sa.Column('creation_date', sa.DateTime(), nullable=True),
    sa.Column('updation_date', sa.DateTime(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('email_salt', sa.String(length=256), nullable=False),
    sa.Column('confirmed_on', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email'),
    sa.UniqueConstraint('mobile_login')
    )
    op.create_table('userroles',
    sa.Column('role_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('role', sa.String(length=80), nullable=False),
    sa.Column('creation_date', sa.DateTime(), nullable=True),
    sa.Column('updation_date', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('role_id')
    )
    op.create_table('useraddress',
    sa.Column('address_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('first_name', sa.String(length=50), nullable=True),
    sa.Column('last_name', sa.String(length=50), nullable=True),
    sa.Column('address1', sa.String(length=256), nullable=True),
    sa.Column('address2', sa.String(length=256), nullable=True),
    sa.Column('landmark', sa.String(length=256), nullable=True),
    sa.Column('state', sa.String(length=100), nullable=True),
    sa.Column('city', sa.String(length=75), nullable=True),
    sa.Column('pincode', sa.String(length=10), nullable=True),
    sa.Column('mobileno', sa.String(length=15), nullable=True),
    sa.Column('default_flag', sa.Boolean(), nullable=True),
    sa.Column('delete_flag', sa.Boolean(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('address_id')
    )
    op.create_table('userprofile',
    sa.Column('profile_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('first_name', sa.String(length=50), nullable=True),
    sa.Column('last_name', sa.String(length=50), nullable=True),
    sa.Column('gender', sa.String(length=6), nullable=True),
    sa.Column('mobile_number', sa.String(length=15), nullable=True),
    sa.Column('creation_date', sa.DateTime(), nullable=True),
    sa.Column('updation_date', sa.DateTime(), nullable=True),
    sa.Column('dateofbirth', sa.Date(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('profile_id')
    )
    op.create_table('userrolemapping',
    sa.Column('mapping_id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('role_id', sa.Integer(), nullable=False),
    sa.ForeignKeyConstraint(['role_id'], ['userroles.role_id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
    sa.PrimaryKeyConstraint('mapping_id')
    )
Exemple #15
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tags', sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('tagname', sa.String(length=100), nullable=True),
                    sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'users', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('username', sa.String(length=80), nullable=False),
        sa.Column('email', sa.String(length=100), nullable=False),
        sa.Column('password', sa.Binary(), nullable=True),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=False),
        sa.Column('bio', sa.String(length=300), nullable=True),
        sa.Column('image', sa.String(length=120), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'),
        sa.UniqueConstraint('username'))
    op.create_table('userprofile', sa.Column('id',
                                             sa.Integer(),
                                             nullable=False),
                    sa.Column('user_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(
                        ['user_id'],
                        ['users.id'],
                    ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'article', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('slug', sa.Text(), nullable=True),
        sa.Column('title', sa.String(length=100), nullable=False),
        sa.Column('description', sa.Text(), nullable=False),
        sa.Column('body', sa.Text(), nullable=True),
        sa.Column('createdAt', sa.DateTime(), nullable=False),
        sa.Column('updatedAt', sa.DateTime(), nullable=False),
        sa.Column('author_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['author_id'],
            ['userprofile.id'],
        ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('slug'))
    op.create_table(
        'followers_assoc', sa.Column('follower', sa.Integer(), nullable=True),
        sa.Column('followed_by', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['followed_by'],
            ['userprofile.user_id'],
        ), sa.ForeignKeyConstraint(
            ['follower'],
            ['userprofile.user_id'],
        ))
    op.create_table(
        'comment', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('body', sa.Text(), nullable=True),
        sa.Column('createdAt', sa.DateTime(), nullable=False),
        sa.Column('updatedAt', sa.DateTime(), nullable=False),
        sa.Column('author_id', sa.Integer(), nullable=False),
        sa.Column('article_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['article_id'],
            ['article.id'],
        ), sa.ForeignKeyConstraint(
            ['author_id'],
            ['userprofile.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'favoritor_assoc', sa.Column('favoriter', sa.Integer(), nullable=True),
        sa.Column('favorited_article', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['favorited_article'],
            ['article.id'],
        ), sa.ForeignKeyConstraint(
            ['favoriter'],
            ['userprofile.id'],
        ))
    op.create_table('tag_assoc', sa.Column('tag', sa.Integer(), nullable=True),
                    sa.Column('article', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['article'],
                        ['article.id'],
                    ), sa.ForeignKeyConstraint(
                        ['tag'],
                        ['tags.id'],
                    ))
Exemple #16
0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('actiontypes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('sampletypes',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('smbresources',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('servername', sa.String(length=64), nullable=True),
    sa.Column('serveraddr', sa.String(length=64), nullable=True),
    sa.Column('sharename', sa.String(length=64), nullable=True),
    sa.Column('userid', sa.String(length=64), nullable=True),
    sa.Column('password', sa.String(length=64), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=64), nullable=True),
    sa.Column('username', sa.String(length=64), nullable=True),
    sa.Column('password_hash', sa.String(length=128), nullable=True),
    sa.Column('is_admin', sa.Boolean(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    op.create_table('samples',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('owner_id', sa.Integer(), nullable=True),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('parent_id', sa.Integer(), nullable=True),
    sa.Column('sampletype_id', sa.Integer(), nullable=True),
    sa.Column('image', sa.String(length=300), nullable=True),
    sa.Column('mwidth', sa.Integer(), nullable=True),
    sa.Column('mheight', sa.Integer(), nullable=True),
    sa.Column('mx', sa.Integer(), nullable=True),
    sa.Column('my', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['parent_id'], ['samples.id'], ),
    sa.ForeignKeyConstraint(['sampletype_id'], ['sampletypes.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_samples_name'), 'samples', ['name'], unique=True)
    op.create_table('actions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.Date(), nullable=True),
    sa.Column('sample_id', sa.Integer(), nullable=True),
    sa.Column('actiontype_id', sa.Integer(), nullable=True),
    sa.Column('description', sa.UnicodeText(), nullable=True),
    sa.ForeignKeyConstraint(['actiontype_id'], ['actiontypes.id'], ),
    sa.ForeignKeyConstraint(['sample_id'], ['samples.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('shares',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('sample_id', sa.Integer(), nullable=True),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['sample_id'], ['samples.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ###
    op.execute(
        'INSERT INTO "users"(email, username, password_hash, is_admin) VALUES ("*****@*****.**", "admin", "'+generate_password_hash('admin')+'", 1);'
    )
def upgrade():
    op.create_table('config',
                    sa.Column('username', sa.String(), nullable=False),
                    sa.Column('sell_price_msat', sa.Integer(), nullable=True),
                    sa.PrimaryKeyConstraint('username', name=op.f('pk_config'))
                    )
    op.create_table('peer',
                    sa.Column('peer_id', sa.Integer(), nullable=False),
                    sa.Column(
                        'created_time_ms', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column('peer_name', sa.String(), nullable=False),
                    sa.Column('network', sa.String(length=10), nullable=False),
                    sa.Column('host', sa.String(), nullable=False),
                    sa.Column('port', sa.Integer(), nullable=False),
                    sa.Column('autoconnect', sa.Boolean(), nullable=False),
                    sa.Column('share_for_free', sa.Boolean(), nullable=False),
                    sa.PrimaryKeyConstraint('peer_id', name=op.f('pk_peer')),
                    sa.UniqueConstraint(
                        'host', 'port', name='uq_peer_host_port'),
                    sqlite_autoincrement=True
                    )
    op.create_table('profile',
                    sa.Column('profile_id', sa.Integer(), nullable=False),
                    sa.Column(
                        'created_time_ms', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column('profile_name', sa.String(), nullable=False),
                    sa.Column('private_key', sa.LargeBinary(), nullable=True),
                    sa.Column('public_key', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('following', sa.Boolean(), nullable=False),
                    sa.Column('profile_image',
                              sa.LargeBinary(), nullable=True),
                    sa.PrimaryKeyConstraint(
                        'profile_id', name=op.f('pk_profile')),
                    sa.UniqueConstraint('profile_name', name=op.f(
                        'uq_profile_profile_name')),
                    sa.UniqueConstraint(
                        'public_key', name=op.f('uq_profile_public_key')),
                    sqlite_autoincrement=True
                    )
    op.create_table('received_offer',
                    sa.Column(
                        'received_offer_id', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column(
                        'created_time_ms', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column('squeak_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('payment_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('nonce', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('payment_point', sa.LargeBinary(
                        length=33), nullable=False),
                    sa.Column('invoice_timestamp',
                              sa.Integer(), nullable=False),
                    sa.Column('invoice_expiry', sa.Integer(), nullable=False),
                    sa.Column('price_msat', sa.Integer(), nullable=False),
                    sa.Column('payment_request', sa.String(), nullable=False),
                    sa.Column('destination', sa.String(
                        length=66), nullable=False),
                    sa.Column('lightning_host', sa.String(), nullable=False),
                    sa.Column('lightning_port', sa.Integer(), nullable=False),
                    sa.Column('peer_network', sa.String(
                        length=10), nullable=False),
                    sa.Column('peer_host', sa.String(), nullable=False),
                    sa.Column('peer_port', sa.Integer(), nullable=False),
                    sa.Column('paid', sa.Boolean(), nullable=False),
                    sa.PrimaryKeyConstraint('received_offer_id',
                                            name=op.f('pk_received_offer')),
                    sa.UniqueConstraint('payment_hash', name=op.f(
                        'uq_received_offer_payment_hash')),
                    sqlite_autoincrement=True
                    )
    op.create_table('received_payment',
                    sa.Column('received_payment_id',
                              squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column(
                        'created_time_ms', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column('squeak_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('payment_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('price_msat', sa.Integer(), nullable=False),
                    sa.Column('settle_index',
                              squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column('peer_network', sa.String(
                        length=10), nullable=False),
                    sa.Column('peer_host', sa.String(), nullable=False),
                    sa.Column('peer_port', sa.Integer(), nullable=False),
                    sa.PrimaryKeyConstraint('received_payment_id',
                                            name=op.f('pk_received_payment')),
                    sa.UniqueConstraint('payment_hash', name=op.f(
                        'uq_received_payment_payment_hash')),
                    sqlite_autoincrement=True
                    )
    op.create_table('sent_offer',
                    sa.Column(
                        'sent_offer_id', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column(
                        'created_time_ms', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column('squeak_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('payment_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('nonce', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('price_msat', sa.Integer(), nullable=False),
                    sa.Column('payment_request', sa.String(), nullable=False),
                    sa.Column('invoice_timestamp',
                              sa.Integer(), nullable=False),
                    sa.Column('invoice_expiry', sa.Integer(), nullable=False),
                    sa.Column('peer_network', sa.String(
                        length=10), nullable=False),
                    sa.Column('peer_host', sa.String(), nullable=False),
                    sa.Column('peer_port', sa.Integer(), nullable=False),
                    sa.Column('paid', sa.Boolean(), nullable=False),
                    sa.PrimaryKeyConstraint(
                        'sent_offer_id', name=op.f('pk_sent_offer')),
                    sa.UniqueConstraint('payment_hash', name=op.f(
                        'uq_sent_offer_payment_hash')),
                    sqlite_autoincrement=True
                    )
    op.create_table('sent_payment',
                    sa.Column(
                        'sent_payment_id', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column(
                        'created_time_ms', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column('peer_network', sa.String(
                        length=10), nullable=False),
                    sa.Column('peer_host', sa.String(), nullable=False),
                    sa.Column('peer_port', sa.Integer(), nullable=False),
                    sa.Column('squeak_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('payment_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('secret_key', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('price_msat', sa.Integer(), nullable=False),
                    sa.Column('node_pubkey', sa.String(
                        length=66), nullable=False),
                    sa.Column('valid', sa.Boolean(), nullable=False),
                    sa.PrimaryKeyConstraint(
                        'sent_payment_id', name=op.f('pk_sent_payment')),
                    sa.UniqueConstraint('payment_hash', name=op.f(
                        'uq_sent_payment_payment_hash')),
                    sqlite_autoincrement=True
                    )
    op.create_table('squeak',
                    sa.Column('hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column(
                        'created_time_ms', squeaknode.db.models.SLBigInteger(), nullable=False),
                    sa.Column('squeak', sa.LargeBinary(), nullable=False),
                    sa.Column('reply_hash', sa.LargeBinary(
                        length=32), nullable=True),
                    sa.Column('block_hash', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('block_height', sa.Integer(), nullable=False),
                    sa.Column('time_s', sa.Integer(), nullable=False),
                    sa.Column('author_public_key', sa.LargeBinary(
                        length=32), nullable=False),
                    sa.Column('recipient_public_key', sa.LargeBinary(
                        length=32), nullable=True),
                    sa.Column('secret_key', sa.LargeBinary(
                        length=32), nullable=True),
                    sa.Column('block_time_s', sa.Integer(), nullable=False),
                    sa.Column('liked_time_ms',
                              squeaknode.db.models.SLBigInteger(), nullable=True),
                    sa.Column('content', sa.String(length=280), nullable=True),
                    sa.PrimaryKeyConstraint('hash', name=op.f('pk_squeak'))
                    )
    with op.batch_alter_table('squeak', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_squeak_author_public_key'), [
                              'author_public_key'], unique=False)
        batch_op.create_index(batch_op.f('ix_squeak_recipient_public_key'), [
                              'recipient_public_key'], unique=False)

    op.create_table('twitter_account',
                    sa.Column('twitter_account_id',
                              sa.Integer(), nullable=False),
                    sa.Column('handle', sa.String(), nullable=False),
                    sa.Column('profile_id', sa.Integer(), nullable=False),
                    sa.Column('bearer_token', sa.String(), nullable=False),
                    sa.PrimaryKeyConstraint('twitter_account_id',
                                            name=op.f('pk_twitter_account')),
                    sa.UniqueConstraint('handle', name=op.f(
                        'uq_twitter_account_handle'))
                    )
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'user',
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('created_at_ip', sa.String(), nullable=False),
        sa.Column('id', sa.BigInteger(), nullable=False),
        # change id field to BigInt for psql on heroku
        # psql doesn't suppoer unsigned
        sa.Column('handle', sa.String(length=20), nullable=False),
        sa.Column('name', sa.String(length=50), nullable=False),
        sa.Column('email', sa.String(length=120), nullable=False),
        sa.Column('phone', sa.String(length=20), nullable=True),
        sa.Column('birthdate', sa.Date(), nullable=False),
        sa.Column('password', sa.String(length=60), nullable=False),
        sa.Column('profile_image', sa.String(length=20), nullable=False),
        sa.Column('background_image', sa.String(length=20), nullable=False),
        sa.Column('bio', sa.String(length=160), nullable=False),
        sa.Column('location', sa.String(length=30), nullable=False),
        sa.Column('website', sa.String(length=100), nullable=False),
        sa.Column('last_read_message_at', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('email'),
        sa.UniqueConstraint('handle'),
        sa.UniqueConstraint('phone'))
    op.create_table('follower',
                    sa.Column('follower_id', sa.BigInteger(), nullable=True),
                    sa.Column('following_id', sa.BigInteger(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['follower_id'],
                        ['user.id'],
                    ), sa.ForeignKeyConstraint(
                        ['following_id'],
                        ['user.id'],
                    ))
    op.create_table('message',
                    sa.Column('created_at', sa.DateTime(), nullable=False),
                    sa.Column('id', sa.BigInteger(), nullable=False),
                    sa.Column('sender_id', sa.BigInteger(), nullable=False),
                    sa.Column('recipient_id', sa.BigInteger(), nullable=False),
                    sa.Column('body', sa.String(length=500), nullable=False),
                    sa.Column('read_at', sa.DateTime(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['recipient_id'],
                        ['user.id'],
                    ), sa.ForeignKeyConstraint(
                        ['sender_id'],
                        ['user.id'],
                    ), sa.PrimaryKeyConstraint('id'))
    op.create_table('post',
                    sa.Column('created_at', sa.DateTime(), nullable=False),
                    sa.Column('id', sa.BigInteger(), nullable=False),
                    sa.Column('content', sa.Text(), nullable=False),
                    sa.Column('user_id', sa.BigInteger(), nullable=False),
                    sa.Column('op_id', sa.BigInteger(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['op_id'],
                        ['post.id'],
                    ), sa.ForeignKeyConstraint(
                        ['user_id'],
                        ['user.id'],
                    ), sa.PrimaryKeyConstraint('id'))
    op.create_table('liker',
                    sa.Column('user_id', sa.BigInteger(), nullable=True),
                    sa.Column('post_id', sa.BigInteger(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['post_id'],
                        ['post.id'],
                    ), sa.ForeignKeyConstraint(
                        ['user_id'],
                        ['user.id'],
                    ))
Exemple #19
0
    def _schema_creation(self):
        """Create the schemas of the different tables in the database."""
        metadata = sqlalchemy.MetaData()

        self.articles_table = sqlalchemy.Table(
            "articles",
            metadata,
            sqlalchemy.Column(
                "article_id", sqlalchemy.Integer(), primary_key=True, autoincrement=True
            ),
            sqlalchemy.Column("cord_uid", sqlalchemy.String(8), nullable=False),
            sqlalchemy.Column("sha", sqlalchemy.Text()),
            sqlalchemy.Column("source_x", sqlalchemy.Text()),
            sqlalchemy.Column("title", sqlalchemy.Text()),
            sqlalchemy.Column("doi", sqlalchemy.Text()),
            sqlalchemy.Column("pmcid", sqlalchemy.Text()),
            sqlalchemy.Column("pubmed_id", sqlalchemy.Text()),
            sqlalchemy.Column("license", sqlalchemy.Text()),
            sqlalchemy.Column("abstract", sqlalchemy.Text()),
            sqlalchemy.Column("publish_time", sqlalchemy.Date()),
            sqlalchemy.Column("authors", sqlalchemy.Text()),
            sqlalchemy.Column("journal", sqlalchemy.Text()),
            sqlalchemy.Column("mag_id", sqlalchemy.Text()),
            sqlalchemy.Column("who_covidence_id", sqlalchemy.Text()),
            sqlalchemy.Column("arxiv_id", sqlalchemy.Text()),
            sqlalchemy.Column("pdf_json_files", sqlalchemy.Text()),
            sqlalchemy.Column("pmc_json_files", sqlalchemy.Text()),
            sqlalchemy.Column("url", sqlalchemy.Text()),
            sqlalchemy.Column("s2_id", sqlalchemy.Text()),
            sqlalchemy.Column("is_english", sqlalchemy.Boolean()),
        )

        self.sentences_table = sqlalchemy.Table(
            "sentences",
            metadata,
            sqlalchemy.Column(
                "sentence_id",
                sqlalchemy.Integer(),
                primary_key=True,
                autoincrement=True,
            ),
            sqlalchemy.Column("section_name", sqlalchemy.Text()),
            sqlalchemy.Column(
                "article_id",
                sqlalchemy.Integer(),
                sqlalchemy.ForeignKey("articles.article_id"),
                nullable=False,
            ),
            sqlalchemy.Column("text", sqlalchemy.Text()),
            sqlalchemy.Column(
                "paragraph_pos_in_article", sqlalchemy.Integer(), nullable=False
            ),
            sqlalchemy.Column(
                "sentence_pos_in_paragraph", sqlalchemy.Integer(), nullable=False
            ),
            sqlalchemy.UniqueConstraint(
                "article_id",
                "paragraph_pos_in_article",
                "sentence_pos_in_paragraph",
                name="sentence_unique_identifier",
            ),
            sqlalchemy.Column("is_bad", sqlalchemy.Boolean(), server_default="0"),
        )

        with self.engine.begin() as connection:
            metadata.create_all(connection)
Exemple #20
0
Fichier : group.py Projet : y3g0r/h
    }.get(group.writeable_by)


TypeFlags = namedtuple("TypeFlags", "joinable_by readable_by writeable_by")

OPEN_GROUP_TYPE_FLAGS = TypeFlags(joinable_by=None,
                                  readable_by=ReadableBy.world,
                                  writeable_by=WriteableBy.authority)

PRIVATE_GROUP_TYPE_FLAGS = TypeFlags(
    joinable_by=JoinableBy.authority,
    readable_by=ReadableBy.members,
    writeable_by=WriteableBy.members,
)

RESTRICTED_GROUP_TYPE_FLAGS = TypeFlags(joinable_by=None,
                                        readable_by=ReadableBy.world,
                                        writeable_by=WriteableBy.members)

USER_GROUP_TABLE = sa.Table(
    "user_group",
    Base.metadata,
    sa.Column("id", sa.Integer, autoincrement=True, primary_key=True),
    sa.Column("user_id", sa.Integer, sa.ForeignKey("user.id"), nullable=False),
    sa.Column("group_id",
              sa.Integer,
              sa.ForeignKey("group.id"),
              nullable=False),
    sa.UniqueConstraint("user_id", "group_id"),
)
Exemple #21
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'protocoltypes', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=128), nullable=True),
        sa.Column('short_name', sa.String(length=128), nullable=True),
        sa.Column('organization', sa.Text(), nullable=True),
        sa.Column('usual_time', sa.Time(), nullable=True),
        sa.Column('is_public', sa.Boolean(), nullable=True),
        sa.Column('modify_group', sa.Text(), nullable=True),
        sa.Column('private_group', sa.Text(), nullable=True),
        sa.Column('public_group', sa.Text(), nullable=True),
        sa.Column('publish_group', sa.Text(), nullable=True),
        sa.Column('private_mail', sa.Text(), nullable=True),
        sa.Column('public_mail', sa.Text(), nullable=True),
        sa.Column('non_reproducible_pad_links', sa.Boolean(), nullable=True),
        sa.Column('use_wiki', sa.Boolean(), nullable=True),
        sa.Column('wiki_category', sa.Text(), nullable=True),
        sa.Column('wiki_only_public', sa.Boolean(), nullable=True),
        sa.Column('printer', sa.Text(), nullable=True),
        sa.Column('calendar', sa.Text(), nullable=True),
        sa.Column('restrict_networks', sa.Boolean(), nullable=True),
        sa.Column('allowed_networks', sa.Text(), nullable=True),
        sa.Column('latex_template', sa.Text(), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'),
        sa.UniqueConstraint('short_name'))
    op.create_table('todomails', sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=128), nullable=True),
                    sa.Column('mail', sa.Text(), nullable=True),
                    sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'))
    op.create_table(
        'decisioncategories', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocoltype_id', sa.Integer(), nullable=True),
        sa.Column('name', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocoltype_id'],
            ['protocoltypes.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'defaultmetas', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocoltype_id', sa.Integer(), nullable=True),
        sa.Column('key', sa.Text(), nullable=True),
        sa.Column('name', sa.Text(), nullable=True),
        sa.Column('value', sa.Text(), nullable=True),
        sa.Column('internal', sa.Boolean(), nullable=True),
        sa.Column('prior', sa.Boolean(), nullable=False),
        sa.ForeignKeyConstraint(
            ['protocoltype_id'],
            ['protocoltypes.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'defaulttops', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocoltype_id', sa.Integer(), nullable=True),
        sa.Column('name', sa.Text(), nullable=True),
        sa.Column('number', sa.Integer(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocoltype_id'],
            ['protocoltypes.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'meetingreminders', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocoltype_id', sa.Integer(), nullable=True),
        sa.Column('days_before', sa.Integer(), nullable=True),
        sa.Column('send_public', sa.Boolean(), nullable=True),
        sa.Column('send_private', sa.Boolean(), nullable=True),
        sa.Column('additional_text', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocoltype_id'],
            ['protocoltypes.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'protocols', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocoltype_id', sa.Integer(), nullable=True),
        sa.Column('source', sa.Text(), nullable=True),
        sa.Column('content_public', sa.Text(), nullable=True),
        sa.Column('content_private', sa.Text(), nullable=True),
        sa.Column('content_html_public', sa.Text(), nullable=True),
        sa.Column('content_html_private', sa.Text(), nullable=True),
        sa.Column('date', sa.Date(), nullable=True),
        sa.Column('start_time', sa.Time(), nullable=True),
        sa.Column('end_time', sa.Time(), nullable=True),
        sa.Column('done', sa.Boolean(), nullable=False),
        sa.Column('public', sa.Boolean(), nullable=True),
        sa.Column('pad_identifier', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocoltype_id'],
            ['protocoltypes.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'todos', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocoltype_id', sa.Integer(), nullable=True),
        sa.Column('number', sa.Integer(), nullable=True),
        sa.Column('who', sa.Text(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('state',
                  sa.Enum('open',
                          'waiting',
                          'in_progress',
                          'after',
                          'before',
                          'orphan',
                          'done',
                          'rejected',
                          'obsolete',
                          name='todostate'),
                  nullable=False), sa.Column('date', sa.Date(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocoltype_id'],
            ['protocoltypes.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'decisions', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocol_id', sa.Integer(), nullable=True),
        sa.Column('content', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocol_id'],
            ['protocols.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'documents', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocol_id', sa.Integer(), nullable=True),
        sa.Column('name', sa.Text(), nullable=True),
        sa.Column('filename', sa.Text(), nullable=True),
        sa.Column('is_compiled', sa.Boolean(), nullable=True),
        sa.Column('is_private', sa.Boolean(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocol_id'],
            ['protocols.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'errors', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocol_id', sa.Integer(), nullable=True),
        sa.Column('action', sa.Text(), nullable=True),
        sa.Column('name', sa.Text(), nullable=True),
        sa.Column('datetime', sa.DateTime(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocol_id'],
            ['protocols.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'likeprotocolassociations',
        sa.Column('like_id', sa.Integer(), nullable=False),
        sa.Column('protocol_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['like_id'],
            ['likes.id'],
        ), sa.ForeignKeyConstraint(
            ['protocol_id'],
            ['protocols.id'],
        ), sa.PrimaryKeyConstraint('like_id', 'protocol_id'))
    op.create_table('liketodoassociations',
                    sa.Column('like_id', sa.Integer(), nullable=False),
                    sa.Column('todo_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(
                        ['like_id'],
                        ['likes.id'],
                    ), sa.ForeignKeyConstraint(
                        ['todo_id'],
                        ['todos.id'],
                    ), sa.PrimaryKeyConstraint('like_id', 'todo_id'))
    op.create_table(
        'localtops', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocol_id', sa.Integer(), nullable=True),
        sa.Column('defaulttop_id', sa.Integer(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['defaulttop_id'],
            ['defaulttops.id'],
        ), sa.ForeignKeyConstraint(
            ['protocol_id'],
            ['protocols.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'metas', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocol_id', sa.Integer(), nullable=True),
        sa.Column('name', sa.Text(), nullable=True),
        sa.Column('value', sa.Text(), nullable=True),
        sa.Column('internal', sa.Boolean(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocol_id'],
            ['protocols.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'todoprotocolassociations',
        sa.Column('todo_id', sa.Integer(), nullable=False),
        sa.Column('protocol_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['protocol_id'],
            ['protocols.id'],
        ), sa.ForeignKeyConstraint(
            ['todo_id'],
            ['todos.id'],
        ), sa.PrimaryKeyConstraint('todo_id', 'protocol_id'))
    op.create_table(
        'tops', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('protocol_id', sa.Integer(), nullable=True),
        sa.Column('name', sa.Text(), nullable=True),
        sa.Column('number', sa.Integer(), nullable=True),
        sa.Column('planned', sa.Boolean(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['protocol_id'],
            ['protocols.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'decisioncategoryassociations',
        sa.Column('decision_id', sa.Integer(), nullable=False),
        sa.Column('decisioncategory_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['decision_id'],
            ['decisions.id'],
        ),
        sa.ForeignKeyConstraint(
            ['decisioncategory_id'],
            ['decisioncategories.id'],
        ), sa.PrimaryKeyConstraint('decision_id', 'decisioncategory_id'))
    op.create_table(
        'decisiondocuments', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('decision_id', sa.Integer(), nullable=True),
        sa.Column('name', sa.Text(), nullable=True),
        sa.Column('filename', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['decision_id'],
            ['decisions.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'likedecisionassociations',
        sa.Column('like_id', sa.Integer(), nullable=False),
        sa.Column('decision_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['decision_id'],
            ['decisions.id'],
        ), sa.ForeignKeyConstraint(
            ['like_id'],
            ['likes.id'],
        ), sa.PrimaryKeyConstraint('like_id', 'decision_id'))
    op.create_table('liketopassociations',
                    sa.Column('like_id', sa.Integer(), nullable=False),
                    sa.Column('top_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(
                        ['like_id'],
                        ['likes.id'],
                    ), sa.ForeignKeyConstraint(
                        ['top_id'],
                        ['tops.id'],
                    ), sa.PrimaryKeyConstraint('like_id', 'top_id'))
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('company',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(), nullable=True),
    sa.Column('isin', sa.String(), nullable=True),
    sa.Column('number_of_shares', sa.BigInteger(), nullable=True),
    sa.Column('url', sa.String(), nullable=True),
    sa.Column('ticker', sa.String(), nullable=True),
    sa.Column('ipo_date', sa.DateTime(), nullable=True),
    sa.Column('stock_exchange', sa.String(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('isin'),
    sa.UniqueConstraint('name'),
    sa.UniqueConstraint('url')
    )
    op.create_index(op.f('ix_company_id'), 'company', ['id'], unique=False)
    op.create_table('daily_ratio',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('period', sa.String(), nullable=True),
    sa.Column('end_date', sa.DateTime(), nullable=True),
    sa.Column('currency', sa.String(), nullable=True),
    sa.Column('market_cap', sa.BigInteger(), nullable=True),
    sa.Column('price_to_earnings_ratio_ttm', sa.Float(), nullable=True),
    sa.Column('price_to_book_ratio', sa.Float(), nullable=True),
    sa.Column('market_to_book_ratio', sa.Float(), nullable=True),
    sa.Column('price_to_tangible_book_value', sa.Float(), nullable=True),
    sa.Column('enterprise_value', sa.BigInteger(), nullable=True),
    sa.Column('ev_to_revenue', sa.Float(), nullable=True),
    sa.Column('ev_to_net_income', sa.Float(), nullable=True),
    sa.Column('ev_to_ebit', sa.Float(), nullable=True),
    sa.Column('ev_to_ebitda', sa.Float(), nullable=True),
    sa.Column('ev_to_assets', sa.Float(), nullable=True),
    sa.Column('company_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['company.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_daily_ratio_id'), 'daily_ratio', ['id'], unique=False)
    op.create_table('dividend',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('currency', sa.String(), nullable=True),
    sa.Column('ex_dividend_date', sa.DateTime(), nullable=True),
    sa.Column('pay_date', sa.DateTime(), nullable=True),
    sa.Column('dividend_payout', sa.Float(), nullable=True),
    sa.Column('company_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['company.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_dividend_id'), 'dividend', ['id'], unique=False)
    op.create_table('financial_statement',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('period', sa.String(), nullable=True),
    sa.Column('end_date', sa.DateTime(), nullable=True),
    sa.Column('publish_date', sa.DateTime(), nullable=True),
    sa.Column('url', sa.String(), nullable=True),
    sa.Column('audited', sa.Boolean(), nullable=True),
    sa.Column('currency', sa.String(), nullable=True),
    sa.Column('non_current_assets', sa.BigInteger(), nullable=True),
    sa.Column('cash_and_equivalents', sa.BigInteger(), nullable=True),
    sa.Column('current_assets', sa.BigInteger(), nullable=True),
    sa.Column('total_assets', sa.BigInteger(), nullable=True),
    sa.Column('short_term_debt', sa.BigInteger(), nullable=True),
    sa.Column('current_liabilities', sa.BigInteger(), nullable=True),
    sa.Column('long_term_debt', sa.BigInteger(), nullable=True),
    sa.Column('long_term_liabilities', sa.BigInteger(), nullable=True),
    sa.Column('total_debt', sa.BigInteger(), nullable=True),
    sa.Column('total_liabilities', sa.BigInteger(), nullable=True),
    sa.Column('total_equity', sa.BigInteger(), nullable=True),
    sa.Column('total_equities_and_liabilities', sa.BigInteger(), nullable=True),
    sa.Column('total_revenues', sa.BigInteger(), nullable=True),
    sa.Column('cost_of_revenue', sa.BigInteger(), nullable=True),
    sa.Column('costs_of_goods_sold', sa.BigInteger(), nullable=True),
    sa.Column('gross_profit', sa.BigInteger(), nullable=True),
    sa.Column('ebitda', sa.BigInteger(), nullable=True),
    sa.Column('ebit', sa.BigInteger(), nullable=True),
    sa.Column('operating_income', sa.BigInteger(), nullable=True),
    sa.Column('interest_expense', sa.BigInteger(), nullable=True),
    sa.Column('profit_before_tax', sa.BigInteger(), nullable=True),
    sa.Column('tax_expense', sa.BigInteger(), nullable=True),
    sa.Column('depreciation', sa.BigInteger(), nullable=True),
    sa.Column('amortization', sa.BigInteger(), nullable=True),
    sa.Column('net_income', sa.BigInteger(), nullable=True),
    sa.Column('earnings_per_share', sa.Float(), nullable=True),
    sa.Column('company_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['company.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('url')
    )
    op.create_index(op.f('ix_financial_statement_id'), 'financial_statement', ['id'], unique=False)
    op.create_table('value_metrics',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('period', sa.String(), nullable=True),
    sa.Column('end_date', sa.DateTime(), nullable=True),
    sa.Column('currency', sa.String(), nullable=True),
    sa.Column('book_value', sa.BigInteger(), nullable=True),
    sa.Column('tangible_book_value', sa.BigInteger(), nullable=True),
    sa.Column('tangible_book_value_per_share', sa.Float(), nullable=True),
    sa.Column('debt_to_equity', sa.Float(), nullable=True),
    sa.Column('equity_ratio', sa.Float(), nullable=True),
    sa.Column('debt_ratio', sa.Float(), nullable=True),
    sa.Column('cash_ratio', sa.Float(), nullable=True),
    sa.Column('gross_profit_margin', sa.Float(), nullable=True),
    sa.Column('net_profit_margin', sa.Float(), nullable=True),
    sa.Column('ebit_margin', sa.Float(), nullable=True),
    sa.Column('operating_margin', sa.Float(), nullable=True),
    sa.Column('ebitda_margin', sa.Float(), nullable=True),
    sa.Column('cash_return_on_capital_invested', sa.Float(), nullable=True),
    sa.Column('debt_to_ebitda', sa.Float(), nullable=True),
    sa.Column('return_on_equity', sa.Float(), nullable=True),
    sa.Column('return_on_assets', sa.Float(), nullable=True),
    sa.Column('current_ratio', sa.Float(), nullable=True),
    sa.Column('working_capital', sa.BigInteger(), nullable=True),
    sa.Column('company_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['company_id'], ['company.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_value_metrics_id'), 'value_metrics', ['id'], unique=False)
    op.drop_index('ix_item_description', table_name='item')
    op.drop_index('ix_item_id', table_name='item')
    op.drop_index('ix_item_title', table_name='item')
    op.drop_table('item')
    op.alter_column('user', 'email',
               existing_type=sa.VARCHAR(),
               nullable=False)
    op.alter_column('user', 'hashed_password',
               existing_type=sa.VARCHAR(),
               nullable=False)
Exemple #23
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('info_category',
                    sa.Column('create_time', sa.DateTime(), nullable=True),
                    sa.Column('update_time', sa.DateTime(), nullable=True),
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=64), nullable=False),
                    sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'info_user', sa.Column('create_time', sa.DateTime(), nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('nick_name', sa.String(length=32), nullable=False),
        sa.Column('password_hash', sa.String(length=128), nullable=False),
        sa.Column('mobile', sa.String(length=11), nullable=False),
        sa.Column('avatar_url', sa.String(length=256), nullable=True),
        sa.Column('last_login', sa.DateTime(), nullable=True),
        sa.Column('is_admin', sa.Boolean(), nullable=True),
        sa.Column('signature', sa.String(length=512), nullable=True),
        sa.Column('gender', sa.Enum('MAN', 'WOMAN'), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('mobile'),
        sa.UniqueConstraint('nick_name'))
    op.create_table(
        'info_news', sa.Column('create_time', sa.DateTime(), nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('title', sa.String(length=256), nullable=False),
        sa.Column('source', sa.String(length=64), nullable=False),
        sa.Column('digest', sa.String(length=512), nullable=False),
        sa.Column('content', sa.Text(), nullable=False),
        sa.Column('clicks', sa.Integer(), nullable=True),
        sa.Column('index_image_url', sa.String(length=256), nullable=True),
        sa.Column('category_id', sa.Integer(), nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('status', sa.Integer(), nullable=True),
        sa.Column('reason', sa.String(length=256), nullable=True),
        sa.ForeignKeyConstraint(
            ['category_id'],
            ['info_category.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['info_user.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'info_user_fans', sa.Column('follower_id',
                                    sa.Integer(),
                                    nullable=False),
        sa.Column('followed_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['followed_id'],
            ['info_user.id'],
        ), sa.ForeignKeyConstraint(
            ['follower_id'],
            ['info_user.id'],
        ), sa.PrimaryKeyConstraint('follower_id', 'followed_id'))
    op.create_table(
        'info_comment', sa.Column('create_time', sa.DateTime(), nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('news_id', sa.Integer(), nullable=False),
        sa.Column('content', sa.Text(), nullable=False),
        sa.Column('parent_id', sa.Integer(), nullable=True),
        sa.Column('like_count', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['news_id'],
            ['info_news.id'],
        ), sa.ForeignKeyConstraint(
            ['parent_id'],
            ['info_comment.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['info_user.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table('info_user_collection',
                    sa.Column('user_id', sa.Integer(), nullable=False),
                    sa.Column('news_id', sa.Integer(), nullable=False),
                    sa.Column('create_time', sa.DateTime(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['news_id'],
                        ['info_news.id'],
                    ), sa.ForeignKeyConstraint(
                        ['user_id'],
                        ['info_user.id'],
                    ), sa.PrimaryKeyConstraint('user_id', 'news_id'))
    op.create_table(
        'info_comment_like',
        sa.Column('create_time', sa.DateTime(), nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('comment_id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['comment_id'],
            ['info_comment.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['info_user.id'],
        ), sa.PrimaryKeyConstraint('comment_id', 'user_id'))
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('backup_config',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('keep_hourly', sa.Integer(), nullable=True),
                    sa.Column('keep_daily', sa.Integer(), nullable=True),
                    sa.Column('limit', sa.Integer(), nullable=True),
                    sa.Column('units', sa.Integer(), nullable=False),
                    sa.Column('last_changed', sa.DateTime(), nullable=True),
                    sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'celery_crontabs', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('minute', sa.String(length=64), nullable=True),
        sa.Column('hour', sa.String(length=64), nullable=True),
        sa.Column('day_of_week', sa.String(length=64), nullable=True),
        sa.Column('day_of_month', sa.String(length=64), nullable=True),
        sa.Column('month_of_year', sa.String(length=64), nullable=True),
        sa.PrimaryKeyConstraint('id'))
    op.create_table('celery_intervals',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('every', sa.Integer(), nullable=False),
                    sa.Column('period', sa.String(length=24), nullable=True),
                    sa.PrimaryKeyConstraint('id'))
    op.create_table('main_config',
                    sa.Column('year', sa.Integer(), nullable=False),
                    sa.PrimaryKeyConstraint('year'))
    op.create_table(
        'roles', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('description', sa.String(length=255), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'))
    op.create_table(
        'users', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('email', sa.String(length=255), nullable=True),
        sa.Column('username', sa.String(length=255), nullable=True),
        sa.Column('password', sa.String(length=255), nullable=True),
        sa.Column('first_name', sa.String(length=255), nullable=True),
        sa.Column('last_name', sa.String(length=255), nullable=True),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('confirmed_at', sa.DateTime(), nullable=True),
        sa.Column('last_login_at', sa.DateTime(), nullable=True),
        sa.Column('current_login_at', sa.DateTime(), nullable=True),
        sa.Column('last_login_ip', sa.String(length=60), nullable=True),
        sa.Column('current_login_ip', sa.String(length=60), nullable=True),
        sa.Column('login_count', sa.Integer(), nullable=True),
        sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_first_name'),
                    'users', ['first_name'],
                    unique=False)
    op.create_index(op.f('ix_users_last_name'),
                    'users', ['last_name'],
                    unique=False)
    op.create_index(op.f('ix_users_username'),
                    'users', ['username'],
                    unique=True)
    op.create_table(
        'backups', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('owner_id', sa.Integer(), nullable=True),
        sa.Column('description', sa.String(length=255), nullable=True),
        sa.Column('date', sa.DateTime(), nullable=True),
        sa.Column('type', sa.Integer(), nullable=True),
        sa.Column('filename', sa.String(length=255), nullable=True),
        sa.Column('db_size', sa.Integer(), nullable=True),
        sa.Column('archive_size', sa.Integer(), nullable=True),
        sa.Column('backup_size', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['owner_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_backups_date'), 'backups', ['date'], unique=False)
    op.create_table(
        'celery_schedules', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('task', sa.String(length=255), nullable=True),
        sa.Column('interval_id', sa.Integer(), nullable=True),
        sa.Column('crontab_id', sa.Integer(), nullable=True),
        sa.Column('arguments', sa.String(length=255), nullable=True),
        sa.Column('keyword_arguments', sa.String(length=255), nullable=True),
        sa.Column('queue', sa.String(length=255), nullable=True),
        sa.Column('exchange', sa.String(length=255), nullable=True),
        sa.Column('routing_key', sa.String(length=255), nullable=True),
        sa.Column('expires', sa.DateTime(), nullable=True),
        sa.Column('enabled', sa.Boolean(), nullable=True),
        sa.Column('last_run_at', sa.DateTime(), nullable=True),
        sa.Column('total_run_count', sa.Integer(), nullable=True),
        sa.Column('date_changed', sa.DateTime(), nullable=True),
        sa.Column('owner_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['crontab_id'],
            ['celery_crontabs.id'],
        ), sa.ForeignKeyConstraint(
            ['interval_id'],
            ['celery_intervals.id'],
        ), sa.ForeignKeyConstraint(
            ['owner_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'degree_types', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_degree_types_name'),
                    'degree_types', ['name'],
                    unique=True)
    op.create_table(
        'email_log', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('recipient', sa.String(length=255), nullable=True),
        sa.Column('send_date', sa.DateTime(), nullable=True),
        sa.Column('subject', sa.String(length=255), nullable=True),
        sa.Column('body', sa.Text(), nullable=True),
        sa.Column('html', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['user_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_email_log_send_date'),
                    'email_log', ['send_date'],
                    unique=False)
    op.create_table(
        'faculty_data', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('academic_title', sa.Integer(), nullable=True),
        sa.Column('use_academic_title', sa.Boolean(), nullable=True),
        sa.Column('sign_off_students', sa.Boolean(), nullable=True),
        sa.Column('office', sa.String(length=255), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table('messages', sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('user_id', sa.Integer(), nullable=True),
                    sa.Column('issue_date', sa.DateTime(), nullable=True),
                    sa.Column('show_students', sa.Boolean(), nullable=True),
                    sa.Column('show_faculty', sa.Boolean(), nullable=True),
                    sa.Column('show_login', sa.Boolean(), nullable=True),
                    sa.Column('dismissible', sa.Boolean(), nullable=True),
                    sa.Column('title', sa.String(length=255), nullable=True),
                    sa.Column('body', sa.Text(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['user_id'],
                        ['users.id'],
                    ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_messages_issue_date'),
                    'messages', ['issue_date'],
                    unique=False)
    op.create_table(
        'notifications', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('type', sa.Integer(), nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('uuid', sa.String(length=255), nullable=True),
        sa.Column('timestamp', sa.Integer(), nullable=True),
        sa.Column('remove_on_pageload', sa.Boolean(), nullable=True),
        sa.Column('payload_json', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['user_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_notifications_timestamp'),
                    'notifications', ['timestamp'],
                    unique=False)
    op.create_index(op.f('ix_notifications_uuid'),
                    'notifications', ['uuid'],
                    unique=False)
    op.create_table(
        'project_classes', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('abbreviation', sa.String(length=255), nullable=True),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('year', sa.Integer(), nullable=True),
        sa.Column('extent', sa.Integer(), nullable=True),
        sa.Column('require_confirm', sa.Boolean(), nullable=True),
        sa.Column('supervisor_carryover', sa.Boolean(), nullable=True),
        sa.Column('submissions', sa.Integer(), nullable=True),
        sa.Column('initial_choices', sa.Integer(), nullable=True),
        sa.Column('switch_choices', sa.Integer(), nullable=True),
        sa.Column('selection_open_to_all', sa.Boolean(), nullable=True),
        sa.Column('convenor_id', sa.Integer(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['convenor_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_project_classes_abbreviation'),
                    'project_classes', ['abbreviation'],
                    unique=True)
    op.create_index(op.f('ix_project_classes_convenor_id'),
                    'project_classes', ['convenor_id'],
                    unique=False)
    op.create_index(op.f('ix_project_classes_name'),
                    'project_classes', ['name'],
                    unique=True)
    op.create_index(op.f('ix_project_classes_year'),
                    'project_classes', ['year'],
                    unique=False)
    op.create_table(
        'research_groups', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('abbreviation', sa.String(length=255), nullable=True),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('website', sa.String(length=255), nullable=True),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_research_groups_abbreviation'),
                    'research_groups', ['abbreviation'],
                    unique=True)
    op.create_table('roles_users',
                    sa.Column('user_id', sa.Integer(), nullable=False),
                    sa.Column('role_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(
                        ['role_id'],
                        ['roles.id'],
                    ), sa.ForeignKeyConstraint(
                        ['user_id'],
                        ['users.id'],
                    ), sa.PrimaryKeyConstraint('user_id', 'role_id'))
    op.create_table(
        'supervision_team', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'))
    op.create_table(
        'tasks', sa.Column('id', sa.String(length=255), nullable=False),
        sa.Column('owner_id', sa.Integer(), nullable=True),
        sa.Column('start_date', sa.DateTime(), nullable=True),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('description', sa.String(length=255), nullable=True),
        sa.Column('status', sa.Integer(), nullable=True),
        sa.Column('progress', sa.Integer(), nullable=True),
        sa.Column('message', sa.String(length=255), nullable=True),
        sa.ForeignKeyConstraint(
            ['owner_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_tasks_name'), 'tasks', ['name'], unique=False)
    op.create_table(
        'transferable_skills', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_transferable_skills_name'),
                    'transferable_skills', ['name'],
                    unique=True)
    op.create_table(
        'degree_programmes', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('type_id', sa.Integer(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['type_id'],
            ['degree_types.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_degree_programmes_name'),
                    'degree_programmes', ['name'],
                    unique=False)
    op.create_index(op.f('ix_degree_programmes_type_id'),
                    'degree_programmes', ['type_id'],
                    unique=False)
    op.create_table(
        'faculty_affiliations',
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('group_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['group_id'],
            ['research_groups.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['faculty_data.id'],
        ), sa.PrimaryKeyConstraint('user_id', 'group_id'))
    op.create_table(
        'faculty_enrollments',
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('project_class_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_class_id'],
            ['project_classes.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['faculty_data.id'],
        ), sa.PrimaryKeyConstraint('user_id', 'project_class_id'))
    op.create_table('message_dismissals',
                    sa.Column('message_id', sa.Integer(), nullable=False),
                    sa.Column('user_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(
                        ['message_id'],
                        ['messages.id'],
                    ), sa.ForeignKeyConstraint(
                        ['user_id'],
                        ['users.id'],
                    ), sa.PrimaryKeyConstraint('message_id', 'user_id'))
    op.create_table(
        'project_class_config', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('year', sa.Integer(), nullable=True),
        sa.Column('pclass_id', sa.Integer(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('requests_issued', sa.Boolean(), nullable=True),
        sa.Column('request_deadline', sa.DateTime(), nullable=True),
        sa.Column('live', sa.Boolean(), nullable=True),
        sa.Column('golive_id', sa.Integer(), nullable=True),
        sa.Column('golive_timestamp', sa.DateTime(), nullable=True),
        sa.Column('live_deadline', sa.DateTime(), nullable=True),
        sa.Column('closed', sa.Boolean(), nullable=True),
        sa.Column('closed_id', sa.Integer(), nullable=True),
        sa.Column('closed_timestamp', sa.DateTime(), nullable=True),
        sa.Column('submission_period', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['closed_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['golive_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['pclass_id'],
            ['project_classes.id'],
        ), sa.ForeignKeyConstraint(
            ['year'],
            ['main_config.year'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'project_class_to_messages',
        sa.Column('project_class_id', sa.Integer(), nullable=False),
        sa.Column('message_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['message_id'],
            ['messages.id'],
        ),
        sa.ForeignKeyConstraint(
            ['project_class_id'],
            ['project_classes.id'],
        ), sa.PrimaryKeyConstraint('project_class_id', 'message_id'))
    op.create_table(
        'projects', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('active', sa.Boolean(), nullable=True),
        sa.Column('keywords', sa.String(length=255), nullable=True),
        sa.Column('owner_id', sa.Integer(), nullable=True),
        sa.Column('group_id', sa.Integer(), nullable=True),
        sa.Column('meeting_reqd', sa.Integer(), nullable=True),
        sa.Column('capacity', sa.Integer(), nullable=True),
        sa.Column('enforce_capacity', sa.Boolean(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('reading', sa.Text(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['group_id'],
            ['research_groups.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['owner_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_projects_group_id'),
                    'projects', ['group_id'],
                    unique=False)
    op.create_index(op.f('ix_projects_name'),
                    'projects', ['name'],
                    unique=True)
    op.create_index(op.f('ix_projects_owner_id'),
                    'projects', ['owner_id'],
                    unique=False)
    op.create_table(
        'go_live_confirmation',
        sa.Column('faculty_id', sa.Integer(), nullable=False),
        sa.Column('pclass_config_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['faculty_id'],
            ['faculty_data.id'],
        ),
        sa.ForeignKeyConstraint(
            ['pclass_config_id'],
            ['project_class_config.id'],
        ), sa.PrimaryKeyConstraint('faculty_id', 'pclass_config_id'))
    op.create_table(
        'live_projects', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('config_id', sa.Integer(), nullable=True),
        sa.Column('number', sa.Integer(), nullable=True),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('keywords', sa.String(length=255), nullable=True),
        sa.Column('owner_id', sa.Integer(), nullable=True),
        sa.Column('group_id', sa.Integer(), nullable=True),
        sa.Column('capacity', sa.Integer(), nullable=True),
        sa.Column('enforce_capacity', sa.Boolean(), nullable=True),
        sa.Column('meeting_reqd', sa.Integer(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('reading', sa.Text(), nullable=True),
        sa.Column('page_views', sa.Integer(), nullable=True),
        sa.Column('last_view', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['config_id'],
            ['project_class_config.id'],
        ), sa.ForeignKeyConstraint(
            ['group_id'],
            ['research_groups.id'],
        ), sa.ForeignKeyConstraint(
            ['owner_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_live_projects_group_id'),
                    'live_projects', ['group_id'],
                    unique=False)
    op.create_index(op.f('ix_live_projects_name'),
                    'live_projects', ['name'],
                    unique=False)
    op.create_index(op.f('ix_live_projects_owner_id'),
                    'live_projects', ['owner_id'],
                    unique=False)
    op.create_table(
        'project_class_to_programmes',
        sa.Column('project_class_id', sa.Integer(), nullable=False),
        sa.Column('programme_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['programme_id'],
            ['degree_programmes.id'],
        ),
        sa.ForeignKeyConstraint(
            ['project_class_id'],
            ['project_classes.id'],
        ), sa.PrimaryKeyConstraint('project_class_id', 'programme_id'))
    op.create_table(
        'project_to_classes',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('project_class_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_class_id'],
            ['project_classes.id'],
        ), sa.ForeignKeyConstraint(
            ['project_id'],
            ['projects.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'project_class_id'))
    op.create_table(
        'project_to_programmes',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('programme_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['programme_id'],
            ['degree_programmes.id'],
        ), sa.ForeignKeyConstraint(
            ['project_id'],
            ['projects.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'programme_id'))
    op.create_table(
        'project_to_skills',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('skill_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_id'],
            ['projects.id'],
        ), sa.ForeignKeyConstraint(
            ['skill_id'],
            ['transferable_skills.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'skill_id'))
    op.create_table(
        'project_to_supervision',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('supervisor.id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_id'],
            ['projects.id'],
        ), sa.ForeignKeyConstraint(
            ['supervisor.id'],
            ['supervision_team.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'supervisor.id'))
    op.create_table(
        'selecting_students', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('retired', sa.Integer(), nullable=True),
        sa.Column('config_id', sa.Integer(), nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['config_id'],
            ['project_class_config.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'student_data', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('exam_number', sa.Integer(), nullable=True),
        sa.Column('cohort', sa.Integer(), nullable=True),
        sa.Column('programme_id', sa.Integer(), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=True),
        sa.Column('creation_timestamp', sa.DateTime(), nullable=True),
        sa.Column('last_edit_id', sa.Integer(), nullable=True),
        sa.Column('last_edit_timestamp', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['creator_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['last_edit_id'],
            ['users.id'],
        ), sa.ForeignKeyConstraint(
            ['programme_id'],
            ['degree_programmes.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_student_data_cohort'),
                    'student_data', ['cohort'],
                    unique=False)
    op.create_index(op.f('ix_student_data_exam_number'),
                    'student_data', ['exam_number'],
                    unique=True)
    op.create_table(
        'submitting_students', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('retired', sa.Integer(), nullable=True),
        sa.Column('config_id', sa.Integer(), nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['config_id'],
            ['project_class_config.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['users.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'bookmarks', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('liveproject_id', sa.Integer(), nullable=True),
        sa.Column('rank', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['liveproject_id'],
            ['live_projects.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['selecting_students.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'confirmation_requests',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('student_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_id'],
            ['live_projects.id'],
        ), sa.ForeignKeyConstraint(
            ['student_id'],
            ['selecting_students.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'student_id'))
    op.create_table(
        'faculty_confirmations',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('student_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_id'],
            ['live_projects.id'],
        ), sa.ForeignKeyConstraint(
            ['student_id'],
            ['selecting_students.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'student_id'))
    op.create_table(
        'live_project_to_classes',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('project_class_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_class_id'],
            ['project_classes.id'],
        ), sa.ForeignKeyConstraint(
            ['project_id'],
            ['live_projects.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'project_class_id'))
    op.create_table(
        'live_project_to_programmes',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('programme_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['programme_id'],
            ['degree_programmes.id'],
        ), sa.ForeignKeyConstraint(
            ['project_id'],
            ['live_projects.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'programme_id'))
    op.create_table(
        'live_project_to_skills',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('skill_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_id'],
            ['live_projects.id'],
        ), sa.ForeignKeyConstraint(
            ['skill_id'],
            ['transferable_skills.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'skill_id'))
    op.create_table(
        'live_project_to_supervision',
        sa.Column('project_id', sa.Integer(), nullable=False),
        sa.Column('supervisor.id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['project_id'],
            ['live_projects.id'],
        ), sa.ForeignKeyConstraint(
            ['supervisor.id'],
            ['supervision_team.id'],
        ), sa.PrimaryKeyConstraint('project_id', 'supervisor.id'))
Exemple #25
0
    def define_tables(cls, metadata):
        Table(
            "quote ' one",
            metadata,
            Column("id", Integer),
            Column("name", String(50)),
            Column("data", String(50)),
            Column("related_id", Integer),
            sa.PrimaryKeyConstraint("id", name="pk quote ' one"),
            sa.Index("ix quote ' one", "name"),
            sa.UniqueConstraint(
                "data",
                name="uq quote' one",
            ),
            sa.ForeignKeyConstraint(["id"], ["related.id"],
                                    name="fk quote ' one"),
            sa.CheckConstraint("name != 'foo'", name="ck quote ' one"),
            comment=r"""quote ' one comment""",
            test_needs_fk=True,
        )

        if testing.requires.symbol_names_w_double_quote.enabled:
            Table(
                'quote " two',
                metadata,
                Column("id", Integer),
                Column("name", String(50)),
                Column("data", String(50)),
                Column("related_id", Integer),
                sa.PrimaryKeyConstraint("id", name='pk quote " two'),
                sa.Index('ix quote " two', "name"),
                sa.UniqueConstraint(
                    "data",
                    name='uq quote" two',
                ),
                sa.ForeignKeyConstraint(["id"], ["related.id"],
                                        name='fk quote " two'),
                sa.CheckConstraint("name != 'foo'", name='ck quote " two '),
                comment=r"""quote " two comment""",
                test_needs_fk=True,
            )

        Table(
            "related",
            metadata,
            Column("id", Integer, primary_key=True),
            Column("related", Integer),
            test_needs_fk=True,
        )

        if testing.requires.view_column_reflection.enabled:

            if testing.requires.symbol_names_w_double_quote.enabled:
                names = [
                    "quote ' one",
                    'quote " two',
                ]
            else:
                names = [
                    "quote ' one",
                ]
            for name in names:
                query = "CREATE VIEW %s AS SELECT * FROM %s" % (
                    testing.db.dialect.identifier_preparer.quote(
                        "view %s" % name),
                    testing.db.dialect.identifier_preparer.quote(name),
                )

                event.listen(metadata, "after_create", DDL(query))
                event.listen(
                    metadata,
                    "before_drop",
                    DDL("DROP VIEW %s" %
                        testing.db.dialect.identifier_preparer.quote(
                            "view %s" % name)),
                )
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'discipline',
        sa.Column('discipline_id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=25), nullable=False),
        sa.Column('category', sa.String(length=25), nullable=True),
        sa.PrimaryKeyConstraint('discipline_id'),
    )
    op.create_index(op.f('ix_discipline_category'),
                    'discipline', ['category'],
                    unique=False)
    op.create_index(op.f('ix_discipline_discipline_id'),
                    'discipline', ['discipline_id'],
                    unique=False)
    op.create_index(op.f('ix_discipline_name'),
                    'discipline', ['name'],
                    unique=False)

    conn = op.get_bind()
    inspector = Inspector.from_engine(conn)
    tables = inspector.get_table_names()
    if 'program_template' not in tables:
        op.create_table(
            'program_template',
            sa.Column('program_template_id', sa.Integer(), nullable=False),
            sa.Column('hours', sa.Integer(), nullable=True),
            sa.Column('category', sa.String(length=25), nullable=True),
            sa.PrimaryKeyConstraint('program_template_id'),
            sa.UniqueConstraint('category'),
        )
        op.create_index(
            op.f('ix_program_template_program_template_id'),
            'program_template',
            ['program_template_id'],
            unique=False,
        )

    op.create_table(
        'program_to_discipline',
        sa.Column('discipline_id', sa.Integer(), nullable=False),
        sa.Column('program_id', sa.Integer(), nullable=False),
        sa.Column('hours', sa.Integer(), nullable=True),
        sa.Column('parameters',
                  postgresql.JSONB(astext_type=sa.Text()),
                  nullable=True),
        sa.ForeignKeyConstraint(
            ['discipline_id'],
            ['discipline.discipline_id'],
        ),
        sa.ForeignKeyConstraint(
            ['program_id'],
            ['program.program_id'],
        ),
        sa.PrimaryKeyConstraint('discipline_id', 'program_id'),
    )
    op.drop_column('program', 'is_minor')
    op.add_column('program_to_parameter',
                  sa.Column('parameter_id', sa.Integer(), nullable=False))
    op.add_column('program_to_parameter',
                  sa.Column('program_id', sa.Integer(), nullable=False))
    op.drop_constraint('program_to_parameter_right_id_fkey',
                       'program_to_parameter',
                       type_='foreignkey')
    op.drop_constraint('program_to_parameter_left_id_fkey',
                       'program_to_parameter',
                       type_='foreignkey')
    op.create_foreign_key(None, 'program_to_parameter', 'program',
                          ['program_id'], ['program_id'])
    op.create_foreign_key(None, 'program_to_parameter', 'parameter',
                          ['parameter_id'], ['parameter_id'])
    op.drop_column('program_to_parameter', 'right_id')
    op.drop_column('program_to_parameter', 'left_id')
Exemple #27
0
metadata = sa.MetaData()


class CurrencyEnum(enum.Enum):
    """Enum for currencies."""

    USD = "USD"


users = sa.Table(
    "users",
    metadata,
    sa.Column("id", sa.Integer, primary_key=True, nullable=False),
    sa.Column("email", sa.String, nullable=False),
    sa.UniqueConstraint("email", name="unique_email"),
)

wallets = sa.Table(
    "wallets",
    metadata,
    sa.Column("id", sa.Integer, primary_key=True, nullable=False),
    sa.Column(
        "user_id",
        sa.Integer,
        sa.ForeignKey("users.id", ondelete="cascade"),
        nullable=False,
        unique=True,
    ),
    sa.Column("balance",
              sa.Numeric(10, 2, asdecimal=True),
Exemple #28
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('ih_area_info',
                    sa.Column('create_time', sa.DateTime(), nullable=True),
                    sa.Column('update_time', sa.DateTime(), nullable=True),
                    sa.Column('is_delete', sa.Integer(), nullable=True),
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=32), nullable=False),
                    sa.PrimaryKeyConstraint('id'))
    op.create_table('ih_facility_info',
                    sa.Column('create_time', sa.DateTime(), nullable=True),
                    sa.Column('update_time', sa.DateTime(), nullable=True),
                    sa.Column('is_delete', sa.Integer(), nullable=True),
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=32), nullable=False),
                    sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'ih_user_profile',
        sa.Column('create_time', sa.DateTime(), nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('is_delete', sa.Integer(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=32), nullable=False),
        sa.Column('password_hash', sa.String(length=128), nullable=False),
        sa.Column('mobile', sa.String(length=11), nullable=False),
        sa.Column('real_name', sa.String(length=32), nullable=True),
        sa.Column('id_card', sa.String(length=20), nullable=True),
        sa.Column('avatar_url', sa.String(length=128), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('mobile'),
        sa.UniqueConstraint('name'))
    op.create_table(
        'ih_house_info', sa.Column('create_time', sa.DateTime(),
                                   nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('is_delete', sa.Integer(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('area_id', sa.Integer(), nullable=False),
        sa.Column('title', sa.String(length=64), nullable=False),
        sa.Column('price', sa.Integer(), nullable=True),
        sa.Column('address', sa.String(length=512), nullable=True),
        sa.Column('room_count', sa.Integer(), nullable=True),
        sa.Column('acreage', sa.Integer(), nullable=True),
        sa.Column('unit', sa.String(length=32), nullable=True),
        sa.Column('capacity', sa.Integer(), nullable=True),
        sa.Column('beds', sa.String(length=64), nullable=True),
        sa.Column('deposit', sa.Integer(), nullable=True),
        sa.Column('min_days', sa.Integer(), nullable=True),
        sa.Column('max_days', sa.Integer(), nullable=True),
        sa.Column('order_count', sa.Integer(), nullable=True),
        sa.Column('index_image_url', sa.String(length=256), nullable=True),
        sa.ForeignKeyConstraint(
            ['area_id'],
            ['ih_area_info.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['ih_user_profile.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'ih_house_facility', sa.Column('house_id',
                                       sa.Integer(),
                                       nullable=False),
        sa.Column('facility_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['facility_id'],
            ['ih_facility_info.id'],
        ), sa.ForeignKeyConstraint(
            ['house_id'],
            ['ih_house_info.id'],
        ), sa.PrimaryKeyConstraint('house_id', 'facility_id'))
    op.create_table(
        'ih_house_image', sa.Column('create_time',
                                    sa.DateTime(),
                                    nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('is_delete', sa.Integer(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('house_id', sa.Integer(), nullable=False),
        sa.Column('url', sa.String(length=256), nullable=False),
        sa.ForeignKeyConstraint(
            ['house_id'],
            ['ih_house_info.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'ih_order_info', sa.Column('create_time', sa.DateTime(),
                                   nullable=True),
        sa.Column('update_time', sa.DateTime(), nullable=True),
        sa.Column('is_delete', sa.Integer(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('house_id', sa.Integer(), nullable=False),
        sa.Column('begin_date', sa.DateTime(), nullable=False),
        sa.Column('end_date', sa.DateTime(), nullable=False),
        sa.Column('days', sa.Integer(), nullable=False),
        sa.Column('house_price', sa.Integer(), nullable=False),
        sa.Column('amount', sa.Integer(), nullable=False),
        sa.Column('status',
                  sa.Enum('WAIT_ACCEPT', 'WAIT_PAYMENT', 'PAID',
                          'WAIT_COMMENT', 'COMPLETE', 'CANCELED', 'REJECTED'),
                  nullable=True), sa.Column('comment',
                                            sa.Text(),
                                            nullable=True),
        sa.ForeignKeyConstraint(
            ['house_id'],
            ['ih_house_info.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['ih_user_profile.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_ih_order_info_status'),
                    'ih_order_info', ['status'],
                    unique=False)
Exemple #29
0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'institution', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=120), nullable=False),
        sa.Column('administrator_id', sa.Integer(), nullable=False),
        sa.Column('created_on', sa.DateTime(), nullable=True),
        sa.Column('blurb', sa.String(length=400), nullable=True),
        sa.Column('view_institution_only_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(['administrator_id'], [u'user.id'],
                                name='fk_institution_creator_id',
                                use_alter=True),
        sa.ForeignKeyConstraint(
            ['view_institution_only_id'],
            ['institution.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_institution_name'),
                    'institution', ['name'],
                    unique=True)
    op.create_table('subject', sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=64), nullable=False),
                    sa.Column('time_created', sa.DateTime(), nullable=True),
                    sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'))
    op.create_table(
        'group', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=120), nullable=True),
        sa.Column('creator_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(['creator_id'], [u'user.id'],
                                name='fk_group_creator_id',
                                use_alter=True), sa.PrimaryKeyConstraint('id'))
    op.create_table('topic', sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=64), nullable=False),
                    sa.Column('time_created', sa.DateTime(), nullable=True),
                    sa.Column('subject_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(
                        ['subject_id'],
                        [u'subject.id'],
                    ), sa.PrimaryKeyConstraint('id'),
                    sa.UniqueConstraint('name'))
    op.create_table(
        'user', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('password_hash', sa.String(length=128), nullable=False),
        sa.Column('email', sa.String(length=128), nullable=False),
        sa.Column('slug', sa.String(length=128), nullable=False),
        sa.Column('name', sa.String(length=64), nullable=False),
        sa.Column('forename', sa.String(length=64), nullable=True),
        sa.Column('surname', sa.String(length=64), nullable=True),
        sa.Column('confirmed', sa.Boolean(), nullable=True),
        sa.Column('blurb', sa.String(length=256), nullable=True),
        sa.Column('role', sa.SmallInteger(), nullable=False),
        sa.Column('time_registered', sa.DateTime(), nullable=True),
        sa.Column('last_seen', sa.DateTime(), nullable=True),
        sa.Column('enterprise_licence', sa.DateTime(), nullable=True),
        sa.Column('time_deleted', sa.DateTime(), nullable=True),
        sa.Column('subject_id', sa.Integer(), nullable=True),
        sa.Column('view_institution_only_id', sa.Integer(), nullable=True),
        sa.Column('institution_student_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['institution_student_id'],
            ['institution.id'],
        ), sa.ForeignKeyConstraint(
            ['subject_id'],
            ['subject.id'],
        ),
        sa.ForeignKeyConstraint(
            ['view_institution_only_id'],
            ['institution.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
    op.create_index(op.f('ix_user_slug'), 'user', ['slug'], unique=True)
    op.create_table('student_tutor',
                    sa.Column('tutor_id', sa.Integer(), nullable=True),
                    sa.Column('student_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['student_id'],
                        ['user.id'],
                    ), sa.ForeignKeyConstraint(
                        ['tutor_id'],
                        ['user.id'],
                    ))
    op.create_table(
        'module', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=120), nullable=True),
        sa.Column('description', sa.String(length=400), nullable=True),
        sa.Column('notes', sa.String(length=400), nullable=True),
        sa.Column('material_type', sa.String(length=120), nullable=True),
        sa.Column('time_created', sa.DateTime(), nullable=True),
        sa.Column('last_updated', sa.DateTime(), nullable=True),
        sa.Column('material_source', sa.String(length=120), nullable=True),
        sa.Column('material_path', sa.String(length=400), nullable=True),
        sa.Column('submitted', sa.DateTime(), nullable=True),
        sa.Column('published', sa.DateTime(), nullable=True),
        sa.Column('locked', sa.DateTime(), nullable=True),
        sa.Column('deleted', sa.DateTime(), nullable=True),
        sa.Column('live', sa.Boolean(), nullable=True),
        sa.Column('subtitles', sa.Boolean(), nullable=True),
        sa.Column('easy_language', sa.Boolean(), nullable=True),
        sa.Column('extension', sa.Boolean(), nullable=True),
        sa.Column('for_teachers', sa.Boolean(), nullable=True),
        sa.Column('visually_impaired', sa.Boolean(), nullable=True),
        sa.Column('votes', sa.Integer(), nullable=True),
        sa.Column('subject_id', sa.Integer(), nullable=False),
        sa.Column('author_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['author_id'],
            ['user.id'],
        ), sa.ForeignKeyConstraint(
            ['subject_id'],
            ['subject.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'objective', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('name', sa.String(length=50), nullable=False),
        sa.Column('subject_id', sa.Integer(), nullable=False),
        sa.Column('topic_id', sa.Integer(), nullable=True),
        sa.Column('description', sa.String(length=50), nullable=True),
        sa.Column('time_created', sa.DateTime(), nullable=True),
        sa.Column('last_updated', sa.DateTime(), nullable=True),
        sa.Column('approved', sa.DateTime(), nullable=True),
        sa.Column('assessable', sa.Boolean(), nullable=False),
        sa.Column('created_by_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['created_by_id'],
            ['user.id'],
        ), sa.ForeignKeyConstraint(
            ['subject_id'],
            [u'subject.id'],
        ), sa.ForeignKeyConstraint(
            ['topic_id'],
            [u'topic.id'],
        ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name'))
    op.create_table('group_members',
                    sa.Column('group_id', sa.Integer(), nullable=True),
                    sa.Column('member_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['group_id'],
                        ['group.id'],
                    ), sa.ForeignKeyConstraint(
                        ['member_id'],
                        ['user.id'],
                    ))
    op.create_table('scheme_of_work',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.Column('name', sa.String(length=120), nullable=True),
                    sa.Column('creator_id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(
                        ['creator_id'],
                        [u'user.id'],
                    ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'institution_members',
        sa.Column('institution_id', sa.Integer(), nullable=True),
        sa.Column('member_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['institution_id'],
            ['institution.id'],
        ), sa.ForeignKeyConstraint(
            ['member_id'],
            ['user.id'],
        ))
    op.create_table(
        'question', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('question', sa.String(length=5000), nullable=True),
        sa.Column('answer', sa.String(length=5000), nullable=True),
        sa.Column('time_created', sa.DateTime(), nullable=True),
        sa.Column('last_updated', sa.DateTime(), nullable=True),
        sa.Column('submitted', sa.DateTime(), nullable=True),
        sa.Column('published', sa.DateTime(), nullable=True),
        sa.Column('locked', sa.DateTime(), nullable=True),
        sa.Column('extension', sa.Boolean(), nullable=True),
        sa.Column('visually_impaired', sa.Boolean(), nullable=True),
        sa.Column('votes', sa.Integer(), nullable=True),
        sa.Column('subject_id', sa.Integer(), nullable=False),
        sa.Column('author_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['author_id'],
            ['user.id'],
        ), sa.ForeignKeyConstraint(
            ['subject_id'],
            [u'subject.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'institution_approved_questions',
        sa.Column('institution_id', sa.Integer(), nullable=True),
        sa.Column('question_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['institution_id'],
            ['institution.id'],
        ), sa.ForeignKeyConstraint(
            ['question_id'],
            ['question.id'],
        ))
    op.create_table('user_module', sa.Column('id',
                                             sa.Integer(),
                                             nullable=False),
                    sa.Column('user_id', sa.Integer(), nullable=True),
                    sa.Column('module_id', sa.Integer(), nullable=True),
                    sa.Column('first_viewed', sa.DateTime(), nullable=True),
                    sa.Column('last_viewed', sa.DateTime(), nullable=True),
                    sa.Column('starred', sa.Boolean(), nullable=True),
                    sa.Column('vote', sa.Integer(), nullable=True),
                    sa.Column('notes', sa.String(length=1000), nullable=True),
                    sa.Column('enrolled', sa.Boolean(), nullable=True),
                    sa.Column('deleted', sa.Boolean(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['module_id'],
                        [u'module.id'],
                    ), sa.ForeignKeyConstraint(
                        ['user_id'],
                        [u'user.id'],
                    ), sa.PrimaryKeyConstraint('id'))
    op.create_table('course_modules',
                    sa.Column('course_id', sa.Integer(), nullable=True),
                    sa.Column('module_id', sa.Integer(), nullable=True),
                    sa.ForeignKeyConstraint(
                        ['course_id'],
                        ['module.id'],
                    ), sa.ForeignKeyConstraint(
                        ['module_id'],
                        ['module.id'],
                    ))
    op.create_table(
        'user_objective', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('assessor_id', sa.Integer(), nullable=True),
        sa.Column('objective_id', sa.Integer(), nullable=True),
        sa.Column('completed', sa.SmallInteger(), nullable=True),
        sa.ForeignKeyConstraint(
            ['assessor_id'],
            [u'user.id'],
        ), sa.ForeignKeyConstraint(
            ['objective_id'],
            [u'objective.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            [u'user.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'objective_heirarchy',
        sa.Column('prerequisite_id', sa.Integer(), nullable=True),
        sa.Column('followon_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['followon_id'],
            ['objective.id'],
        ), sa.ForeignKeyConstraint(
            ['prerequisite_id'],
            ['objective.id'],
        ))
    op.create_table(
        'module_objectives', sa.Column('module_id',
                                       sa.Integer(),
                                       nullable=True),
        sa.Column('objective_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['module_id'],
            ['module.id'],
        ), sa.ForeignKeyConstraint(
            ['objective_id'],
            ['objective.id'],
        ))
    op.create_table(
        'scheme_objectives', sa.Column('scheme_id',
                                       sa.Integer(),
                                       nullable=True),
        sa.Column('objective_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['objective_id'],
            ['objective.id'],
        ), sa.ForeignKeyConstraint(
            ['scheme_id'],
            ['scheme_of_work.id'],
        ))
    op.create_table(
        'question_objectives',
        sa.Column('question_id', sa.Integer(), nullable=True),
        sa.Column('objective_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['objective_id'],
            ['objective.id'],
        ), sa.ForeignKeyConstraint(
            ['question_id'],
            ['question.id'],
        ))
    op.create_table(
        'institution_approved_modules',
        sa.Column('institution_id', sa.Integer(), nullable=True),
        sa.Column('module_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['institution_id'],
            ['institution.id'],
        ), sa.ForeignKeyConstraint(
            ['module_id'],
            ['module.id'],
        ))
    op.create_table(
        'message', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('from_id', sa.Integer(), nullable=True),
        sa.Column('to_id', sa.Integer(), nullable=True),
        sa.Column('subject', sa.Text(), nullable=False),
        sa.Column('body', sa.Text(), nullable=True),
        sa.Column('sent', sa.DateTime(), nullable=True),
        sa.Column('read', sa.DateTime(), nullable=True),
        sa.Column('reported', sa.DateTime(), nullable=True),
        sa.Column('deleted', sa.DateTime(), nullable=True),
        sa.Column('request_access', sa.Boolean(), nullable=True),
        sa.Column('recommended_material_id', sa.Integer(), nullable=True),
        sa.Column('assign_objective_id', sa.Integer(), nullable=True),
        sa.Column('assign_scheme_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['assign_objective_id'],
            [u'objective.id'],
        ),
        sa.ForeignKeyConstraint(
            ['assign_scheme_id'],
            [u'scheme_of_work.id'],
        ), sa.ForeignKeyConstraint(
            ['from_id'],
            [u'user.id'],
        ),
        sa.ForeignKeyConstraint(
            ['recommended_material_id'],
            [u'module.id'],
        ), sa.ForeignKeyConstraint(
            ['to_id'],
            [u'user.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'question_selections', sa.Column('user_id',
                                         sa.Integer(),
                                         nullable=True),
        sa.Column('question_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['question_id'],
            ['question.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['user.id'],
        ))
    op.create_table(
        'scheme_users', sa.Column('scheme_id', sa.Integer(), nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ['scheme_id'],
            ['scheme_of_work.id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            ['user.id'],
        ))
Exemple #30
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'blacklist_tokens',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('token', sa.String(length=500), nullable=False),
        sa.Column('blacklisted_on', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('token'))
    op.create_table(
        'item',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('public_id', sa.String(length=100), nullable=True),
        sa.Column('release_date', sa.DateTime(), nullable=True),
        sa.Column('selling', sa.Boolean(), nullable=False),
        sa.Column('name', sa.String(length=100), nullable=False),
        sa.Column('category', sa.String(length=50), nullable=False),
        sa.Column('cost', sa.Float(), nullable=False),
        sa.Column('color', sa.String(length=50), nullable=True),
        sa.Column('size', sa.String(length=10), nullable=False),
        sa.Column('available', sa.Integer(), nullable=False),
        sa.Column('picture', sa.String(), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('public_id'))
    op.create_table(
        'user',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('public_id', sa.String(length=100), nullable=True),
        sa.Column('registered_on', sa.DateTime(), nullable=True),
        sa.Column('fname', sa.String(length=100), nullable=True),
        sa.Column('lname', sa.String(length=100), nullable=True),
        sa.Column('email', sa.String(length=255), nullable=False),
        sa.Column('password_hash', sa.String(length=100), nullable=True),
        sa.Column('phone', sa.String(length=10), nullable=True),
        sa.Column('address', sa.String(length=100), nullable=True),
        sa.Column('city', sa.String(length=100), nullable=True),
        sa.Column('zip_code', sa.String(length=5), nullable=True),
        sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'),
        sa.UniqueConstraint('public_id'))
    op.create_table(
        'cart',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('cost', sa.Float(), nullable=True),
        sa.Column('size', sa.Integer(), nullable=True),
        sa.Column('user_id', sa.String(length=100), nullable=True),
        sa.ForeignKeyConstraint(
            ['user_id'],
            ['user.public_id'],
        ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('user_id'))
    op.create_table(
        'cart_item',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('cost', sa.Float(), nullable=True),
        sa.Column('quantity', sa.Integer(), nullable=True),
        sa.Column('name', sa.String(), nullable=True),
        sa.Column('cart_id', sa.String(length=100), nullable=False),
        sa.Column('item_id', sa.String(length=100), nullable=False),
        sa.ForeignKeyConstraint(
            ['cart_id'],
            ['cart.user_id'],
        ), sa.ForeignKeyConstraint(
            ['item_id'],
            ['item.public_id'],
        ), sa.PrimaryKeyConstraint('id', 'cart_id', 'item_id'))