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
Container Registry
Model registry
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
Maunium
synapse
Commits
aefa76f5
Commit
aefa76f5
authored
5 years ago
by
Olivier Wilkinson (reivilibre)
Browse files
Options
Downloads
Patches
Plain Diff
Allow schema deltas to be engine-specific
Signed-off-by:
Olivier Wilkinson (reivilibre)
<
olivier@librepush.net
>
parent
8767b63a
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
+21
-5
21 additions, 5 deletions
synapse/storage/prepare_database.py
with
21 additions
and
5 deletions
synapse/storage/prepare_database.py
+
21
−
5
View file @
aefa76f5
...
@@ -238,6 +238,15 @@ def _upgrade_existing_database(
...
@@ -238,6 +238,15 @@ def _upgrade_existing_database(
logger
.
debug
(
"
applied_delta_files: %s
"
,
applied_delta_files
)
logger
.
debug
(
"
applied_delta_files: %s
"
,
applied_delta_files
)
if
isinstance
(
database_engine
,
PostgresEngine
):
specific_engine_extension
=
"
.postgres
"
else
:
specific_engine_extension
=
"
.sqlite
"
specific_engine_extensions
=
(
"
.sqlite
"
,
"
.postgres
"
)
for
v
in
range
(
start_ver
,
SCHEMA_VERSION
+
1
):
for
v
in
range
(
start_ver
,
SCHEMA_VERSION
+
1
):
logger
.
info
(
"
Upgrading schema to v%d
"
,
v
)
logger
.
info
(
"
Upgrading schema to v%d
"
,
v
)
...
@@ -274,15 +283,22 @@ def _upgrade_existing_database(
...
@@ -274,15 +283,22 @@ def _upgrade_existing_database(
# Sometimes .pyc files turn up anyway even though we've
# Sometimes .pyc files turn up anyway even though we've
# disabled their generation; e.g. from distribution package
# disabled their generation; e.g. from distribution package
# installers. Silently skip it
# installers. Silently skip it
pass
continue
elif
ext
==
"
.sql
"
:
elif
ext
==
"
.sql
"
:
# A plain old .sql file, just read and execute it
# A plain old .sql file, just read and execute it
logger
.
info
(
"
Applying schema %s
"
,
relative_path
)
logger
.
info
(
"
Applying schema %s
"
,
relative_path
)
executescript
(
cur
,
absolute_path
)
executescript
(
cur
,
absolute_path
)
elif
ext
==
specific_engine_extension
and
root_name
.
endswith
(
"
.sql
"
):
# A .sql file specific to our engine; just read and execute it
logger
.
info
(
"
Applying engine-specific schema %s
"
,
relative_path
)
executescript
(
cur
,
absolute_path
)
elif
ext
in
specific_engine_extensions
and
root_name
.
endswith
(
"
.sql
"
):
# A .sql file for a different engine; skip it.
continue
else
:
else
:
# Not a valid delta file.
# Not a valid delta file.
logger
.
warn
(
logger
.
warn
ing
(
"
Found directory entry that did not end in .py or
"
"
.sql: %s
"
,
"
Found directory entry that did not end in .py or .sql: %s
"
,
relative_path
,
relative_path
,
)
)
continue
continue
...
@@ -290,7 +306,7 @@ def _upgrade_existing_database(
...
@@ -290,7 +306,7 @@ def _upgrade_existing_database(
# Mark as done.
# Mark as done.
cur
.
execute
(
cur
.
execute
(
database_engine
.
convert_param_style
(
database_engine
.
convert_param_style
(
"
INSERT INTO applied_schema_deltas (version, file)
"
"
VALUES (?,?)
"
"
INSERT INTO applied_schema_deltas (version, file) VALUES (?,?)
"
),
),
(
v
,
relative_path
),
(
v
,
relative_path
),
)
)
...
@@ -298,7 +314,7 @@ def _upgrade_existing_database(
...
@@ -298,7 +314,7 @@ def _upgrade_existing_database(
cur
.
execute
(
"
DELETE FROM schema_version
"
)
cur
.
execute
(
"
DELETE FROM schema_version
"
)
cur
.
execute
(
cur
.
execute
(
database_engine
.
convert_param_style
(
database_engine
.
convert_param_style
(
"
INSERT INTO schema_version (version, upgraded)
"
"
VALUES (?,?)
"
"
INSERT INTO schema_version (version, upgraded) VALUES (?,?)
"
),
),
(
v
,
True
),
(
v
,
True
),
)
)
...
...
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