Skip to content

Commit

Permalink
Merge pull request #95 from matrix-org/hs/fix-db
Browse files Browse the repository at this point in the history
Fix postgres database configuration breakage
  • Loading branch information
Half-Shot authored Apr 2, 2020
2 parents 20d91d7 + 0e52e98 commit 77713d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion sygnal/gcmpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,14 +495,15 @@ async def get_canonical_ids(self, reg_ids):
mapping of registration ID to either its canonical registration ID,
or `None` if there is no entry.
"""
parameter_key = "?" if self.engine == "sqlite" else "%s"
rows = dict(
await self.db.runQuery(
"""
SELECT reg_id, canonical_reg_id
FROM gcm_canonical_reg_id
WHERE reg_id IN (%s)
"""
% (",".join(["?"] * len(reg_ids))),
% (",".join(parameter_key for _ in reg_ids)),
reg_ids,
)
)
Expand Down
6 changes: 5 additions & 1 deletion sygnal/sygnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
CONFIG_DEFAULTS = {
"http": {"port": 5000, "bind_addresses": ["127.0.0.1"]},
"log": {"setup": {}, "access": {"x_forwarded_for": False}},
"database": {"name": "sqlite3", "args": {"dbfile": "sygnal.db"}},
"metrics": {
"prometheus": {"enabled": False, "address": "127.0.0.1", "port": 8000},
"opentracing": {
Expand Down Expand Up @@ -86,6 +85,11 @@ def __init__(self, config, custom_reactor, tracer=opentracing.tracer):
"name": "sqlite3",
"args": {"dbfile": config["db"]["dbfile"]},
}
elif config.get("database") is None:
config["database"] = {
"name": "sqlite3",
"args": {"dbfile": "sygnal.db"},
}

sentrycfg = config["metrics"]["sentry"]
if sentrycfg["enabled"] is True:
Expand Down
4 changes: 2 additions & 2 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ def _tear_down_database(self, dbname):
password=POSTGRES_PASSWORD,
host=POSTGRES_HOST,
)
conn.autocommit = True
cur = conn.cursor()
cur.execute("DROP DATABASE %s;" % (dbname,))
cur.commit()
cur.close()
conn.close()

def setUp(self):
reactor = ExtendedMemoryReactorClock()

config = {"apps": {}, "log": {"setup": {"version": 1}}}
config = merge_left_with_defaults(CONFIG_DEFAULTS, config)

self.config_setup(config)

config = merge_left_with_defaults(CONFIG_DEFAULTS, config)
if USE_POSTGRES:
self._set_up_database(self.dbname)

Expand Down

0 comments on commit 77713d9

Please sign in to comment.