Projet

Général

Profil

0001-misc-drop-sqlit-support-postgresql-only-56148.patch

Lauréline Guérin, 13 août 2021 12:44

Télécharger (7,8 ko)

Voir les différences:

Subject: [PATCH] misc: drop sqlit support - postgresql only (#56148)

 .gitignore                                    |  1 -
 README                                        |  2 +-
 .../0052_event_date_range_constraint.py       |  2 --
 .../0053_event_date_range_constraint.py       |  2 --
 chrono/settings.py                            |  3 +--
 chrono/utils/db.py                            | 20 +++++++++----------
 tests/settings.py                             |  2 +-
 tests/test_ensure_jsonbfields.py              |  1 -
 tests/test_misc.py                            |  9 ---------
 tox.ini                                       |  3 +--
 10 files changed, 13 insertions(+), 32 deletions(-)
.gitignore
1 1
*.pyc
2 2
*.mo
3 3
local_settings.py
4
/db.sqlite3
5 4
/dist
6 5
/chrono.egg-info
7 6
/chrono/manager/static/css/style.css
README
13 13
 $ pip install -r requirements.txt
14 14

  
15 15
It's then required to get the database configured (./manage.py migrate); by
16
default it will create a db.sqlite3 file.
16
default it will create a postgresqsl DB.
17 17

  
18 18
You can then run the Django test server for a quick try (you should refer to
19 19
the Django documentation for production deployments).
chrono/agendas/migrations/0052_event_date_range_constraint.py
102 102
    operations = [migrations.RunSQL(sql=sql_forwards, reverse_sql=sql_backwards)]
103 103

  
104 104
    def _check_db(self, project_state, schema_editor):
105
        if schema_editor.connection.vendor != 'postgresql':
106
            return project_state
107 105
        try:
108 106
            with transaction.atomic():
109 107
                try:
chrono/agendas/migrations/0053_event_date_range_constraint.py
22 22
    operations = [migrations.RunSQL(sql=sql_forwards, reverse_sql=sql_backwards)]
23 23

  
24 24
    def _check_db(self, project_state, schema_editor):
25
        if schema_editor.connection.vendor != 'postgresql':
26
            return project_state
27 25
        try:
28 26
            with transaction.atomic():
29 27
                try:
chrono/settings.py
82 82

  
83 83
DATABASES = {
84 84
    'default': {
85
        'ENGINE': 'django.db.backends.sqlite3',
86
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
85
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
87 86
    }
88 87
}
89 88

  
chrono/utils/db.py
14 14
# You should have received a copy of the GNU Affero General Public License
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17
from django.db import connection
18 17
from django.db.migrations.operations.base import Operation
19 18

  
20 19

  
......
30 29
        pass
31 30

  
32 31
    def database_forwards(self, app_label, schema_editor, from_state, to_state):
33
        if connection.vendor == 'postgresql':
34
            model = from_state.apps.get_model(app_label, self.model_name)
35
            table_name = model._meta.db_table
36
            field = model._meta.get_field(self.field_name)
37
            _, column_name = field.get_attname_column()
38
            with schema_editor.connection.cursor() as cursor:
39
                cursor.execute(
40
                    'ALTER TABLE {table} ALTER COLUMN {col} TYPE jsonb USING {col}::jsonb;'.format(
41
                        table=table_name, col=column_name
42
                    )
32
        model = from_state.apps.get_model(app_label, self.model_name)
33
        table_name = model._meta.db_table
34
        field = model._meta.get_field(self.field_name)
35
        _, column_name = field.get_attname_column()
36
        with schema_editor.connection.cursor() as cursor:
37
            cursor.execute(
38
                'ALTER TABLE {table} ALTER COLUMN {col} TYPE jsonb USING {col}::jsonb;'.format(
39
                    table=table_name, col=column_name
43 40
                )
41
            )
44 42

  
45 43
    def database_backwards(self, app_label, schema_editor, from_state, to_state):
46 44
        pass
tests/settings.py
10 10

  
11 11
DATABASES = {
12 12
    'default': {
13
        'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'),
13
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
14 14
        'TEST': {
15 15
            'NAME': 'chrono-test-%s' % os.environ.get("BRANCH_NAME", "").replace('/', '-')[:63],
16 16
        },
tests/test_ensure_jsonbfields.py
5 5
pytestmark = pytest.mark.django_db
6 6

  
7 7

  
8
@pytest.mark.skipif(connection.vendor != 'postgresql', reason='only postgresql is supported')
9 8
def test_ensure_jsonb_fields():
10 9
    json_fields = (
11 10
        'extra_data',
tests/test_misc.py
31 31

  
32 32

  
33 33
def test_event_ignore_reason():
34
    if connection.vendor != 'postgresql':
35
        pytest.skip('postgresql required')
36

  
37 34
    agenda = Agenda.objects.create(label='Meetings', kind='meetings')
38 35
    meeting_type = MeetingType.objects.create(agenda=agenda, label='Foo', duration=60)
39 36
    desk = Desk.objects.create(agenda=agenda, label='Desk')
......
62 59

  
63 60

  
64 61
def test_event_end_datetime():
65
    if connection.vendor != 'postgresql':
66
        pytest.skip('postgresql required')
67

  
68 62
    agenda = Agenda.objects.create(label='Meetings', kind='meetings')
69 63
    meeting_type1 = MeetingType.objects.create(agenda=agenda, label='Foo', duration=60)
70 64
    meeting_type2 = MeetingType.objects.create(agenda=agenda, label='Foo', duration=45)
......
101 95

  
102 96

  
103 97
def test_meeting_event_exclusion_constraint():
104
    if connection.vendor != 'postgresql':
105
        pytest.skip('postgresql required')
106

  
107 98
    agenda = Agenda.objects.create(label='Meetings', kind='meetings')
108 99
    meeting_type1 = MeetingType.objects.create(agenda=agenda, label='Foo 1', duration=60)
109 100
    meeting_type2 = MeetingType.objects.create(agenda=agenda, label='Foo 2', duration=30)
tox.ini
1 1
[tox]
2
envlist = py3-django22-pg-codestyle-coverage-pylint
2
envlist = py3-django22-codestyle-coverage-pylint
3 3
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/chrono/{env:BRANCH_NAME:}
4 4

  
5 5
[testenv]
......
12 12
  BRANCH_NAME={env:BRANCH_NAME:}
13 13
  SETUPTOOLS_USE_DISTUTILS=stdlib
14 14
  coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml --cov-report html --cov=chrono/
15
  pg: DB_ENGINE=django.db.backends.postgresql_psycopg2
16 15
deps =
17 16
  pytest-cov
18 17
  pytest-django
19
-