forked from MirrorHub/synapse
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(
|
_upgrade_existing_database(
|
||||||
cur,
|
cur,
|
||||||
current_version=max_current_ver,
|
current_version=max_current_ver,
|
||||||
delta_files=[],
|
applied_delta_files=[],
|
||||||
upgraded=False
|
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.
|
"""Upgrades an existing database.
|
||||||
|
|
||||||
Delta files can either be SQL stored in *.sql files, or python modules
|
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:
|
Args:
|
||||||
cur (Cursor)
|
cur (Cursor)
|
||||||
current_version (int): The current version of the schema
|
current_version (int): The current version of the schema.
|
||||||
delta_files (list): A list of deltas that have already been applied
|
applied_delta_files (list): A list of deltas that have already been
|
||||||
|
applied.
|
||||||
upgraded (bool): Whether the current version was generated by having
|
upgraded (bool): Whether the current version was generated by having
|
||||||
applied deltas or from full schema file. If `True` the function
|
applied deltas or from full schema file. If `True` the function
|
||||||
will never apply delta files for the given `current_version`, since
|
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()
|
directory_entries.sort()
|
||||||
for file_name in directory_entries:
|
for file_name in directory_entries:
|
||||||
relative_path = os.path.join(str(v), file_name)
|
relative_path = os.path.join(str(v), file_name)
|
||||||
if relative_path in delta_files:
|
if relative_path in applied_delta_files:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
absolute_path = os.path.join(
|
absolute_path = os.path.join(
|
||||||
|
@ -781,7 +783,7 @@ def _upgrade_existing_database(cur, current_version, delta_files, upgraded):
|
||||||
|
|
||||||
# Mark as done.
|
# Mark as done.
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO schema_deltas (version, file)"
|
"INSERT INTO applied_schema_deltas (version, file)"
|
||||||
" VALUES (?,?)",
|
" VALUES (?,?)",
|
||||||
(v, relative_path)
|
(v, relative_path)
|
||||||
)
|
)
|
||||||
|
@ -807,7 +809,7 @@ def _get_or_create_schema_state(txn):
|
||||||
|
|
||||||
if current_version:
|
if current_version:
|
||||||
txn.execute(
|
txn.execute(
|
||||||
"SELECT file FROM schema_deltas WHERE version >= ?",
|
"SELECT file FROM applied_schema_deltas WHERE version >= ?",
|
||||||
(current_version,)
|
(current_version,)
|
||||||
)
|
)
|
||||||
return current_version, txn.fetchall(), upgraded
|
return current_version, txn.fetchall(), upgraded
|
||||||
|
|
|
@ -21,10 +21,10 @@ CREATE TABLE IF NOT EXISTS schema_version(
|
||||||
CONSTRAINT schema_version_lock_uniq UNIQUE (Lock)
|
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,
|
version INTEGER NOT NULL,
|
||||||
file TEXT NOT NULL,
|
file TEXT NOT NULL,
|
||||||
CONSTRAINT schema_deltas_ver_file UNIQUE (version, file) ON CONFLICT IGNORE
|
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