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

Commit

Permalink
Fix DB scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Dec 5, 2019
1 parent 6dcd6c4 commit 8b77fc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
17 changes: 7 additions & 10 deletions scripts-dev/update_database
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ if __name__ == "__main__":
" on it."
)
)
parser.add_argument("-v", action='store_true')
parser.add_argument("-v", action="store_true")
parser.add_argument(
"--database-config",
type=argparse.FileType('r'),
type=argparse.FileType("r"),
required=True,
help="A database config file for either a SQLite3 database or a PostgreSQL one.",
)
Expand Down Expand Up @@ -101,24 +101,21 @@ if __name__ == "__main__":

# Instantiate and initialise the homeserver object.
hs = MockHomeserver(
config,
database_engine,
db_conn,
db_config=config.database_config,
config, database_engine, db_conn, db_config=config.database_config,
)
# setup instantiates the store within the homeserver object.
hs.setup()
store = hs.get_datastore()

@defer.inlineCallbacks
def run_background_updates():
yield store.run_background_updates(sleep=False)
yield store.db.updates.run_background_updates(sleep=False)
# Stop the reactor to exit the script once every background update is run.
reactor.stop()

# Apply all background updates on the database.
reactor.callWhenRunning(lambda: run_as_background_process(
"background_updates", run_background_updates
))
reactor.callWhenRunning(
lambda: run_as_background_process("background_updates", run_background_updates)
)

reactor.run()
14 changes: 9 additions & 5 deletions scripts/synapse_port_db
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ class Porter(object):

return headers, forward_rows, backward_rows

headers, frows, brows = yield self.sqlite_store.db.runInteraction("select", r)
headers, frows, brows = yield self.sqlite_store.db.runInteraction(
"select", r
)

if frows or brows:
if frows:
Expand Down Expand Up @@ -521,17 +523,19 @@ class Porter(object):
@defer.inlineCallbacks
def run_background_updates_on_postgres(self):
# Manually apply all background updates on the PostgreSQL database.
postgres_ready = yield self.postgres_store.has_completed_background_updates()
postgres_ready = (
yield self.postgres_store.db.updates.has_completed_background_updates()
)

if not postgres_ready:
# Only say that we're running background updates when there are background
# updates to run.
self.progress.set_state("Running background updates on PostgreSQL")

while not postgres_ready:
yield self.postgres_store.do_next_background_update(100)
yield self.postgres_store.db.updates.do_next_background_update(100)
postgres_ready = yield (
self.postgres_store.has_completed_background_updates()
self.postgres_store.db.updates.has_completed_background_updates()
)

@defer.inlineCallbacks
Expand All @@ -541,7 +545,7 @@ class Porter(object):

# Check if all background updates are done, abort if not.
updates_complete = (
yield self.sqlite_store.has_completed_background_updates()
yield self.sqlite_store.db.updates.has_completed_background_updates()
)
if not updates_complete:
sys.stderr.write(
Expand Down

0 comments on commit 8b77fc6

Please sign in to comment.