Exemple #1
0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('publishers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', citext.CIText(), nullable=False),
    sa.Column('site', sa.Text(), nullable=True),
    sa.Column('series', sa.Integer(), nullable=True),
    sa.Column('changetime', sa.DateTime(), nullable=False),
    sa.Column('changeuser', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['changeuser'], ['users.id'], ),
    sa.ForeignKeyConstraint(['series'], ['series.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('series', 'name')
    )
    op.create_index(op.f('ix_publishers_changetime'), 'publishers', ['changetime'], unique=False)
    op.create_index(op.f('ix_publishers_changeuser'), 'publishers', ['changeuser'], unique=False)
    op.create_table('publisherschanges',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', citext.CIText(), nullable=False),
    sa.Column('site', sa.Text(), nullable=True),
    sa.Column('operation', sa.Text(), nullable=True),
    sa.Column('srccol', sa.Integer(), nullable=True),
    sa.Column('series', sa.Integer(), nullable=True),
    sa.Column('changetime', sa.DateTime(), nullable=False),
    sa.Column('changeuser', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['changeuser'], ['users.id'], ),
    sa.ForeignKeyConstraint(['series'], ['series.id'], ),
    sa.ForeignKeyConstraint(['srccol'], ['publishers.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id'),
    )
    op.create_index(op.f('ix_publisherschanges_changetime'), 'publisherschanges', ['changetime'], unique=False)
    op.create_index(op.f('ix_publisherschanges_changeuser'), 'publisherschanges', ['changeuser'], unique=False)
    op.create_index(op.f('ix_publisherschanges_srccol'), 'publisherschanges', ['srccol'], unique=False)
Exemple #2
0
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('serieschanges',
    sa.Column('id', sa.INTEGER(), nullable=False),
    sa.Column('title', citext.CIText(), autoincrement=False, nullable=True),
    sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('orig_lang', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('chapter', postgresql.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
    sa.Column('pub_date', postgresql.TIMESTAMP(), autoincrement=False, nullable=True),
    sa.Column('fspath', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('hash', sa.TEXT(), autoincrement=False, nullable=False),
    sa.Column('operation', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('srccol', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('changeuser', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.Column('changetime', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
    sa.Column('srcfname', sa.TEXT(), autoincrement=False, nullable=True),
    sa.Column('downloads', sa.INTEGER(), autoincrement=False, nullable=True),
    sa.ForeignKeyConstraint(['changeuser'], ['users.id'], name='serieschanges_changeuser_fkey'),
    sa.ForeignKeyConstraint(['srccol'], ['story.id'], name='serieschanges_srccol_fkey', ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id', name='serieschanges_pkey')
    )
    op.drop_index(op.f('ix_storychanges_srccol'), table_name='storychanges')
    op.drop_index(op.f('ix_storychanges_changeuser'), table_name='storychanges')
    op.drop_index(op.f('ix_storychanges_changetime'), table_name='storychanges')
    op.drop_table('storychanges')
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'web_pages',
        sa.Column('previous_release',
                  sa.INTEGER(),
                  autoincrement=False,
                  nullable=True))
    op.create_foreign_key('web_pages_previous_release_fkey', 'web_pages',
                          'web_page_history', ['previous_release'], ['id'])
    op.create_table(
        'web_page_history', sa.Column('id', sa.INTEGER(), nullable=False),
        sa.Column('errno', sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('url', sa.TEXT(), autoincrement=False, nullable=False),
        sa.Column('file', sa.INTEGER(), autoincrement=False, nullable=True),
        sa.Column('distance',
                  sa.INTEGER(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('is_text', sa.BOOLEAN(), autoincrement=False, nullable=True),
        sa.Column('title', citext.CIText(), autoincrement=False,
                  nullable=True),
        sa.Column('mimetype', sa.TEXT(), autoincrement=False, nullable=True),
        sa.Column('content', sa.TEXT(), autoincrement=False, nullable=True),
        sa.Column('fetchtime',
                  postgresql.TIMESTAMP(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('addtime',
                  postgresql.TIMESTAMP(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('tsv_content',
                  postgresql.TSVECTOR(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('root_rel',
                  sa.INTEGER(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('newer_rel',
                  sa.INTEGER(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('older_rel',
                  sa.INTEGER(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('contenthash', sa.TEXT(), autoincrement=False,
                  nullable=True),
        sa.Column('is_diff', sa.BOOLEAN(), autoincrement=False, nullable=True),
        sa.ForeignKeyConstraint(['file'], ['web_files.id'],
                                name='web_page_history_file_fkey'),
        sa.ForeignKeyConstraint(['newer_rel'], ['web_page_history.id'],
                                name='web_page_history_newer_rel_fkey'),
        sa.ForeignKeyConstraint(['older_rel'], ['web_page_history.id'],
                                name='web_page_history_older_rel_fkey'),
        sa.ForeignKeyConstraint(['root_rel'], ['web_pages.id'],
                                name='web_page_history_root_rel_fkey'),
        sa.PrimaryKeyConstraint('id', name='web_page_history_pkey'))
Exemple #4
0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('web_page_history',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('errno', sa.Integer(), nullable=True),
    sa.Column('url', sa.Text(), nullable=False),
    sa.Column('file', sa.Integer(), nullable=True),
    sa.Column('distance', sa.Integer(), nullable=False),
    sa.Column('is_text', sa.Boolean(), nullable=True),
    sa.Column('title', citext.CIText(), nullable=True),
    sa.Column('mimetype', sa.Text(), nullable=True),
    sa.Column('content', sa.Text(), nullable=True),
    sa.Column('fetchtime', sa.DateTime(), nullable=True),
    sa.Column('addtime', sa.DateTime(), nullable=True),
    sa.Column('tsv_content', sqlalchemy_utils.types.ts_vector.TSVectorType(), nullable=True),
    sa.Column('root_rel', sa.Integer(), nullable=False),
    sa.Column('newer_rel', sa.Integer(), nullable=True),
    sa.Column('older_rel', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['file'], ['web_files.id'], ),
    sa.ForeignKeyConstraint(['newer_rel'], ['web_page_history.id'], ),
    sa.ForeignKeyConstraint(['older_rel'], ['web_page_history.id'], ),
    sa.ForeignKeyConstraint(['root_rel'], ['web_pages.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_web_page_history_distance'), 'web_page_history', ['distance'], unique=False)
    op.create_index('ix_web_page_history_tsv_content', 'web_page_history', ['tsv_content'], unique=False, postgresql_using='gin')
    op.create_index(op.f('ix_web_page_history_url'), 'web_page_history', ['url'], unique=True)
def upgrade():
    op.add_column(
        "release_files",
        sa.Column("blake2_256_digest", citext.CIText(), nullable=True))
    op.create_unique_constraint(None, "release_files", ["blake2_256_digest"])
    op.create_check_constraint(None, "release_files",
                               "sha256_digest ~* '^[A-F0-9]{64}$'")
Exemple #6
0
class MangaTags(Base):
    __tablename__ = 'manga_tags'
    id = Column(Integer, primary_key=True)
    tag = Column(citext.CIText(), nullable=False, index=True)

    __table_args__ = (
        UniqueConstraint('tag'),
        CheckConstraint('length(tag) >= 2'),
    )

    @classmethod
    def get_or_create(cls, tag):
        tmp = _session_factory.query(cls)    \
         .filter(cls.tag == tag) \
         .scalar()
        if tmp:
            _session_factory.expunge(tmp)
            return tmp

        # print("manga_tag_creator", tag)
        tmp = cls(tag=tag)
        _session_factory.add(tmp)
        _session_factory.commit()
        _session_factory.expunge(tmp)
        return tmp
Exemple #7
0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('storychanges',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', citext.CIText(), nullable=True),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('orig_lang', sa.Text(), nullable=True),
    sa.Column('chapter', sa.Float(), nullable=True),
    sa.Column('pub_date', sa.DateTime(), nullable=True),
    sa.Column('srcfname', sa.Text(), nullable=True),
    sa.Column('fspath', sa.Text(), nullable=True),
    sa.Column('hash', sa.Text(), nullable=False),
    sa.Column('downloads', sa.Integer(), nullable=True),
    sa.Column('operation', sa.Text(), nullable=True),
    sa.Column('srccol', sa.Integer(), nullable=True),
    sa.Column('changeuser', sa.Integer(), nullable=True),
    sa.Column('changetime', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['changeuser'], ['users.id'], ),
    sa.ForeignKeyConstraint(['srccol'], ['story.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_storychanges_changetime'), 'storychanges', ['changetime'], unique=False)
    op.create_index(op.f('ix_storychanges_changeuser'), 'storychanges', ['changeuser'], unique=False)
    op.create_index(op.f('ix_storychanges_srccol'), 'storychanges', ['srccol'], unique=False)
    op.drop_table('serieschanges')
Exemple #8
0
class HentaiReleases(Base):
    __tablename__ = 'hentai_releases'
    id = Column(BigInteger, primary_key=True)
    state = Column(dlstate_enum, nullable=False, index=True, default='new')
    err_str = Column(Text)

    source_site = Column(Text, nullable=False,
                         index=True)  # Actual source site
    source_id = Column(
        Text, nullable=False,
        index=True)  # ID On source site. Usually (but not always) the item URL

    first_seen = Column(DateTime, nullable=False)
    posted_at = Column(DateTime, nullable=False, default=datetime.datetime.min)
    downloaded_at = Column(DateTime,
                           nullable=False,
                           default=datetime.datetime.min)
    last_checked = Column(DateTime,
                          nullable=False,
                          default=datetime.datetime.min)

    deleted = Column(Boolean, default=False, nullable=False)
    was_duplicate = Column(Boolean, default=False, nullable=False)
    phash_duplicate = Column(Boolean, default=False, nullable=False)
    uploaded = Column(Boolean, default=False, nullable=False)

    dirstate = Column(dir_type, nullable=False, default="unknown")

    origin_name = Column(citext.CIText())
    series_name = Column(citext.CIText(), index=True)

    additional_metadata = Column(sqlalchemy_jsonfield.JSONField())

    fileid = Column(BigInteger, ForeignKey('release_files.id'))
    file = relationship('ReleaseFile', backref='hentai_releases')

    tags_rel = relationship('HentaiTags',
                            secondary=hentai_releases_tags_link,
                            backref=backref("hentai_releases", lazy='dynamic'),
                            collection_class=set)
    tags = association_proxy('tags_rel',
                             'tag',
                             creator=HentaiTags.get_or_create)

    __table_args__ = (UniqueConstraint('source_site', 'source_id'),
                      Index('hentai_releases_source_site_id_idx',
                            'source_site', 'source_id'))
Exemple #9
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('video_stream_moderators',
                    'email',
                    existing_type=citext.CIText(),
                    type_=sa.VARCHAR(),
                    existing_nullable=False)
    op.alter_column('ticket_holders',
                    'email',
                    existing_type=citext.CIText(),
                    type_=sa.VARCHAR(),
                    existing_nullable=True)
    op.alter_column('speaker',
                    'email',
                    existing_type=citext.CIText(),
                    type_=sa.VARCHAR(),
                    existing_nullable=True)
class Author(Base):
	__tablename__ = 'feed_author'
	id          = Column(Integer, primary_key=True)
	author      = Column(citext.CIText(), nullable=False, index=True)

	__table_args__ = (
		UniqueConstraint('author'),
		)
class Tags(Base):
	__tablename__ = 'feed_tags'
	id          = Column(Integer, primary_key=True)
	tag         = Column(citext.CIText(), nullable=False, index=True)

	__table_args__ = (
		UniqueConstraint('tag'),
		)
def upgrade():
    op.add_column('device',
                  sa.Column('devicehub_id',
                            citext.CIText(),
                            unique=True,
                            nullable=True),
                  schema=f'{get_inv()}')

    upgrade_data()
Exemple #13
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('manga_releases', 'series_name',
               existing_type=citext.CIText(),
               type_=sa.TEXT(),
               existing_nullable=True)
    op.alter_column('manga_releases', 'origin_name',
               existing_type=citext.CIText(),
               type_=sa.TEXT(),
               existing_nullable=True)
    op.alter_column('hentai_releases', 'series_name',
               existing_type=citext.CIText(),
               type_=sa.TEXT(),
               existing_nullable=True)
    op.alter_column('hentai_releases', 'origin_name',
               existing_type=citext.CIText(),
               type_=sa.TEXT(),
               existing_nullable=True)
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'book_releases', sa.Column('id', sa.BigInteger(), nullable=False),
        sa.Column('state', dlstate_enum, nullable=False),
        sa.Column('err_str', sa.Text(), nullable=True),
        sa.Column('source_site', sa.Text(), nullable=False),
        sa.Column('source_id', sa.Text(), nullable=False),
        sa.Column('first_seen', sa.DateTime(), nullable=False),
        sa.Column('posted_at', sa.DateTime(), nullable=False),
        sa.Column('downloaded_at', sa.DateTime(), nullable=False),
        sa.Column('last_checked', sa.DateTime(), nullable=False),
        sa.Column('deleted', sa.Boolean(), nullable=False),
        sa.Column('was_duplicate', sa.Boolean(), nullable=False),
        sa.Column('phash_duplicate', sa.Boolean(), nullable=False),
        sa.Column('uploaded', sa.Boolean(), nullable=False),
        sa.Column('dirstate', dir_type, nullable=False),
        sa.Column('origin_name', citext.CIText(), nullable=True),
        sa.Column('series_name', citext.CIText(), nullable=True),
        sa.Column('additional_metadata',
                  sqlalchemy_jsonfield.jsonfield.JSONField(),
                  nullable=True),
        sa.Column('fileid', sa.BigInteger(), nullable=True),
        sa.ForeignKeyConstraint(
            ['fileid'],
            ['release_files.id'],
        ), sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('source_site', 'source_id'))
    op.create_index('book_releases_source_site_id_idx',
                    'book_releases', ['source_site', 'source_id'],
                    unique=False)
    op.create_index(op.f('ix_book_releases_series_name'),
                    'book_releases', ['series_name'],
                    unique=False)
    op.create_index(op.f('ix_book_releases_source_id'),
                    'book_releases', ['source_id'],
                    unique=False)
    op.create_index(op.f('ix_book_releases_source_site'),
                    'book_releases', ['source_site'],
                    unique=False)
    op.create_index(op.f('ix_book_releases_state'),
                    'book_releases', ['state'],
                    unique=False)
def downgrade():
    op.alter_column(
        "release_files", "md5_digest", existing_type=sa.TEXT(), nullable=True
    )
    op.alter_column(
        "release_files",
        "blake2_256_digest",
        existing_type=citext.CIText(),
        nullable=True,
    )
Exemple #16
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'recipes',
        sa.Column('recipe_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('name', citext.CIText(), nullable=False),
        sa.Column('ingredients',
                  postgresql.JSONB(astext_type=sa.Text()),
                  nullable=False),
        sa.Column('instructions', citext.CIText(), nullable=False),
        sa.Column('est_completion_time_hrs', sa.NUMERIC(), nullable=False),
        sa.Column('date_created', sa.DateTime(), nullable=True),
        sa.Column('last_updated', sa.DateTime(), nullable=True),
        sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.ForeignKeyConstraint(
            ['user_id'],
            ['users.user_id'],
        ), sa.PrimaryKeyConstraint('recipe_id'),
        sa.UniqueConstraint('recipe_id'))
    op.create_unique_constraint(None, 'users', ['user_id'])
Exemple #17
0
class BookReleases(Base):
    __tablename__ = 'book_releases'
    id = Column(BigInteger, primary_key=True)
    state = Column(dlstate_enum, nullable=False, index=True, default='new')
    err_str = Column(Text)

    source_site = Column(Text, nullable=False,
                         index=True)  # Actual source site
    source_id = Column(
        Text, nullable=False,
        index=True)  # ID On source site. Usually (but not always) the item URL

    first_seen = Column(DateTime, nullable=False)
    posted_at = Column(DateTime, nullable=False, default=datetime.datetime.min)
    downloaded_at = Column(DateTime,
                           nullable=False,
                           default=datetime.datetime.min)
    last_checked = Column(DateTime,
                          nullable=False,
                          default=datetime.datetime.min)

    deleted = Column(Boolean, default=False, nullable=False)
    was_duplicate = Column(Boolean, default=False, nullable=False)
    phash_duplicate = Column(Boolean, default=False, nullable=False)
    uploaded = Column(Boolean, default=False, nullable=False)

    dirstate = Column(dir_type, nullable=False, default="unknown")

    origin_name = Column(citext.CIText())
    series_name = Column(citext.CIText(), index=True)

    additional_metadata = Column(sqlalchemy_jsonfield.JSONField())

    fileid = Column(BigInteger, ForeignKey('release_files.id'))
    file = relationship('ReleaseFile', backref='book_releases')

    __table_args__ = (UniqueConstraint('source_site', 'source_id'),
                      Index('book_releases_source_site_id_idx', 'source_site',
                            'source_id'))
Exemple #18
0
def downgrade():
    op.drop_table('confirm', schema=f'{get_inv()}')
    op.drop_table('trade', schema=f'{get_inv()}')
    op.create_table(
        'trade',
        sa.Column('shipping_date',
                  sa.TIMESTAMP(timezone=True),
                  nullable=True,
                  comment='When are the devices going to be ready \n    \
                                      for shipping?\n    '),
        sa.Column('invoice_number',
                  citext.CIText(),
                  nullable=True,
                  comment='The id of the invoice so they can be linked.'),
        sa.Column('price_id',
                  postgresql.UUID(as_uuid=True),
                  nullable=True,
                  comment='The price set for this trade.            \n    \
                                      If no price is set it is supposed that the trade was\n   \
                                      not payed, usual in donations.\n        '
                  ),
        sa.Column('to_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('confirms_id',
                  postgresql.UUID(as_uuid=True),
                  nullable=True,
                  comment='An organize action that this association confirms. \
                                      \n    \n    For example, a ``Sell`` or ``Rent``\n   \
                                      can confirm a ``Reserve`` action.\n    '
                  ),
        sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.ForeignKeyConstraint(
            ['confirms_id'],
            [f'{get_inv()}.organize.id'],
        ),
        sa.ForeignKeyConstraint(
            ['id'],
            [f'{get_inv()}.action.id'],
        ),
        sa.ForeignKeyConstraint(
            ['price_id'],
            [f'{get_inv()}.price.id'],
        ),
        sa.ForeignKeyConstraint(
            ['to_id'],
            [f'{get_inv()}.agent.id'],
        ),
        sa.PrimaryKeyConstraint('id'),
        schema=f'{get_inv()}')
    op.drop_column('user', 'active', schema='common')
    op.drop_column('user', 'phantom', schema='common')
Exemple #19
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'seen_netloc_tracker', sa.Column('id', sa.BigInteger(),
                                         nullable=False),
        sa.Column('netloc', citext.CIText(), nullable=False),
        sa.Column('ignore', sa.Boolean(), nullable=True),
        sa.Column('have', sa.Boolean(), nullable=True),
        sa.Column('extra',
                  postgresql.JSONB(astext_type=sa.Text()),
                  nullable=True), sa.PrimaryKeyConstraint('id'))
    op.create_index(op.f('ix_seen_netloc_tracker_netloc'),
                    'seen_netloc_tracker', ['netloc'],
                    unique=True)
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('recipe_reviews',
    sa.Column('recipe_review_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('recipe_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
    sa.Column('rating', sa.NUMERIC(), nullable=False),
    sa.Column('review', citext.CIText(), nullable=False),
    sa.Column('date_created', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['recipe_id'], ['recipes.recipe_id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.user_id'], ),
    sa.PrimaryKeyConstraint('recipe_review_id'),
    sa.UniqueConstraint('recipe_review_id')
    )
def upgrade():
    # Report Hash table
    op.create_table('report_hash',
                    sa.Column('id',
                              postgresql.UUID(as_uuid=True),
                              nullable=False),
                    sa.Column('created',
                              sa.TIMESTAMP(timezone=True),
                              server_default=sa.text('CURRENT_TIMESTAMP'),
                              nullable=False,
                              comment='When Devicehub created this.'),
                    sa.Column('hash3', citext.CIText(), nullable=False),
                    sa.PrimaryKeyConstraint('id'),
                    schema=f'{get_inv()}')
Exemple #22
0
class Files(Base):
    __tablename__ = 'db_files'
    id = Column(BigInteger, primary_key=True)

    filepath = Column(citext.CIText(), nullable=False)
    fhash = Column(Text, nullable=False)

    phash = Column(BigInteger)
    imgx = Column(Integer)
    imgy = Column(Integer)

    __table_args__ = (UniqueConstraint('filepath'), UniqueConstraint('fhash'),
                      Index('phash_bktree_idx',
                            'phash',
                            postgresql_using="spgist"))
Exemple #23
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'users',
        sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('email', citext.CIText(), nullable=False),
        sa.Column('password', citext.CIText(), nullable=False),
        sa.Column('date_created', sa.DateTime(), nullable=True),
        sa.Column('first_name', citext.CIText(), nullable=False),
        sa.Column('last_name', citext.CIText(), nullable=False),
        sa.PrimaryKeyConstraint('user_id'), sa.UniqueConstraint('email'),
        sa.UniqueConstraint('user_id'))
    op.create_table(
        'user_jwts',
        sa.Column('user_jwt_id', postgresql.UUID(as_uuid=True),
                  nullable=False),
        sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('jwt', citext.CIText(), nullable=False),
        sa.Column('date_created', sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ['user_id'],
            ['users.user_id'],
        ), sa.PrimaryKeyConstraint('user_jwt_id'),
        sa.UniqueConstraint('user_jwt_id'))
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'users_groups_roles',
        sa.Column('accepted',
                  sa.Boolean(),
                  nullable=False,
                  server_default='False'),
    )
    op.add_column('users_groups_roles',
                  sa.Column('email', citext.CIText(), nullable=False))
    op.add_column('users_groups_roles',
                  sa.Column('token', sa.String(), nullable=True))
    op.alter_column('users_groups_roles',
                    'user_id',
                    existing_type=sa.INTEGER(),
                    nullable=True)
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('db_tag_entries',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('tag_str', citext.CIText(), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('tag_str')
    )
    op.create_index(op.f('ix_db_tag_entries_tag_str'), 'db_tag_entries', ['tag_str'], unique=False)
    op.create_table('db_tags_link',
        sa.Column('series_id', sa.Integer(), nullable=False),
        sa.Column('link_weight', sa.Float(), nullable=False),
        sa.Column('tag_id', sa.Integer(), nullable=False),
        sa.Column('changeuser', sa.Integer(), nullable=True),
        sa.Column('changetime', sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(['changeuser'], ['users.id'], ),
        sa.ForeignKeyConstraint(['series_id'], ['series.id'], ),
        sa.ForeignKeyConstraint(['tag_id'], ['db_tag_entries.id'], ),
        sa.PrimaryKeyConstraint('series_id', 'tag_id'),
        sa.UniqueConstraint('series_id', 'tag_id')
    )
    op.create_index(op.f('ix_db_tags_link_changetime'), 'db_tags_link', ['changetime'], unique=False)
    op.create_index(op.f('ix_db_tags_link_changeuser'), 'db_tags_link', ['changeuser'], unique=False)
    op.create_table('db_tags_link_changes',
        sa.Column('srccol', sa.Integer(), nullable=False),
        sa.Column('series_id', sa.Integer(), nullable=False),
        sa.Column('link_weight', sa.Float(), nullable=False),
        sa.Column('tag_id', sa.Integer(), nullable=False),
        sa.Column('changeuser', sa.Integer(), nullable=False),
        sa.Column('changetime', sa.DateTime(), nullable=False),
        sa.Column('operation', sa.Text(), nullable=False),
        sa.ForeignKeyConstraint(['changeuser'], ['users.id'], ),
        sa.ForeignKeyConstraint(['series_id'], ['series.id'], ),
        sa.ForeignKeyConstraint(['srccol'], ['series.id'], ondelete='SET NULL'),
        sa.ForeignKeyConstraint(['tag_id'], ['db_tag_entries.id'], ),
        sa.PrimaryKeyConstraint('series_id', 'tag_id', 'srccol', 'operation', 'changetime', 'changeuser')
    )
    op.create_index(op.f('ix_db_tags_link_changes_changetime'), 'db_tags_link_changes', ['changetime'], unique=False)
    op.create_index(op.f('ix_db_tags_link_changes_changeuser'), 'db_tags_link_changes', ['changeuser'], unique=False)
Exemple #26
0
def upgrade():
    op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}')
    op.alter_column('deliverynote',
                    'deposit',
                    new_column_name='amount',
                    schema=f'{get_inv()}')
    op.alter_column('computer',
                    'deposit',
                    new_column_name='amount',
                    schema=f'{get_inv()}')
    op.alter_column('lot',
                    'deposit',
                    new_column_name='amount',
                    schema=f'{get_inv()}')
    op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}')
    op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}')
    op.drop_column('computer', 'ethereum_address', schema=f'{get_inv()}')
    op.drop_column('lot', 'receiver_address', schema=f'{get_inv()}')
    op.add_column('lot',
                  sa.Column('receiver_address',
                            citext.CIText(),
                            sa.ForeignKey('common.user.email'),
                            nullable=True),
                  schema=f'{get_inv()}')

    op.drop_column('user', 'ethereum_address', schema='common')

    op.drop_table('proof_function', schema=f'{get_inv()}')
    op.drop_table('proof_data_wipe', schema=f'{get_inv()}')
    op.drop_table('proof_transfer', schema=f'{get_inv()}')
    op.drop_table('proof_reuse', schema=f'{get_inv()}')
    op.drop_table('proof_recycling', schema=f'{get_inv()}')
    op.drop_index(op.f('ix_proof_updated'),
                  table_name='proof',
                  schema=f'{get_inv()}')
    op.drop_index(op.f('ix_proof_created'),
                  table_name='proof',
                  schema=f'{get_inv()}')
    op.drop_table('proof', schema=f'{get_inv()}')
Exemple #27
0
def upgrade():
    op.execute("CREATE EXTENSION IF NOT EXISTS citext")

    op.create_table(
        "openid_discovered",
        sa.Column("url", sa.Text(), nullable=False),
        sa.Column("created", sa.DateTime(), nullable=True),
        sa.Column("services", sa.LargeBinary(), nullable=True),
        sa.Column("op_endpoint", sa.Text(), nullable=True),
        sa.Column("op_local", sa.Text(), nullable=True),
        sa.PrimaryKeyConstraint("url"),
    )

    op.create_table(
        "accounts_user",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("password", sa.String(length=128), nullable=False),
        sa.Column("last_login", sa.DateTime(), nullable=False),
        sa.Column("is_superuser", sa.Boolean(), nullable=False),
        sa.Column("username", citext.CIText(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("is_staff", sa.Boolean(), nullable=False),
        sa.Column("is_active", sa.Boolean(), nullable=False),
        sa.Column("date_joined",
                  sa.DateTime(),
                  server_default=sa.text("now()"),
                  nullable=True),
        sa.CheckConstraint(
            "username ~* '^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$'",
            name="accounts_user_valid_username",
        ),
        sa.CheckConstraint("length(username) <= 50",
                           name="packages_valid_name"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("username"),
    )

    op.create_table(
        "packages",
        sa.Column("name", sa.Text(), nullable=False),
        sa.Column("stable_version", sa.Text(), nullable=True),
        sa.Column("normalized_name", sa.Text(), nullable=True),
        sa.Column("autohide",
                  sa.Boolean(),
                  server_default=sa.text("true"),
                  nullable=True),
        sa.Column("comments",
                  sa.Boolean(),
                  server_default=sa.text("true"),
                  nullable=True),
        sa.Column("bugtrack_url", sa.Text(), nullable=True),
        sa.Column("hosting_mode",
                  sa.Text(),
                  server_default="pypi-explicit",
                  nullable=False),
        sa.Column("created",
                  sa.DateTime(),
                  server_default=sa.text("now()"),
                  nullable=False),
        sa.CheckConstraint(
            "name ~* '^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$'::text",
            name="packages_valid_name",
        ),
        sa.PrimaryKeyConstraint("name"),
    )

    op.create_table("dual", sa.Column("dummy", sa.Integer(), nullable=True))

    op.create_table(
        "cheesecake_main_indices",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("absolute", sa.Integer(), nullable=False),
        sa.Column("relative", sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )

    op.create_table(
        "trove_classifiers",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("classifier", sa.Text(), nullable=True),
        sa.Column("l2", sa.Integer(), nullable=True),
        sa.Column("l3", sa.Integer(), nullable=True),
        sa.Column("l4", sa.Integer(), nullable=True),
        sa.Column("l5", sa.Integer(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("classifier",
                            name="trove_classifiers_classifier_key"),
    )

    op.create_index("trove_class_class_idx",
                    "trove_classifiers", ["classifier"],
                    unique=False)

    op.create_index("trove_class_id_idx",
                    "trove_classifiers", ["id"],
                    unique=False)

    op.create_table(
        "browse_tally",
        sa.Column("trove_id", sa.Integer(), nullable=False),
        sa.Column("tally", sa.Integer(), nullable=True),
        sa.PrimaryKeyConstraint("trove_id"),
    )

    op.create_table(
        "timestamps",
        sa.Column("name", sa.Text(), nullable=False),
        sa.Column("value", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("name"),
    )

    op.create_table(
        "oauth_nonce",
        sa.Column("timestamp", sa.Integer(), nullable=False),
        sa.Column("consumer", sa.String(length=32), nullable=False),
        sa.Column("nonce", sa.String(length=32), nullable=False),
        sa.Column("token", sa.String(length=32), nullable=True),
    )

    op.create_table(
        "oid_associations",
        sa.Column("server_url", sa.String(length=2047), nullable=False),
        sa.Column("handle", sa.String(length=255), nullable=False),
        sa.Column("secret", sa.LargeBinary(length=128), nullable=False),
        sa.Column("issued", sa.Integer(), nullable=False),
        sa.Column("lifetime", sa.Integer(), nullable=False),
        sa.Column("assoc_type", sa.String(length=64), nullable=False),
        sa.CheckConstraint("length(secret) <= 128",
                           name="secret_length_constraint"),
        sa.PrimaryKeyConstraint("server_url", "handle"),
    )

    op.create_table(
        "oid_nonces",
        sa.Column("server_url", sa.String(length=2047), nullable=False),
        sa.Column("timestamp", sa.Integer(), nullable=False),
        sa.Column("salt", sa.String(length=40), nullable=False),
        sa.PrimaryKeyConstraint("server_url", "timestamp", "salt"),
    )

    op.create_table(
        "openid_sessions",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("url", sa.Text(), nullable=True),
        sa.Column("assoc_handle", sa.Text(), nullable=True),
        sa.Column("expires", sa.DateTime(), nullable=True),
        sa.Column("mac_key", sa.Text(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )

    op.create_table(
        "openid_nonces",
        sa.Column("created", sa.DateTime(), nullable=True),
        sa.Column("nonce", sa.Text(), nullable=True),
    )

    op.create_index("openid_nonces_created",
                    "openid_nonces", ["created"],
                    unique=False)

    op.create_index("openid_nonces_nonce",
                    "openid_nonces", ["nonce"],
                    unique=False)

    op.create_table(
        "file_registry",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("filename", sa.Text(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("filename", name="file_registry_filename_key"),
    )

    op.create_table(
        "openid_whitelist",
        sa.Column("name", sa.Text(), nullable=False),
        sa.Column("trust_root", sa.Text(), nullable=False),
        sa.Column("created", sa.DateTime(), nullable=True),
        sa.PrimaryKeyConstraint("name", "trust_root"),
    )

    op.create_table(
        "releases",
        sa.Column("name", sa.Text(), nullable=False),
        sa.Column("version", sa.Text(), nullable=False),
        sa.Column("author", sa.Text(), nullable=True),
        sa.Column("author_email", sa.Text(), nullable=True),
        sa.Column("maintainer", sa.Text(), nullable=True),
        sa.Column("maintainer_email", sa.Text(), nullable=True),
        sa.Column("home_page", sa.Text(), nullable=True),
        sa.Column("license", sa.Text(), nullable=True),
        sa.Column("summary", sa.Text(), nullable=True),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("keywords", sa.Text(), nullable=True),
        sa.Column("platform", sa.Text(), nullable=True),
        sa.Column("download_url", sa.Text(), nullable=True),
        sa.Column("_pypi_ordering", sa.Integer(), nullable=True),
        sa.Column("_pypi_hidden", sa.Boolean(), nullable=True),
        sa.Column("description_html", sa.Text(), nullable=True),
        sa.Column("cheesecake_installability_id", sa.Integer(), nullable=True),
        sa.Column("cheesecake_documentation_id", sa.Integer(), nullable=True),
        sa.Column("cheesecake_code_kwalitee_id", sa.Integer(), nullable=True),
        sa.Column("requires_python", sa.Text(), nullable=True),
        sa.Column("description_from_readme", sa.Boolean(), nullable=True),
        sa.Column("created",
                  sa.DateTime(),
                  server_default=sa.text("now()"),
                  nullable=False),
        sa.ForeignKeyConstraint(["cheesecake_code_kwalitee_id"],
                                ["cheesecake_main_indices.id"]),
        sa.ForeignKeyConstraint(["cheesecake_documentation_id"],
                                ["cheesecake_main_indices.id"]),
        sa.ForeignKeyConstraint(["cheesecake_installability_id"],
                                ["cheesecake_main_indices.id"]),
        sa.ForeignKeyConstraint(["name"], ["packages.name"],
                                onupdate="CASCADE"),
        sa.PrimaryKeyConstraint("name", "version"),
    )

    op.create_index(
        "release_name_created_idx",
        "releases",
        ["name", sa.text("created DESC")],
        unique=False,
    )

    op.create_index("release_name_idx", "releases", ["name"], unique=False)

    op.create_index("release_pypi_hidden_idx",
                    "releases", ["_pypi_hidden"],
                    unique=False)

    op.create_index("release_version_idx",
                    "releases", ["version"],
                    unique=False)

    op.create_table(
        "mirrors",
        sa.Column("ip", sa.Text(), nullable=False),
        sa.Column("user_name", citext.CIText(), nullable=True),
        sa.Column("index_url", sa.Text(), nullable=True),
        sa.Column("last_modified_url", sa.Text(), nullable=True),
        sa.Column("local_stats_url", sa.Text(), nullable=True),
        sa.Column("stats_url", sa.Text(), nullable=True),
        sa.Column("mirrors_url", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(["user_name"], ["accounts_user.username"]),
        sa.PrimaryKeyConstraint("ip"),
    )

    op.create_table(
        "oauth_consumers",
        sa.Column("consumer", sa.String(length=32), nullable=False),
        sa.Column("secret", sa.String(length=64), nullable=False),
        sa.Column("date_created", sa.Date(), nullable=False),
        sa.Column("created_by", citext.CIText(), nullable=True),
        sa.Column("last_modified", sa.Date(), nullable=False),
        sa.Column("description", sa.String(length=255), nullable=False),
        sa.ForeignKeyConstraint(["created_by"], ["accounts_user.username"],
                                onupdate="CASCADE"),
        sa.PrimaryKeyConstraint("consumer"),
    )

    op.create_table(
        "accounts_email",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("email", sa.String(length=254), nullable=False),
        sa.Column("primary", sa.Boolean(), nullable=False),
        sa.Column("verified", sa.Boolean(), nullable=False),
        sa.ForeignKeyConstraint(["user_id"], ["accounts_user.id"],
                                initially="DEFERRED",
                                deferrable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("email", name="accounts_email_email_key"),
    )

    op.create_index("accounts_email_email_like",
                    "accounts_email", ["email"],
                    unique=False)

    op.create_index("accounts_email_user_id",
                    "accounts_email", ["user_id"],
                    unique=False)

    op.create_table(
        "oauth_access_tokens",
        sa.Column("token", sa.String(length=32), nullable=False),
        sa.Column("secret", sa.String(length=64), nullable=False),
        sa.Column("consumer", sa.String(length=32), nullable=False),
        sa.Column("date_created", sa.Date(), nullable=False),
        sa.Column("last_modified", sa.Date(), nullable=False),
        sa.Column("user_name", citext.CIText(), nullable=True),
        sa.ForeignKeyConstraint(
            ["user_name"],
            ["accounts_user.username"],
            onupdate="CASCADE",
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("token"),
    )

    op.create_table(
        "csrf_tokens",
        sa.Column("name", citext.CIText(), nullable=False),
        sa.Column("token", sa.Text(), nullable=True),
        sa.Column("end_date", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(["name"], ["accounts_user.username"],
                                onupdate="CASCADE",
                                ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("name"),
    )

    op.create_table(
        "oauth_request_tokens",
        sa.Column("token", sa.String(length=32), nullable=False),
        sa.Column("secret", sa.String(length=64), nullable=False),
        sa.Column("consumer", sa.String(length=32), nullable=False),
        sa.Column("callback", sa.Text(), nullable=True),
        sa.Column("date_created", sa.Date(), nullable=False),
        sa.Column("user_name", citext.CIText(), nullable=True),
        sa.ForeignKeyConstraint(
            ["user_name"],
            ["accounts_user.username"],
            onupdate="CASCADE",
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("token"),
    )

    op.create_table(
        "cookies",
        sa.Column("cookie", sa.Text(), nullable=False),
        sa.Column("name", citext.CIText(), nullable=True),
        sa.Column("last_seen", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(["name"], ["accounts_user.username"],
                                onupdate="CASCADE",
                                ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("cookie"),
    )

    op.create_index("cookies_last_seen",
                    "cookies", ["last_seen"],
                    unique=False)

    op.create_table(
        "openids",
        sa.Column("id", sa.Text(), nullable=False),
        sa.Column("name", citext.CIText(), nullable=True),
        sa.ForeignKeyConstraint(["name"], ["accounts_user.username"],
                                onupdate="CASCADE",
                                ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )

    op.create_table(
        "sshkeys",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", citext.CIText(), nullable=True),
        sa.Column("key", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(["name"], ["accounts_user.username"],
                                onupdate="CASCADE",
                                ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )

    op.create_index("sshkeys_name", "sshkeys", ["name"], unique=False)

    op.create_table(
        "rego_otk",
        sa.Column("name", citext.CIText(), nullable=True),
        sa.Column("otk", sa.Text(), nullable=True),
        sa.Column("date", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(["name"], ["accounts_user.username"],
                                ondelete="CASCADE"),
        sa.UniqueConstraint("otk", name="rego_otk_unique"),
    )

    op.create_index("rego_otk_name_idx", "rego_otk", ["name"], unique=False)

    op.create_index("rego_otk_otk_idx", "rego_otk", ["otk"], unique=False)

    op.create_table(
        "cheesecake_subindices",
        sa.Column("main_index_id", sa.Integer(), nullable=False),
        sa.Column("name", sa.Text(), nullable=False),
        sa.Column("value", sa.Integer(), nullable=False),
        sa.Column("details", sa.Text(), nullable=False),
        sa.ForeignKeyConstraint(["main_index_id"],
                                ["cheesecake_main_indices.id"]),
        sa.PrimaryKeyConstraint("main_index_id", "name"),
    )

    op.create_table(
        "accounts_gpgkey",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("key_id", citext.CIText(), nullable=False),
        sa.Column("verified", sa.Boolean(), nullable=False),
        sa.CheckConstraint("key_id ~* '^[A-F0-9]{8}$'::citext",
                           name="accounts_gpgkey_valid_key_id"),
        sa.ForeignKeyConstraint(["user_id"], ["accounts_user.id"],
                                initially="DEFERRED",
                                deferrable=True),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("key_id", name="accounts_gpgkey_key_id_key"),
    )

    op.create_index("accounts_gpgkey_user_id",
                    "accounts_gpgkey", ["user_id"],
                    unique=False)

    op.create_table(
        "roles",
        sa.Column("role_name", sa.Text(), nullable=True),
        sa.Column("user_name", citext.CIText(), nullable=True),
        sa.Column("package_name", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(["package_name"], ["packages.name"],
                                onupdate="CASCADE"),
        sa.ForeignKeyConstraint(["user_name"], ["accounts_user.username"],
                                onupdate="CASCADE"),
    )

    op.create_index("roles_pack_name_idx",
                    "roles", ["package_name"],
                    unique=False)

    op.create_index("roles_user_name_idx",
                    "roles", ["user_name"],
                    unique=False)

    op.create_table(
        "journals",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.Text(), nullable=True),
        sa.Column("version", sa.Text(), nullable=True),
        sa.Column("action", sa.Text(), nullable=True),
        sa.Column("submitted_date", sa.DateTime(), nullable=True),
        sa.Column("submitted_by", citext.CIText(), nullable=True),
        sa.Column("submitted_from", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(["submitted_by"], ["accounts_user.username"],
                                onupdate="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )

    op.create_index(
        "journals_changelog",
        "journals",
        ["submitted_date", "name", "version", "action"],
        unique=False,
    )

    op.create_index("journals_id_idx", "journals", ["id"], unique=False)

    op.create_index(
        "journals_latest_releases",
        "journals",
        ["submitted_date", "name", "version"],
        unique=False,
        postgresql_where=sa.text(
            "journals.version IS NOT NULL AND journals.action = 'new release'"
        ),
    )

    op.create_index("journals_name_idx", "journals", ["name"], unique=False)

    op.create_index("journals_version_idx",
                    "journals", ["version"],
                    unique=False)

    op.create_table(
        "ratings",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.Text(), nullable=False),
        sa.Column("version", sa.Text(), nullable=False),
        sa.Column("user_name", citext.CIText(), nullable=False),
        sa.Column("date", sa.DateTime(), nullable=True),
        sa.Column("rating", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["name", "version"],
            ["releases.name", "releases.version"],
            onupdate="CASCADE",
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(["user_name"], ["accounts_user.username"],
                                ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name",
                            "version",
                            "user_name",
                            name="ratings_name_key"),
    )

    op.create_index("rating_name_version",
                    "ratings", ["name", "version"],
                    unique=False)

    op.create_table(
        "release_classifiers",
        sa.Column("name", sa.Text(), nullable=True),
        sa.Column("version", sa.Text(), nullable=True),
        sa.Column("trove_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["name", "version"],
            ["releases.name", "releases.version"],
            onupdate="CASCADE",
        ),
        sa.ForeignKeyConstraint(["trove_id"], ["trove_classifiers.id"]),
    )

    op.create_index("rel_class_name_idx",
                    "release_classifiers", ["name"],
                    unique=False)

    op.create_index(
        "rel_class_name_version_idx",
        "release_classifiers",
        ["name", "version"],
        unique=False,
    )

    op.create_index("rel_class_trove_id_idx",
                    "release_classifiers", ["trove_id"],
                    unique=False)

    op.create_index("rel_class_version_id_idx",
                    "release_classifiers", ["version"],
                    unique=False)

    op.create_table(
        "release_urls",
        sa.Column("name", sa.Text(), nullable=True),
        sa.Column("version", sa.Text(), nullable=True),
        sa.Column("url", sa.Text(), nullable=True),
        sa.Column("packagetype", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ["name", "version"],
            ["releases.name", "releases.version"],
            onupdate="CASCADE",
        ),
    )

    op.create_index("release_urls_name_idx",
                    "release_urls", ["name"],
                    unique=False)

    op.create_index("release_urls_packagetype_idx",
                    "release_urls", ["packagetype"],
                    unique=False)

    op.create_index("release_urls_version_idx",
                    "release_urls", ["version"],
                    unique=False)

    op.create_table(
        "release_dependencies",
        sa.Column("name", sa.Text(), nullable=True),
        sa.Column("version", sa.Text(), nullable=True),
        sa.Column("kind", sa.Integer(), nullable=True),
        sa.Column("specifier", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ["name", "version"],
            ["releases.name", "releases.version"],
            onupdate="CASCADE",
        ),
    )

    op.create_index("rel_dep_name_idx",
                    "release_dependencies", ["name"],
                    unique=False)

    op.create_index(
        "rel_dep_name_version_idx",
        "release_dependencies",
        ["name", "version"],
        unique=False,
    )

    op.create_index(
        "rel_dep_name_version_kind_idx",
        "release_dependencies",
        ["name", "version", "kind"],
        unique=False,
    )

    op.create_table(
        "comments_journal",
        sa.Column("name", sa.Text(), nullable=True),
        sa.Column("version", sa.Text(), nullable=True),
        sa.Column("id", sa.Integer(), nullable=True),
        sa.Column("submitted_by", citext.CIText(), nullable=True),
        sa.Column("date", sa.DateTime(), nullable=True),
        sa.Column("action", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ["name", "version"],
            ["releases.name", "releases.version"],
            onupdate="CASCADE",
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(["submitted_by"], ["accounts_user.username"],
                                ondelete="CASCADE"),
    )

    op.create_table(
        "release_files",
        sa.Column("name", sa.Text(), nullable=True),
        sa.Column("version", sa.Text(), nullable=True),
        sa.Column("python_version", sa.Text(), nullable=True),
        sa.Column("packagetype", sa.Text(), nullable=True),
        sa.Column("comment_text", sa.Text(), nullable=True),
        sa.Column("filename", sa.Text(), nullable=True),
        sa.Column("md5_digest", sa.Text(), nullable=True),
        sa.Column("downloads",
                  sa.Integer(),
                  server_default=sa.text("0"),
                  nullable=True),
        sa.Column("upload_time", sa.DateTime(), nullable=True),
        sa.ForeignKeyConstraint(
            ["name", "version"],
            ["releases.name", "releases.version"],
            onupdate="CASCADE",
        ),
        sa.UniqueConstraint("filename", name="release_files_filename_key"),
        sa.UniqueConstraint("md5_digest", name="release_files_md5_digest_key"),
    )

    op.create_index("release_files_name_idx",
                    "release_files", ["name"],
                    unique=False)

    op.create_index(
        "release_files_name_version_idx",
        "release_files",
        ["name", "version"],
        unique=False,
    )

    op.create_index("release_files_packagetype_idx",
                    "release_files", ["packagetype"],
                    unique=False)

    op.create_index("release_files_version_idx",
                    "release_files", ["version"],
                    unique=False)

    op.create_table(
        "release_requires_python",
        sa.Column("name", sa.Text(), nullable=True),
        sa.Column("version", sa.Text(), nullable=True),
        sa.Column("specifier", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ["name", "version"],
            ["releases.name", "releases.version"],
            onupdate="CASCADE",
        ),
    )

    op.create_index("rel_req_python_name_idx",
                    "release_requires_python", ["name"],
                    unique=False)

    op.create_index(
        "rel_req_python_name_version_idx",
        "release_requires_python",
        ["name", "version"],
        unique=False,
    )

    op.create_index(
        "rel_req_python_version_id_idx",
        "release_requires_python",
        ["version"],
        unique=False,
    )

    op.create_table(
        "description_urls",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.Text(), nullable=True),
        sa.Column("version", sa.Text(), nullable=True),
        sa.Column("url", sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ["name", "version"],
            ["releases.name", "releases.version"],
            onupdate="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id"),
    )

    op.create_index("description_urls_name_idx",
                    "description_urls", ["name"],
                    unique=False)

    op.create_index(
        "description_urls_name_version_idx",
        "description_urls",
        ["name", "version"],
        unique=False,
    )

    op.create_table(
        "comments",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("rating", sa.Integer(), nullable=True),
        sa.Column("user_name", citext.CIText(), nullable=True),
        sa.Column("date", sa.DateTime(), nullable=True),
        sa.Column("message", sa.Text(), nullable=True),
        sa.Column("in_reply_to", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["in_reply_to"], ["comments.id"],
                                ondelete="CASCADE"),
        sa.ForeignKeyConstraint(["rating"], ["ratings.id"],
                                ondelete="CASCADE"),
        sa.ForeignKeyConstraint(["user_name"], ["accounts_user.username"],
                                ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )

    op.execute(""" CREATE INDEX releases_name_ts_idx
            ON releases
            USING gin
            (to_tsvector('english'::regconfig, name))
        """)

    op.execute(""" CREATE INDEX releases_summary_ts_idx
            ON releases
            USING gin
            (to_tsvector('english'::regconfig, summary));
        """)
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'transaction', sa.Column('issued_at', sa.DateTime(), nullable=True),
        sa.Column('id', sa.BigInteger(), nullable=False),
        sa.Column('remote_addr', sa.String(length=50), nullable=True),
        sa.PrimaryKeyConstraint('id'))
    op.create_table(
        'web_pages_version',
        sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
        sa.Column('state',
                  postgresql.ENUM('new',
                                  'fetching',
                                  'processing',
                                  'complete',
                                  'error',
                                  'removed',
                                  name='dlstate_enum',
                                  create_type=False),
                  autoincrement=False,
                  nullable=True),
        sa.Column('errno', sa.Integer(), autoincrement=False, nullable=True),
        sa.Column('url', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('starturl', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('netloc', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('file', sa.Integer(), autoincrement=False, nullable=True),
        sa.Column('priority', sa.Integer(), autoincrement=False,
                  nullable=True),
        sa.Column('distance', sa.Integer(), autoincrement=False,
                  nullable=True),
        sa.Column('is_text', sa.Boolean(), autoincrement=False, nullable=True),
        sa.Column('limit_netloc',
                  sa.Boolean(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('title', citext.CIText(), autoincrement=False,
                  nullable=True),
        sa.Column('mimetype', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('type',
                  postgresql.ENUM('western',
                                  'eastern',
                                  'unknown',
                                  name='itemtype_enum',
                                  create_type=False),
                  autoincrement=False,
                  nullable=True),
        sa.Column('content', sa.Text(), autoincrement=False, nullable=True),
        sa.Column('fetchtime',
                  sa.DateTime(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('addtime', sa.DateTime(), autoincrement=False,
                  nullable=True),
        sa.Column('ignoreuntiltime',
                  sa.DateTime(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('normal_fetch_mode',
                  sa.Boolean(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('tsv_content',
                  sqlalchemy_utils.types.ts_vector.TSVectorType(),
                  autoincrement=False,
                  nullable=True),
        sa.Column('transaction_id',
                  sa.BigInteger(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('end_transaction_id', sa.BigInteger(), nullable=True),
        sa.Column('operation_type', sa.SmallInteger(), nullable=False),
        sa.PrimaryKeyConstraint('id', 'transaction_id'))
    # op.create_index(op.f('ix_web_pages_version_distance'), 'web_pages_version', ['distance'], unique=False)
    # op.create_index(op.f('ix_web_pages_version_ignoreuntiltime'), 'web_pages_version', ['ignoreuntiltime'], unique=False)
    # op.create_index(op.f('ix_web_pages_version_netloc'), 'web_pages_version', ['netloc'], unique=False)
    # op.create_index(op.f('ix_web_pages_version_priority'), 'web_pages_version', ['priority'], unique=False)
    # op.create_index(op.f('ix_web_pages_version_state'), 'web_pages_version', ['state'], unique=False)
    # op.create_index('ix_web_pages_version_tsv_content', 'web_pages_version', ['tsv_content'], unique=False, postgresql_using='gin')
    # op.create_index(op.f('ix_web_pages_version_type'), 'web_pages_version', ['type'], unique=False)

    op.create_index(op.f('ix_web_pages_version_id'),
                    'web_pages_version', ['id'],
                    unique=False)
    op.create_index(op.f('ix_web_pages_version_operation_type'),
                    'web_pages_version', ['operation_type'],
                    unique=False)
    op.create_index(op.f('ix_web_pages_version_transaction_id'),
                    'web_pages_version', ['transaction_id'],
                    unique=False)
    op.create_index(op.f('ix_web_pages_version_end_transaction_id'),
                    'web_pages_version', ['end_transaction_id'],
                    unique=False)
    op.create_index(op.f('ix_web_pages_version_url'),
                    'web_pages_version', ['url'],
                    unique=False)
Exemple #29
0
 def get_column_type(self):
     return citext.CIText(**self.sa_type_kwargs)
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('hentai_tags', sa.Column('id',
                                             sa.Integer(),
                                             nullable=False),
                    sa.Column('tag', citext.CIText(), nullable=False),
                    sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('tag'))
    op.create_index(op.f('ix_hentai_tags_tag'),
                    'hentai_tags', ['tag'],
                    unique=False)
    op.create_table('manga_tags', sa.Column('id', sa.Integer(),
                                            nullable=False),
                    sa.Column('tag', citext.CIText(), nullable=False),
                    sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('tag'))
    op.create_index(op.f('ix_manga_tags_tag'),
                    'manga_tags', ['tag'],
                    unique=False)
    op.create_table(
        'release_files', sa.Column('id', sa.BigInteger(), nullable=False),
        sa.Column('dirpath', sa.Text(), nullable=False),
        sa.Column('filename', sa.Text(), nullable=False),
        sa.Column('fhash', sa.Text(), nullable=False),
        sa.Column('file_type',
                  postgresql.ENUM('manga',
                                  'hentai',
                                  'unknown',
                                  name='filetype_enum'),
                  nullable=False),
        sa.Column('was_duplicate', sa.Boolean(), nullable=False),
        sa.Column('last_dup_check', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('dirpath', 'filename'),
        sa.UniqueConstraint('fhash'))
    op.create_table(
        'hentai_releases', sa.Column('id', sa.BigInteger(), nullable=False),
        sa.Column('state',
                  postgresql.ENUM('new',
                                  'fetching',
                                  'processing',
                                  'complete',
                                  'error',
                                  'removed',
                                  'disabled',
                                  'upload',
                                  'missing',
                                  name='dlstate_enum'),
                  nullable=False),
        sa.Column('err_str', sa.Text(), nullable=True),
        sa.Column('source_site', sa.Text(), nullable=False),
        sa.Column('source_id', sa.Text(), nullable=False),
        sa.Column('posted_at', sa.DateTime(), nullable=False),
        sa.Column('downloaded_at', sa.DateTime(), nullable=False),
        sa.Column('last_checked', sa.DateTime(), nullable=False),
        sa.Column('was_duplicate', sa.Boolean(), nullable=False),
        sa.Column('phash_duplicate', sa.Boolean(), nullable=False),
        sa.Column('uploaded', sa.Boolean(), nullable=False),
        sa.Column('dirstate',
                  postgresql.ENUM('had_dir',
                                  'created_dir',
                                  'unknown',
                                  name='dirtype_enum'),
                  nullable=False),
        sa.Column('origin_name', sa.Text(), nullable=True),
        sa.Column('additional_metadata',
                  sqlalchemy_jsonfield.jsonfield.JSONField(),
                  nullable=True),
        sa.Column('fileid', sa.BigInteger(), nullable=True),
        sa.ForeignKeyConstraint(
            ['fileid'],
            ['release_files.id'],
        ), sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('source_site', 'source_id'))
    op.create_index('hentai_releases_source_site_id_idx',
                    'hentai_releases', ['source_site', 'source_id'],
                    unique=False)
    op.create_index(op.f('ix_hentai_releases_source_id'),
                    'hentai_releases', ['source_id'],
                    unique=False)
    op.create_index(op.f('ix_hentai_releases_source_site'),
                    'hentai_releases', ['source_site'],
                    unique=False)
    op.create_index(op.f('ix_hentai_releases_state'),
                    'hentai_releases', ['state'],
                    unique=False)
    op.create_table(
        'hentai_tags_link',
        sa.Column('releases_id', sa.Integer(), nullable=False),
        sa.Column('tags_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['releases_id'],
            ['release_files.id'],
        ), sa.ForeignKeyConstraint(
            ['tags_id'],
            ['hentai_tags.id'],
        ), sa.PrimaryKeyConstraint('releases_id', 'tags_id'))
    op.create_table(
        'manga_releases', sa.Column('id', sa.BigInteger(), nullable=False),
        sa.Column('state',
                  postgresql.ENUM('new',
                                  'fetching',
                                  'processing',
                                  'complete',
                                  'error',
                                  'removed',
                                  'disabled',
                                  'upload',
                                  'missing',
                                  name='dlstate_enum'),
                  nullable=False),
        sa.Column('err_str', sa.Text(), nullable=True),
        sa.Column('source_site', sa.Text(), nullable=False),
        sa.Column('source_id', sa.Text(), nullable=False),
        sa.Column('posted_at', sa.DateTime(), nullable=False),
        sa.Column('downloaded_at', sa.DateTime(), nullable=False),
        sa.Column('last_checked', sa.DateTime(), nullable=False),
        sa.Column('was_duplicate', sa.Boolean(), nullable=False),
        sa.Column('phash_duplicate', sa.Boolean(), nullable=False),
        sa.Column('uploaded', sa.Boolean(), nullable=False),
        sa.Column('dirstate',
                  postgresql.ENUM('had_dir',
                                  'created_dir',
                                  'unknown',
                                  name='dirtype_enum'),
                  nullable=False),
        sa.Column('origin_name', sa.Text(), nullable=True),
        sa.Column('additional_metadata',
                  sqlalchemy_jsonfield.jsonfield.JSONField(),
                  nullable=True),
        sa.Column('fileid', sa.BigInteger(), nullable=True),
        sa.ForeignKeyConstraint(
            ['fileid'],
            ['release_files.id'],
        ), sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('source_site', 'source_id'))
    op.create_index(op.f('ix_manga_releases_source_id'),
                    'manga_releases', ['source_id'],
                    unique=False)
    op.create_index(op.f('ix_manga_releases_source_site'),
                    'manga_releases', ['source_site'],
                    unique=False)
    op.create_index(op.f('ix_manga_releases_state'),
                    'manga_releases', ['state'],
                    unique=False)
    op.create_index('manga_releases_source_site_id_idx',
                    'manga_releases', ['source_site', 'source_id'],
                    unique=False)
    op.create_table(
        'manga_tags_link',
        sa.Column('releases_id', sa.Integer(), nullable=False),
        sa.Column('tags_id', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['releases_id'],
            ['release_files.id'],
        ), sa.ForeignKeyConstraint(
            ['tags_id'],
            ['manga_tags.id'],
        ), sa.PrimaryKeyConstraint('releases_id', 'tags_id'))