##// END OF EJS Templates
alembic: check database version before starting kallithea...
domruf -
r6556:4e40640c default
parent child Browse files
Show More
@@ -18,12 +18,16 b' This file complements the .ini file.'
18 """
18 """
19
19
20 import platform
20 import platform
21 import os, sys
21 import os, sys, logging
22
22
23 import tg
23 import tg
24 from tg import hooks
24 from tg import hooks
25 from tg.configuration import AppConfig
25 from tg.configuration import AppConfig
26 from tg.support.converters import asbool
26 from tg.support.converters import asbool
27 import alembic
28 from alembic.script.base import ScriptDirectory
29 from alembic.migration import MigrationContext
30 from sqlalchemy import create_engine
27
31
28 from kallithea.lib.middleware.https_fixup import HttpsFixup
32 from kallithea.lib.middleware.https_fixup import HttpsFixup
29 from kallithea.lib.middleware.simplegit import SimpleGit
33 from kallithea.lib.middleware.simplegit import SimpleGit
@@ -38,6 +42,8 b' from kallithea.model.scm import ScmModel'
38 import formencode
42 import formencode
39 import kallithea
43 import kallithea
40
44
45 log = logging.getLogger(__name__)
46
41
47
42 class KallitheaAppConfig(AppConfig):
48 class KallitheaAppConfig(AppConfig):
43 # Note: AppConfig has a misleading name, as it's not the application
49 # Note: AppConfig has a misleading name, as it's not the application
@@ -113,6 +119,30 b' else:'
113 def setup_configuration(app):
119 def setup_configuration(app):
114 config = app.config
120 config = app.config
115
121
122 if config.get('ignore_alembic_revision', False):
123 log.warn('database alembic revision checking is disabled')
124 else:
125 dbconf = config['sqlalchemy.url']
126 alembic_cfg = alembic.config.Config()
127 alembic_cfg.set_main_option('script_location', 'kallithea:alembic')
128 alembic_cfg.set_main_option('sqlalchemy.url', dbconf)
129 script_dir = ScriptDirectory.from_config(alembic_cfg)
130 available_heads = sorted(script_dir.get_heads())
131
132 engine = create_engine(dbconf)
133 with engine.connect() as conn:
134 context = MigrationContext.configure(conn)
135 current_heads = sorted(str(s) for s in context.get_current_heads())
136 if current_heads != available_heads:
137 log.error('Failed to run Kallithea:\n\n'
138 'The database version does not match the Kallithea version.\n'
139 'Please read the documentation on how to upgrade or downgrade the database.\n'
140 'Current database version id(s): %s\n'
141 'Expected database version id(s): %s\n'
142 'If you are a developer and you know what you are doing, you can add `ignore_alembic_revision = True` '
143 'to your .ini file to skip the check.\n' % (' '.join(current_heads), ' '.join(available_heads)))
144 sys.exit(1)
145
116 # store some globals into kallithea
146 # store some globals into kallithea
117 kallithea.CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
147 kallithea.CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
118 kallithea.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager'))
148 kallithea.CELERY_EAGER = str2bool(config['app_conf'].get('celery.always.eager'))
General Comments 0
You need to be logged in to leave comments. Login now