Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serializable isolation db connection for postgres #6591

Merged
merged 4 commits into from
Apr 2, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion kolibri/deployment/default/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
from kolibri.utils import i18n
from kolibri.utils.logger import get_logging_config

try:
isolation_level = None
import psycopg2 # noqa

isolation_level = psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE
except ImportError:
pass


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
# import kolibri, so we can get the path to the module.
Expand Down Expand Up @@ -152,7 +160,16 @@
"USER": conf.OPTIONS["Database"]["DATABASE_USER"],
"HOST": conf.OPTIONS["Database"]["DATABASE_HOST"],
"PORT": conf.OPTIONS["Database"]["DATABASE_PORT"],
}
},
"default-serializable": {
"ENGINE": "django.db.backends.postgresql",
"NAME": conf.OPTIONS["Database"]["DATABASE_NAME"],
"PASSWORD": conf.OPTIONS["Database"]["DATABASE_PASSWORD"],
"USER": conf.OPTIONS["Database"]["DATABASE_USER"],
"HOST": conf.OPTIONS["Database"]["DATABASE_HOST"],
"PORT": conf.OPTIONS["Database"]["DATABASE_PORT"],
"OPTIONS": {"isolation_level": isolation_level},
},
}


Expand Down
19 changes: 18 additions & 1 deletion kolibri/deployment/default/settings/postgres_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@

from .test import * # noqa

try:
isolation_level = None
import psycopg2 # noqa

isolation_level = psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE
except ImportError:
pass


DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"USER": "postgres",
"PASSWORD": "",
"NAME": os.environ.get("POSTGRES_DB") or "default", # noqa
"TEST": {"NAME": "travis_ci_default"},
}
},
"default-serializable": {
"ENGINE": "django.db.backends.postgresql",
"USER": "postgres",
"PASSWORD": "",
"NAME": os.environ.get("POSTGRES_DB") or "default", # noqa
"OPTIONS": {"isolation_level": isolation_level},
"TEST": {"NAME": "travis_ci_default"},
},
}
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kolibri_exercise_perseus_plugin==1.3.0
jsonfield==2.0.2
requests-toolbelt==0.8.0
clint==0.5.1
morango==0.4.9
morango==0.4.12
tzlocal==1.5.1
pytz==2018.5
python-dateutil==2.7.5
Expand Down