File: configuration.py

package info (click to toggle)
python-django-test-migrations 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 1,479; makefile: 26
file content (31 lines) | stat: -rw-r--r-- 1,038 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import cast

from typing_extensions import final

from django_test_migrations.db.backends.base.configuration import (
    BaseDatabaseConfiguration,
)
from django_test_migrations.types import DatabaseSettingValue


@final
class PostgreSQLDatabaseConfiguration(BaseDatabaseConfiguration):
    """Interact with PostgreSQL database configuration."""

    vendor = 'postgresql'
    statement_timeout = 'statement_timeout'

    def get_setting_value(self, name: str) -> DatabaseSettingValue:
        """Retrieve value of PostgreSQL database's setting with ``name``."""
        with self.connection.cursor() as cursor:
            cursor.execute(
                (
                    'SELECT setting FROM pg_settings '  # noqa: S608
                    + 'WHERE name = %s;'
                ),
                (name,),
            )
            setting_value = cursor.fetchone()
            if not setting_value:
                return super().get_setting_value(name)
            return cast(DatabaseSettingValue, setting_value[0])