misc: add management command to run migrations (#6735)

This commit is contained in:
Frédéric Péters 2017-08-11 11:22:31 +02:00
parent 92cc4014db
commit 8491962406
2 changed files with 56 additions and 0 deletions

View File

@ -11,6 +11,7 @@ from wcs.wf.jump import JumpWorkflowStatusItem
from wcs.fields import StringField, EmailField
import wcs.qommon.ctl
from wcs.qommon.management.commands.collectstatic import Command as CmdCollectStatic
from wcs.qommon.management.commands.migrate import Command as CmdMigrate
from wcs.ctl.process_bounce import CmdProcessBounce
from wcs.ctl.wipe_data import CmdWipeData
from wcs.ctl.trigger_jumps import select_and_jump_formdata
@ -23,6 +24,17 @@ from utilities import create_temporary_pub, clean_temporary_pub
def pub():
return create_temporary_pub()
def pytest_generate_tests(metafunc):
if 'two_pubs' in metafunc.fixturenames:
metafunc.parametrize('two_pubs', ['pickle', 'sql'], indirect=True)
@pytest.fixture
def two_pubs(request):
pub = create_temporary_pub(sql_mode=(request.param == 'sql'))
pub.cfg['language'] = {'language': 'en'}
pub.write_cfg()
return pub
def teardown_module(module):
clean_temporary_pub()
@ -43,6 +55,9 @@ def test_collectstatic(pub):
CmdCollectStatic.collectstatic(pub, clear=True, link=True)
assert os.path.islink(os.path.join(pub.app_dir, 'collectstatic', 'css', 'wcs.css'))
def test_migrate(two_pubs):
CmdMigrate().handle()
def test_get_bounce_addrs():
msg = MIMEText('Hello world')
assert CmdProcessBounce.get_bounce_addrs(msg) is None

View File

@ -0,0 +1,41 @@
# w.c.s. - web application for online forms
# Copyright (C) 2005-2017 Entr'ouvert
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
import os
import quixote
from django.core.management.base import BaseCommand
from qommon.publisher import get_publisher_class
class Command(BaseCommand):
help = 'Migrate databases'
def handle(self, **options):
Publisher = get_publisher_class()
quixote.cleanup()
pub = Publisher.create_publisher()
base_app_dir = pub.app_dir
for hostname in Publisher.get_tenants():
tenant_path = os.path.join(base_app_dir, hostname)
if not os.path.exists(os.path.join(tenant_path, 'config.pck')):
continue
pub = Publisher.create_publisher()
pub.app_dir = tenant_path
pub.set_config()
if pub.is_using_postgresql():
pub.migrate_sql()
pub.cleanup()
quixote.cleanup()