2020-04-29 01:45:59 +05:30
|
|
|
import os
|
2020-02-10 13:30:54 +05:30
|
|
|
|
2021-12-10 11:53:00 +03:00
|
|
|
import frappe
|
2020-04-29 01:45:59 +05:30
|
|
|
from frappe.utils import cint, get_sites
|
2020-07-10 23:15:36 +05:30
|
|
|
from utils import get_config, save_config
|
2020-02-10 13:30:54 +05:30
|
|
|
|
2020-04-29 01:45:59 +05:30
|
|
|
|
2020-02-10 13:30:54 +05:30
|
|
|
def set_maintenance_mode(enable=True):
|
|
|
|
conf = get_config()
|
|
|
|
|
|
|
|
if enable:
|
2020-04-29 01:45:59 +05:30
|
|
|
conf.update({"maintenance_mode": 1, "pause_scheduler": 1})
|
2020-02-10 13:30:54 +05:30
|
|
|
save_config(conf)
|
|
|
|
|
|
|
|
if not enable:
|
2020-04-29 01:45:59 +05:30
|
|
|
conf.update({"maintenance_mode": 0, "pause_scheduler": 0})
|
2020-02-10 13:30:54 +05:30
|
|
|
save_config(conf)
|
|
|
|
|
2020-04-29 01:45:59 +05:30
|
|
|
|
2020-03-20 20:56:23 +05:30
|
|
|
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-29 01:45:59 +05:30
|
|
|
maintenance_mode = cint(os.environ.get("MAINTENANCE_MODE"))
|
2020-03-20 20:56:23 +05:30
|
|
|
|
|
|
|
if maintenance_mode:
|
|
|
|
set_maintenance_mode(True)
|
|
|
|
|
|
|
|
for site in sites:
|
2021-12-10 11:52:40 +03:00
|
|
|
print("Migrating", site)
|
2020-03-20 20:56:23 +05:30
|
|
|
frappe.init(site=site)
|
|
|
|
frappe.connect()
|
|
|
|
try:
|
2020-06-21 13:23:22 +05:30
|
|
|
from frappe.migrate import migrate
|
2021-12-10 11:52:40 +03:00
|
|
|
|
2020-03-20 20:56:23 +05:30
|
|
|
migrate()
|
|
|
|
finally:
|
|
|
|
frappe.destroy()
|
|
|
|
|
2020-04-29 14:03:28 +05:30
|
|
|
# Disable maintenance mode after migration
|
|
|
|
set_maintenance_mode(False)
|
2020-03-20 20:56:23 +05:30
|
|
|
|
2020-04-29 01:45:59 +05:30
|
|
|
|
2020-03-20 20:56:23 +05:30
|
|
|
def main():
|
|
|
|
migrate_sites()
|
2020-06-29 23:28:10 +05:30
|
|
|
if frappe.redis_server:
|
|
|
|
frappe.redis_server.connection_pool.disconnect()
|
2020-03-20 20:56:23 +05:30
|
|
|
exit(0)
|
|
|
|
|
2020-04-29 01:45:59 +05:30
|
|
|
|
2020-03-20 20:56:23 +05:30
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|