2
0
mirror of https://github.com/frappe/frappe_docker.git synced 2024-12-26 03:27:31 +00:00
frappe_docker/build/frappe-worker/commands/migrate.py

53 lines
1.2 KiB
Python
Raw Normal View History

import os
2020-02-10 08:00:54 +00:00
2021-12-10 08:53:00 +00:00
import frappe
from frappe.utils import cint, get_sites
2020-07-10 17:45:36 +00:00
from utils import get_config, save_config
2020-02-10 08:00:54 +00:00
2020-02-10 08:00:54 +00:00
def set_maintenance_mode(enable=True):
conf = get_config()
if enable:
conf.update({"maintenance_mode": 1, "pause_scheduler": 1})
2020-02-10 08:00:54 +00:00
save_config(conf)
if not enable:
conf.update({"maintenance_mode": 0, "pause_scheduler": 0})
2020-02-10 08:00:54 +00:00
save_config(conf)
def migrate_sites(maintenance_mode=False):
installed_sites = ":".join(get_sites())
sites = os.environ.get("SITES", installed_sites).split(":")
if not maintenance_mode:
maintenance_mode = cint(os.environ.get("MAINTENANCE_MODE"))
if maintenance_mode:
set_maintenance_mode(True)
for site in sites:
2021-12-10 08:52:40 +00:00
print("Migrating", site)
frappe.init(site=site)
frappe.connect()
try:
from frappe.migrate import migrate
2021-12-10 08:52:40 +00:00
migrate()
finally:
frappe.destroy()
# Disable maintenance mode after migration
set_maintenance_mode(False)
def main():
migrate_sites()
if frappe.redis_server:
frappe.redis_server.connection_pool.disconnect()
exit(0)
if __name__ == "__main__":
main()