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