mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-26 15:19:25 -05:00
Move database configuration into config module
This commit is contained in:
parent
416a3e6c4f
commit
1ef66cc3bd
@ -350,42 +350,15 @@ def setup(config_options):
|
|||||||
|
|
||||||
tls_context_factory = context_factory.ServerContextFactory(config)
|
tls_context_factory = context_factory.ServerContextFactory(config)
|
||||||
|
|
||||||
if config.database_config:
|
database_engine = create_engine(config.database_config["name"])
|
||||||
with open(config.database_config, 'r') as f:
|
config.database_config["args"]["cp_openfun"] = database_engine.on_new_connection
|
||||||
db_config = yaml.safe_load(f)
|
|
||||||
else:
|
|
||||||
db_config = {
|
|
||||||
"name": "sqlite3",
|
|
||||||
"args": {
|
|
||||||
"database": config.database_path,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
db_config = {
|
|
||||||
k: v for k, v in db_config.items()
|
|
||||||
}
|
|
||||||
|
|
||||||
name = db_config.get("name", None)
|
|
||||||
if name == "psycopg2":
|
|
||||||
pass
|
|
||||||
elif name == "sqlite3":
|
|
||||||
db_config.setdefault("args", {}).update({
|
|
||||||
"cp_min": 1,
|
|
||||||
"cp_max": 1,
|
|
||||||
"check_same_thread": False,
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
raise RuntimeError("Unsupported database type '%s'" % (name,))
|
|
||||||
|
|
||||||
database_engine = create_engine(name)
|
|
||||||
db_config["args"]["cp_openfun"] = database_engine.on_new_connection
|
|
||||||
|
|
||||||
hs = SynapseHomeServer(
|
hs = SynapseHomeServer(
|
||||||
config.server_name,
|
config.server_name,
|
||||||
domain_with_port=domain_with_port,
|
domain_with_port=domain_with_port,
|
||||||
upload_dir=os.path.abspath("uploads"),
|
upload_dir=os.path.abspath("uploads"),
|
||||||
db_name=config.database_path,
|
db_name=config.database_path,
|
||||||
db_config=db_config,
|
db_config=config.database_config,
|
||||||
tls_context_factory=tls_context_factory,
|
tls_context_factory=tls_context_factory,
|
||||||
config=config,
|
config=config,
|
||||||
content_addr=config.content_addr,
|
content_addr=config.content_addr,
|
||||||
@ -404,7 +377,7 @@ def setup(config_options):
|
|||||||
try:
|
try:
|
||||||
db_conn = database_engine.module.connect(
|
db_conn = database_engine.module.connect(
|
||||||
**{
|
**{
|
||||||
k: v for k, v in db_config.get("args", {}).items()
|
k: v for k, v in config.database_config.get("args", {}).items()
|
||||||
if not k.startswith("cp_")
|
if not k.startswith("cp_")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from ._base import Config
|
from ._base import Config
|
||||||
import os
|
import os
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
class DatabaseConfig(Config):
|
class DatabaseConfig(Config):
|
||||||
@ -27,9 +28,27 @@ class DatabaseConfig(Config):
|
|||||||
self.event_cache_size = self.parse_size(args.event_cache_size)
|
self.event_cache_size = self.parse_size(args.event_cache_size)
|
||||||
|
|
||||||
if args.database_config:
|
if args.database_config:
|
||||||
self.database_config = self.abspath(args.database_config)
|
with open(args.database_config) as f:
|
||||||
|
self.database_config = yaml.safe_load(f)
|
||||||
else:
|
else:
|
||||||
self.database_config = None
|
self.database_config = {
|
||||||
|
"name": "sqlite3",
|
||||||
|
"args": {
|
||||||
|
"database": self.database_path,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
name = self.database_config.get("name", None)
|
||||||
|
if name == "psycopg2":
|
||||||
|
pass
|
||||||
|
elif name == "sqlite3":
|
||||||
|
self.database_config.setdefault("args", {}).update({
|
||||||
|
"cp_min": 1,
|
||||||
|
"cp_max": 1,
|
||||||
|
"check_same_thread": False,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
raise RuntimeError("Unsupported database type '%s'" % (name,))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_arguments(cls, parser):
|
def add_arguments(cls, parser):
|
||||||
|
Loading…
Reference in New Issue
Block a user