Fix the db definition for torrentinfo and add migration

This commit is contained in:
Jake Moshenko 2016-01-06 13:52:27 -05:00
parent 476ac8cec9
commit 77aa58996a
3 changed files with 45 additions and 3 deletions

View file

@ -853,9 +853,13 @@ class TorrentInfo(BaseModel):
piece_length = IntegerField()
pieces = Base64BinaryField()
indexes = (
(('storage', 'piece_length'), True),
)
class Meta:
database = db
read_slaves = (read_slave,)
indexes = (
# we may want to compute the piece hashes multiple times with different piece lengths
(('storage', 'piece_length'), True),
)
all_models = [User, Repository, Image, AccessToken, Role, RepositoryPermission, Visibility,

View file

@ -0,0 +1,38 @@
"""Add the torrentinfo table and torrent fields on blobuploads.
Revision ID: 23ca04d0bc8e
Revises: 471caec2cb66
Create Date: 2016-01-06 13:25:24.597037
"""
# revision identifiers, used by Alembic.
revision = '23ca04d0bc8e'
down_revision = '471caec2cb66'
from alembic import op
import sqlalchemy as sa
def upgrade(tables):
### commands auto generated by Alembic - please adjust! ###
op.create_table('torrentinfo',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('storage_id', sa.Integer(), nullable=False),
sa.Column('piece_length', sa.Integer(), nullable=False),
sa.Column('pieces', sa.Text(), nullable=False),
sa.ForeignKeyConstraint(['storage_id'], ['imagestorage.id'], name=op.f('fk_torrentinfo_storage_id_imagestorage')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_torrentinfo'))
)
op.create_index('torrentinfo_storage_id', 'torrentinfo', ['storage_id'], unique=False)
op.create_index('torrentinfo_storage_id_piece_length', 'torrentinfo', ['storage_id', 'piece_length'], unique=True)
op.add_column(u'blobupload', sa.Column('piece_hashes', sa.Text(), nullable=False))
op.add_column(u'blobupload', sa.Column('piece_sha_state', sa.Text(), nullable=True))
### end Alembic commands ###
def downgrade(tables):
### commands auto generated by Alembic - please adjust! ###
op.drop_column(u'blobupload', 'piece_sha_state')
op.drop_column(u'blobupload', 'piece_hashes')
op.drop_table('torrentinfo')
### end Alembic commands ###

Binary file not shown.