2020-04-28 20:15:59 +00:00
|
|
|
import os
|
|
|
|
import frappe
|
|
|
|
import json
|
2020-02-10 08:00:54 +00:00
|
|
|
|
|
|
|
from frappe.migrate import migrate
|
2020-04-28 20:15:59 +00:00
|
|
|
from frappe.utils import cint, get_sites
|
2020-03-20 15:26:23 +00:00
|
|
|
from check_connection import get_config
|
2020-02-10 08:00:54 +00:00
|
|
|
|
2020-04-28 20:15:59 +00:00
|
|
|
|
2020-02-10 08:00:54 +00:00
|
|
|
def save_config(config):
|
|
|
|
with open('common_site_config.json', 'w') as f:
|
|
|
|
return json.dump(config, f, indent=1, sort_keys=True)
|
|
|
|
|
2020-04-28 20:15:59 +00:00
|
|
|
|
2020-02-10 08:00:54 +00:00
|
|
|
def set_maintenance_mode(enable=True):
|
|
|
|
conf = get_config()
|
|
|
|
|
|
|
|
if enable:
|
2020-04-28 20:15:59 +00:00
|
|
|
conf.update({"maintenance_mode": 1, "pause_scheduler": 1})
|
2020-02-10 08:00:54 +00:00
|
|
|
save_config(conf)
|
|
|
|
|
|
|
|
if not enable:
|
2020-04-28 20:15:59 +00:00
|
|
|
conf.update({"maintenance_mode": 0, "pause_scheduler": 0})
|
2020-02-10 08:00:54 +00:00
|
|
|
save_config(conf)
|
|
|
|
|
2020-04-28 20:15:59 +00:00
|
|
|
|
2020-03-20 15:26:23 +00:00
|
|
|
def migrate_sites(maintenance_mode=False):
|
|
|
|
installed_sites = ":".join(get_sites())
|
|
|
|
sites = os.environ.get("SITES", installed_sites).split(":")
|
|
|
|
if not maintenance_mode:
|
2020-04-28 20:15:59 +00:00
|
|
|
maintenance_mode = cint(os.environ.get("MAINTENANCE_MODE"))
|
2020-03-20 15:26:23 +00:00
|
|
|
|
|
|
|
if maintenance_mode:
|
|
|
|
set_maintenance_mode(True)
|
|
|
|
|
|
|
|
for site in sites:
|
|
|
|
print('Migrating', site)
|
|
|
|
frappe.init(site=site)
|
|
|
|
frappe.connect()
|
|
|
|
try:
|
|
|
|
migrate()
|
|
|
|
finally:
|
|
|
|
frappe.destroy()
|
|
|
|
|
2020-04-29 08:33:28 +00:00
|
|
|
# Disable maintenance mode after migration
|
|
|
|
set_maintenance_mode(False)
|
2020-03-20 15:26:23 +00:00
|
|
|
|
2020-04-28 20:15:59 +00:00
|
|
|
|
2020-03-20 15:26:23 +00:00
|
|
|
def main():
|
|
|
|
migrate_sites()
|
|
|
|
exit(0)
|
|
|
|
|
2020-04-28 20:15:59 +00:00
|
|
|
|
2020-03-20 15:26:23 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|