2021-12-16 13:41:49 +00:00
|
|
|
"""Move files to filesystem
|
|
|
|
|
|
|
|
Revision ID: 7225d990740e
|
|
|
|
Revises: 44dd9397c555
|
|
|
|
Create Date: 2021-12-14 10:52:50.785342
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
import sqlalchemy as sa
|
2021-12-16 19:22:37 +00:00
|
|
|
from crc import app, session
|
|
|
|
from crc.models.file import FileModel
|
|
|
|
from crc.services.file_service import FileService
|
|
|
|
from crc.services.temp_migration_service import FromFilesystemService, ToFilesystemService
|
2021-12-16 13:41:49 +00:00
|
|
|
|
2021-12-16 19:22:37 +00:00
|
|
|
import os
|
2021-12-16 13:41:49 +00:00
|
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
|
|
revision = '7225d990740e'
|
2021-12-17 16:48:24 +00:00
|
|
|
down_revision = '65b5ed6ae05b'
|
2021-12-16 13:41:49 +00:00
|
|
|
branch_labels = None
|
|
|
|
depends_on = None
|
|
|
|
|
|
|
|
|
2021-12-16 19:22:37 +00:00
|
|
|
def upgrade():
|
2021-12-16 13:41:49 +00:00
|
|
|
|
2021-12-16 19:22:37 +00:00
|
|
|
"""Starting this cautiously
|
|
|
|
Don't want to hork my dev system
|
|
|
|
Not deleting records yet
|
2021-12-16 13:41:49 +00:00
|
|
|
|
2021-12-16 19:22:37 +00:00
|
|
|
Originally, was only going to delete data in file_data.data
|
|
|
|
Now, thinking about deleting the record.
|
|
|
|
"""
|
|
|
|
|
|
|
|
processed_files = []
|
2021-12-16 13:41:49 +00:00
|
|
|
files = session.query(FileModel).all()
|
|
|
|
for file in files:
|
|
|
|
if file.archived is not True:
|
2021-12-16 19:22:37 +00:00
|
|
|
ToFilesystemService().write_file_to_system(file)
|
|
|
|
processed_files.append(file.id)
|
2021-12-16 13:41:49 +00:00
|
|
|
|
2021-12-16 19:22:37 +00:00
|
|
|
# TODO: delete processed files from file_data table
|
2021-12-16 13:41:49 +00:00
|
|
|
|
2021-12-16 19:22:37 +00:00
|
|
|
print('upgrade: done: ')
|
2021-12-16 13:41:49 +00:00
|
|
|
|
|
|
|
|
2021-12-16 19:22:37 +00:00
|
|
|
def downgrade():
|
2021-12-16 13:41:49 +00:00
|
|
|
|
2021-12-16 19:22:37 +00:00
|
|
|
# TODO: This is a work in progress, and depends on what we do in upgrade()
|
2021-12-16 13:41:49 +00:00
|
|
|
SYNC_FILE_ROOT = os.path.join(app.root_path, '..', 'files')
|
2021-12-16 19:22:37 +00:00
|
|
|
FromFilesystemService().update_file_metadata_from_filesystem(SYNC_FILE_ROOT)
|
2021-12-16 13:41:49 +00:00
|
|
|
|
|
|
|
print('downgrade: ')
|