Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
23d62ede
"src/api/client_server/alias.rs" did not exist on "1e8fbd8d50c1bf0fe80cb77b8df8b5a45c3698f5"
Commit
23d62ede
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Clean up prepare_database.py a bit and add comments
parent
6cc497f9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/prepare_database.py
+30
-7
30 additions, 7 deletions
synapse/storage/prepare_database.py
with
30 additions
and
7 deletions
synapse/storage/prepare_database.py
+
30
−
7
View file @
23d62ede
...
...
@@ -97,7 +97,8 @@ def prepare_database(db_conn, database_engine, config):
def
_setup_new_database
(
cur
,
database_engine
,
data_stores
):
"""
Sets up the database by finding a base set of
"
full schemas
"
and then
applying any necessary deltas.
applying any necessary deltas, including schemas from the given data
stores.
The
"
full_schemas
"
directory has subdirectories named after versions. This
function searches for the highest version less than or equal to
...
...
@@ -122,6 +123,15 @@ def _setup_new_database(cur, database_engine, data_stores):
In the example foo.sql and bar.sql would be run, and then any delta files
for versions strictly greater than 11.
Note: we apply the full schemas and deltas from the top level `schema/`
folder as well those in the data stores specified.
Args:
cur (Cursor): a database cursor
database_engine (DatabaseEngine)
data_stores (list[str]): The names of the data stores to instantiate
on the given database.
"""
current_dir
=
os
.
path
.
join
(
dir_path
,
"
schema
"
,
"
full_schemas
"
)
directory_entries
=
os
.
listdir
(
current_dir
)
...
...
@@ -245,6 +255,10 @@ def _upgrade_existing_database(
only if `upgraded` is True. Then `foo.sql` and `bar.py` would be run in
some arbitrary order.
Note: we apply the delta files from the specified data stores as well as
those in the top-level schema. We apply all delta files across data stores
for a version before applying those in the next version.
Args:
cur (Cursor)
current_version (int): The current version of the schema.
...
...
@@ -254,6 +268,14 @@ def _upgrade_existing_database(
applied deltas or from full schema file. If `True` the function
will never apply delta files for the given `current_version`, since
the current_version wasn
'
t generated by applying those delta files.
database_engine (DatabaseEngine)
config (synapse.config.homeserver.HomeServerConfig|None):
application config, or None if we are connecting to an existing
database which we expect to be configured already
data_stores (list[str]): The names of the data stores to instantiate
on the given database.
is_empty (bool): Is this a blank database? I.e. do we need to run the
upgrade portions of the delta scripts.
"""
if
current_version
>
SCHEMA_VERSION
:
...
...
@@ -305,21 +327,19 @@ def _upgrade_existing_database(
# Data stores can have empty entries for a given version delta.
pass
except
OSError
:
logger
.
exception
(
"
Could not open delta dir for version %d
"
,
v
)
raise
UpgradeDatabaseException
(
"
Could not open delta dir for version %d
"
%
(
v
,)
"
Could not open delta dir for version %d
: %s
"
%
(
v
,
directory
)
)
if
not
directory_entries
:
continue
# We sort to ensure that we apply the delta files in a consistent
# order (to avoid bugs caused by inconsistent directory listing order)
directory_entries
.
sort
()
for
entry
in
directory_entries
:
file_name
=
entry
.
file_name
relative_path
=
os
.
path
.
join
(
str
(
v
),
file_name
)
absolute_path
=
entry
.
absolute_path
logger
.
debug
(
"
Found file: %s
"
,
relative_path
)
logger
.
debug
(
"
Found file: %s
(%s)
"
,
relative_path
,
absolute_path
)
if
relative_path
in
applied_delta_files
:
continue
...
...
@@ -511,6 +531,9 @@ def _get_or_create_schema_state(txn, database_engine):
class
_DirectoryListing
(
object
):
"""
Helper class to store schema file name and the
absolute path to it.
These entries get sorted, so for consistency we want to ensure that
`file_name` attr is kept first.
"""
file_name
=
attr
.
ib
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment