mirror of
https://github.com/element-hq/synapse
synced 2024-08-31 04:40:21 +00:00
prepare
This commit is contained in:
parent
d828d1dc57
commit
37057d5d60
1 changed files with 14 additions and 2 deletions
|
@ -20,6 +20,8 @@ import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from synapse.storage.engines.postgres import PostgresEngine
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,8 +117,16 @@ def _setup_new_database(cur, database_engine):
|
||||||
|
|
||||||
valid_dirs = []
|
valid_dirs = []
|
||||||
pattern = re.compile(r"^\d+(\.sql)?$")
|
pattern = re.compile(r"^\d+(\.sql)?$")
|
||||||
|
|
||||||
|
if isinstance(database_engine, PostgresEngine):
|
||||||
|
specific = "postgres"
|
||||||
|
else:
|
||||||
|
specific = "sqlite"
|
||||||
|
|
||||||
|
specific_pattern = re.compile(r"^\d+(\.sql." + specific + r")?$")
|
||||||
|
|
||||||
for filename in directory_entries:
|
for filename in directory_entries:
|
||||||
match = pattern.match(filename)
|
match = pattern.match(filename) or specific_pattern.match(filename)
|
||||||
abs_path = os.path.join(current_dir, filename)
|
abs_path = os.path.join(current_dir, filename)
|
||||||
if match and os.path.isdir(abs_path):
|
if match and os.path.isdir(abs_path):
|
||||||
ver = int(match.group(0))
|
ver = int(match.group(0))
|
||||||
|
@ -136,7 +146,9 @@ def _setup_new_database(cur, database_engine):
|
||||||
|
|
||||||
directory_entries = os.listdir(sql_dir)
|
directory_entries = os.listdir(sql_dir)
|
||||||
|
|
||||||
for filename in fnmatch.filter(directory_entries, "*.sql"):
|
for filename in fnmatch.filter(directory_entries, "*.sql") + fnmatch.filter(
|
||||||
|
directory_entries, "*.sql." + specific
|
||||||
|
):
|
||||||
sql_loc = os.path.join(sql_dir, filename)
|
sql_loc = os.path.join(sql_dir, filename)
|
||||||
logger.debug("Applying schema %s", sql_loc)
|
logger.debug("Applying schema %s", sql_loc)
|
||||||
executescript(cur, sql_loc)
|
executescript(cur, sql_loc)
|
||||||
|
|
Loading…
Reference in a new issue