general: run sql "migrations" when starting wcs (#6617)
This is required when new global tables (such as tracking_codes) have to be created.
This commit is contained in:
parent
f19d6b9375
commit
45d666464c
|
@ -1115,11 +1115,8 @@ class SettingsDirectory(QommonSettingsDirectory):
|
|||
postgresql_cfg = copy.copy(get_cfg('postgresql', {}))
|
||||
cfg_submit(form, 'postgresql', ['database', 'user', 'password',
|
||||
'host', 'port'])
|
||||
import sql
|
||||
try:
|
||||
sql.get_connection(new=True)
|
||||
sql.do_user_table()
|
||||
sql.do_tracking_code_table()
|
||||
get_publisher().initialize_sql()
|
||||
except Exception, e:
|
||||
postgresql_cfg[str('postgresql')] = postgresql_cfg
|
||||
form.set_error('database', str(e))
|
||||
|
|
|
@ -18,6 +18,7 @@ import os
|
|||
import socket
|
||||
import sys
|
||||
import qommon.scgi_server
|
||||
import quixote
|
||||
import quixote.server.simple_server
|
||||
|
||||
from qommon.ctl import Command, make_option
|
||||
|
@ -87,6 +88,23 @@ class CmdStart(Command):
|
|||
if sub_options.silent:
|
||||
self.make_silent()
|
||||
|
||||
# iterate over all tenants to execute required SQL migrations
|
||||
# beforehand.
|
||||
pub = publisher.WcsPublisher.create_publisher(register_cron=False)
|
||||
quixote.cleanup()
|
||||
base_app_dir = pub.app_dir
|
||||
for hostname in os.listdir(base_app_dir):
|
||||
tenant_path = os.path.join(base_app_dir, hostname)
|
||||
if not os.path.exists(os.path.join(tenant_path, 'config.pck')):
|
||||
continue
|
||||
pub = publisher.WcsPublisher.create_publisher(register_cron=False)
|
||||
pub.app_dir = tenant_path
|
||||
pub.set_config()
|
||||
if pub.is_using_postgresql():
|
||||
pub.initialize_sql()
|
||||
pub.cleanup()
|
||||
quixote.cleanup()
|
||||
|
||||
if sub_options.daemonize:
|
||||
try:
|
||||
pid = os.fork()
|
||||
|
|
|
@ -207,6 +207,12 @@ class WcsPublisher(StubWcsPublisher):
|
|||
request.response.iframe_mode = True
|
||||
return QommonPublisher.try_publish(self, request)
|
||||
|
||||
def initialize_sql(self):
|
||||
import sql
|
||||
sql.get_connection(new=True)
|
||||
sql.do_user_table()
|
||||
sql.do_tracking_code_table()
|
||||
|
||||
def cleanup(self):
|
||||
if self.is_using_postgresql():
|
||||
import sql
|
||||
|
|
|
@ -703,12 +703,13 @@ class QommonPublisher(Publisher):
|
|||
cls.etld = etld.etld(filename)
|
||||
load_effective_tld_names = classmethod(load_effective_tld_names)
|
||||
|
||||
def create_publisher(cls):
|
||||
def create_publisher(cls, register_cron=True):
|
||||
cls.load_extra_dirs()
|
||||
cls.load_translations()
|
||||
cls.register_cronjob(CronJob(cls.clean_sessions, minutes=range(0, 60, 5)))
|
||||
cls.register_cronjob(CronJob(cls.clean_afterjobs, minutes=[random.randint(0, 59)]))
|
||||
cls.register_cronjob(CronJob(cls.clean_tempfiles, minutes=[random.randint(0, 59)]))
|
||||
if register_cron:
|
||||
cls.register_cronjob(CronJob(cls.clean_sessions, minutes=range(0, 60, 5)))
|
||||
cls.register_cronjob(CronJob(cls.clean_afterjobs, minutes=[random.randint(0, 59)]))
|
||||
cls.register_cronjob(CronJob(cls.clean_tempfiles, minutes=[random.randint(0, 59)]))
|
||||
cls.load_effective_tld_names()
|
||||
|
||||
publisher = cls(cls.root_directory_class(),
|
||||
|
|
Loading…
Reference in New Issue