Coverage for mindsdb / migrations / versions / 2022-09-19_3d5e70105df7_content_storage.py: 15%
41 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
1"""content_storage
3Revision ID: 3d5e70105df7
4Revises: 87b2df2b83e1
5Create Date: 2022-09-19 11:30:09.182435
7"""
8from pathlib import Path
9import shutil
11from mindsdb.utilities.config import Config
14# revision identifiers, used by Alembic.
15revision = '3d5e70105df7'
16down_revision = '87b2df2b83e1'
17branch_labels = None
18depends_on = None
21def upgrade():
22 config = Config()
23 is_cloud = config.get('cloud', False)
24 if is_cloud is True:
25 return
27 storage_path = Path(config.paths['storage'])
28 for item in storage_path.iterdir():
29 if item.is_file() and item.name.startswith('predictor_'):
30 original_name = item.name
31 temp_file_path = item.parent / f'{original_name}_temp'
32 item.replace(temp_file_path)
33 item.mkdir(exist_ok=True)
34 temp_file_path.replace(item / original_name)
36 root_path = Path(config.paths['root'])
37 if (root_path / 'datasources').is_dir():
38 shutil.rmtree(root_path / 'datasources')
39 if (root_path / 'integrations').is_dir():
40 shutil.rmtree(root_path / 'integrations')
41 if (root_path / 'predictors').is_dir():
42 shutil.rmtree(root_path / 'predictors')
45def downgrade():
46 config = Config()
47 is_cloud = config.get('cloud', False)
48 if is_cloud is True:
49 return
51 storage_path = Path(config.paths['storage'])
52 for item in storage_path.iterdir():
53 if item.is_dir() and item.name.startswith('predictor_'):
54 original_name = item.name
55 if (item / original_name).is_file():
56 temp_dir_path = item.parent / f'{original_name}_temp'
57 item.replace(temp_dir_path)
58 (temp_dir_path / original_name).replace(item.parent / original_name)
59 shutil.rmtree(temp_dir_path)