##// END OF EJS Templates
fix(db-migrate): enforce gc collection to optimize memory usage
super-admin -
r5504:44ad8d20 default
parent child Browse files
Show More
@@ -1,50 +1,53 b''
1
1
2
2
3 import logging
3 import logging
4 from sqlalchemy import *
4 from sqlalchemy import *
5 from sqlalchemy.engine import reflection
5 from sqlalchemy.engine import reflection
6
6
7 from alembic.migration import MigrationContext
7 from alembic.migration import MigrationContext
8 from alembic.operations import Operations
8 from alembic.operations import Operations
9
9
10 from rhodecode.lib.dbmigrate.versions import _reset_base
10 from rhodecode.lib.dbmigrate.versions import _reset_base
11 from rhodecode.model import meta, init_model_encryption
11 from rhodecode.model import meta, init_model_encryption
12
12
13
13
14 log = logging.getLogger(__name__)
14 log = logging.getLogger(__name__)
15
15
16
16
17 def _get_indexes_list(migrate_engine, table_name):
17 def _get_indexes_list(migrate_engine, table_name):
18 inspector = reflection.Inspector.from_engine(migrate_engine)
18 inspector = reflection.Inspector.from_engine(migrate_engine)
19 return inspector.get_indexes(table_name)
19 return inspector.get_indexes(table_name)
20
20
21
21
22 def upgrade(migrate_engine):
22 def upgrade(migrate_engine):
23 """
23 """
24 Upgrade operations go here.
24 Upgrade operations go here.
25 Don't create your own engine; bind migrate_engine to your metadata
25 Don't create your own engine; bind migrate_engine to your metadata
26 """
26 """
27 from rhodecode.model import db as db_5_1_0_0
27 from rhodecode.model import db as db_5_1_0_0
28
28
29 # issue fixups
29 # issue fixups
30 fixups(db_5_1_0_0, meta.Session)
30 fixups(db_5_1_0_0, meta.Session)
31
31
32
32
33 def downgrade(migrate_engine):
33 def downgrade(migrate_engine):
34 pass
34 pass
35
35
36
36
37 def fixups(models, _SESSION):
37 def fixups(models, _SESSION):
38
38 for db_repo in _SESSION.query(models.Repository).all():
39 for db_repo in _SESSION.query(models.Repository).all():
39
40
40 config = db_repo._config
41 try:
41 config.set('extensions', 'largefiles', '')
42 config = db_repo._config
43 config.set('extensions', 'largefiles', '')
42
44
43 try:
45 scm = db_repo.scm_instance(cache=False, config=config, vcs_full_cache=False)
44 scm = db_repo.scm_instance(cache=False, config=config)
45 if scm:
46 if scm:
46 print(f'installing hook for repo: {db_repo}')
47 print(f'installing hook for repo: {db_repo}')
47 scm.install_hooks(force=True)
48 scm.install_hooks(force=True)
49 del scm # force GC
50 del config
48 except Exception as e:
51 except Exception as e:
49 print(e)
52 print(e)
50 print('continue...')
53 print('continue...')
General Comments 0
You need to be logged in to leave comments. Login now