Skip to content

Commit

Permalink
Run middleware migrations on config upload
Browse files Browse the repository at this point in the history
(cherry picked from commit 319293f)
  • Loading branch information
themylogin authored and bugclerk committed May 15, 2024
1 parent 7624eb9 commit 67ba47a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/middlewared/middlewared/plugins/migration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import os

import sqlite3

from middlewared.service import Service
import middlewared.sqlalchemy as sa
from middlewared.utils.plugins import load_modules
Expand Down Expand Up @@ -45,3 +47,15 @@ async def run(self):
await self.middleware.call("datastore.insert", "system.migration", {"name": name}, {"ha_sync": False})

await self.middleware.call("keyvalue.set", "run_migration", False, {"ha_sync": False})


def on_config_upload(middleware, path):
conn = sqlite3.connect(path)
try:
conn.execute("REPLACE INTO system_keyvalue (key, value) VALUES ('run_migration', 'true')")
finally:
conn.close()


async def setup(middleware):
middleware.register_hook('config.on_upload', on_config_upload, sync=True)

0 comments on commit 67ba47a

Please sign in to comment.