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

Make a full SQL schema #5320

Merged
merged 12 commits into from Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions MANIFEST.in
Expand Up @@ -9,7 +9,10 @@ include demo/*.py
include demo/*.sh

recursive-include synapse/storage/schema *.sql
recursive-include synapse/storage/schema *.sql.postgres
recursive-include synapse/storage/schema *.sql.sqlite
recursive-include synapse/storage/schema *.py
recursive-include synapse/storage/schema *.txt

recursive-include docs *
recursive-include scripts *
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5320.misc
@@ -0,0 +1 @@
New installs will now use the v54 full schema, rather than the full schema v14 and applying incremental updates to v54.
16 changes: 14 additions & 2 deletions synapse/storage/prepare_database.py
Expand Up @@ -20,6 +20,8 @@
import os
import re

from synapse.storage.engines.postgres import PostgresEngine

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -115,8 +117,16 @@ def _setup_new_database(cur, database_engine):

valid_dirs = []
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:
match = pattern.match(filename)
match = pattern.match(filename) or specific_pattern.match(filename)
abs_path = os.path.join(current_dir, filename)
if match and os.path.isdir(abs_path):
ver = int(match.group(0))
Expand All @@ -136,7 +146,9 @@ def _setup_new_database(cur, database_engine):

directory_entries = os.listdir(sql_dir)

for filename in fnmatch.filter(directory_entries, "*.sql"):
for filename in sorted(fnmatch.filter(directory_entries, "*.sql") + fnmatch.filter(
directory_entries, "*.sql." + specific
)):
sql_loc = os.path.join(sql_dir, filename)
logger.debug("Applying schema %s", sql_loc)
executescript(cur, sql_loc)
Expand Down