Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add --run-background-updates option to update_database script. #10954

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10954.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `--run-background-updates` option to `update_database` script.
richvdh marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 20 additions & 12 deletions scripts-dev/update_database
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ if __name__ == "__main__":
required=True,
help="A database config file for either a SQLite3 database or a PostgreSQL one.",
)
parser.add_argument(
"--run-background-updates",
type=bool,
required=False,
help="Whether to run background updates after upgrading the database schema.",
)

args = parser.parse_args()

Expand All @@ -82,19 +88,21 @@ if __name__ == "__main__":
# Setup instantiates the store within the homeserver object and updates the
# DB.
hs.setup()
store = hs.get_datastore()

async def run_background_updates():
await store.db_pool.updates.run_background_updates(sleep=False)
# Stop the reactor to exit the script once every background update is run.
reactor.stop()
if args.run_background_updates:
store = hs.get_datastore()

def run():
# Apply all background updates on the database.
defer.ensureDeferred(
run_as_background_process("background_updates", run_background_updates)
)
async def run_background_updates():
await store.db_pool.updates.run_background_updates(sleep=False)
# Stop the reactor to exit the script once every background update is run.
reactor.stop()

def run():
# Apply all background updates on the database.
defer.ensureDeferred(
run_as_background_process("background_updates", run_background_updates)
)

reactor.callWhenRunning(run)
reactor.callWhenRunning(run)

reactor.run()
reactor.run()
richvdh marked this conversation as resolved.
Show resolved Hide resolved