mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-19 00:11:47 +01:00
s/schema_deltas/applied_schema_deltas/
This commit is contained in:
parent
5681264faa
commit
17d319a20d
2 changed files with 11 additions and 9 deletions
|
@ -674,12 +674,13 @@ def _setup_new_database(cur):
|
|||
_upgrade_existing_database(
|
||||
cur,
|
||||
current_version=max_current_ver,
|
||||
delta_files=[],
|
||||
applied_delta_files=[],
|
||||
upgraded=False
|
||||
)
|
||||
|
||||
|
||||
def _upgrade_existing_database(cur, current_version, delta_files, upgraded):
|
||||
def _upgrade_existing_database(cur, current_version, applied_delta_files,
|
||||
upgraded):
|
||||
"""Upgrades an existing database.
|
||||
|
||||
Delta files can either be SQL stored in *.sql files, or python modules
|
||||
|
@ -712,8 +713,9 @@ def _upgrade_existing_database(cur, current_version, delta_files, upgraded):
|
|||
|
||||
Args:
|
||||
cur (Cursor)
|
||||
current_version (int): The current version of the schema
|
||||
delta_files (list): A list of deltas that have already been applied
|
||||
current_version (int): The current version of the schema.
|
||||
applied_delta_files (list): A list of deltas that have already been
|
||||
applied.
|
||||
upgraded (bool): Whether the current version was generated by having
|
||||
applied deltas or from full schema file. If `True` the function
|
||||
will never apply delta files for the given `current_version`, since
|
||||
|
@ -746,7 +748,7 @@ def _upgrade_existing_database(cur, current_version, delta_files, upgraded):
|
|||
directory_entries.sort()
|
||||
for file_name in directory_entries:
|
||||
relative_path = os.path.join(str(v), file_name)
|
||||
if relative_path in delta_files:
|
||||
if relative_path in applied_delta_files:
|
||||
continue
|
||||
|
||||
absolute_path = os.path.join(
|
||||
|
@ -781,7 +783,7 @@ def _upgrade_existing_database(cur, current_version, delta_files, upgraded):
|
|||
|
||||
# Mark as done.
|
||||
cur.execute(
|
||||
"INSERT INTO schema_deltas (version, file)"
|
||||
"INSERT INTO applied_schema_deltas (version, file)"
|
||||
" VALUES (?,?)",
|
||||
(v, relative_path)
|
||||
)
|
||||
|
@ -807,7 +809,7 @@ def _get_or_create_schema_state(txn):
|
|||
|
||||
if current_version:
|
||||
txn.execute(
|
||||
"SELECT file FROM schema_deltas WHERE version >= ?",
|
||||
"SELECT file FROM applied_schema_deltas WHERE version >= ?",
|
||||
(current_version,)
|
||||
)
|
||||
return current_version, txn.fetchall(), upgraded
|
||||
|
|
|
@ -21,10 +21,10 @@ CREATE TABLE IF NOT EXISTS schema_version(
|
|||
CONSTRAINT schema_version_lock_uniq UNIQUE (Lock)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS schema_deltas(
|
||||
CREATE TABLE IF NOT EXISTS applied_schema_deltas(
|
||||
version INTEGER NOT NULL,
|
||||
file TEXT NOT NULL,
|
||||
CONSTRAINT schema_deltas_ver_file UNIQUE (version, file) ON CONFLICT IGNORE
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS schema_deltas_ver ON schema_deltas(version);
|
||||
CREATE INDEX IF NOT EXISTS schema_deltas_ver ON applied_schema_deltas(version);
|
||||
|
|
Loading…
Reference in a new issue