diff --git a/data/database.py b/data/database.py index c8fbc27ea..ffea9aadd 100644 --- a/data/database.py +++ b/data/database.py @@ -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, diff --git a/data/migrations/versions/23ca04d0bc8e_add_the_torrentinfo_table_and_torrent_.py b/data/migrations/versions/23ca04d0bc8e_add_the_torrentinfo_table_and_torrent_.py new file mode 100644 index 000000000..1e16f9838 --- /dev/null +++ b/data/migrations/versions/23ca04d0bc8e_add_the_torrentinfo_table_and_torrent_.py @@ -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 ### diff --git a/test/data/test.db b/test/data/test.db index 16a8c3581..e26e28a9b 100644 Binary files a/test/data/test.db and b/test/data/test.db differ