0003-misc-add-migration-to-ensure-jsonb-type-42312.patch
passerelle/apps/atos_genesys/migrations/0004_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('atos_genesys', '0003_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='Link', field_name='extra'), |
|
18 |
] |
passerelle/apps/base_adresse/migrations/0018_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('base_adresse', '0017_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='AddressCacheModel', field_name='data'), |
|
18 |
] |
passerelle/apps/cartads_cs/migrations/0012_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('cartads_cs', '0011_cartadsdossier_cartads_cache_infos'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='CartaDSDataCache', field_name='data_parameters'), |
|
18 |
EnsureJsonbType(model_name='CartaDSDataCache', field_name='data_values'), |
|
19 |
EnsureJsonbType(model_name='cartadsdossier', field_name='cartads_steps_cache'), |
|
20 |
EnsureJsonbType(model_name='cartadsdossier', field_name='cartads_cache_infos'), |
|
21 |
] |
passerelle/apps/csvdatasource/migrations/0018_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('csvdatasource', '0017_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='csvdatasource', field_name='_dialect_options'), |
|
18 |
EnsureJsonbType(model_name='TableRow', field_name='data'), |
|
19 |
] |
passerelle/apps/gesbac/migrations/0004_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('gesbac', '0003_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='Form', field_name='demand_data'), |
|
18 |
EnsureJsonbType(model_name='Form', field_name='card_data'), |
|
19 |
] |
passerelle/apps/jsondatastore/migrations/0008_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('jsondatastore', '0007_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='JsonData', field_name='content'), |
|
18 |
] |
passerelle/apps/mdel_ddpacs/migrations/0003_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('mdel_ddpacs', '0002_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='Demand', field_name='data'), |
|
18 |
] |
passerelle/apps/opengis/migrations/0011_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('opengis', '0010_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='FeatureCache', field_name='data'), |
|
18 |
] |
passerelle/apps/pastell/migrations/0008_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('pastell', '0007_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='Pastell', field_name='document_fields'), |
|
18 |
] |
passerelle/apps/phonecalls/migrations/0002_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('phonecalls', '0001_initial'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='Call', field_name='details'), |
|
18 |
] |
passerelle/apps/sp_fr/migrations/0003_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('sp_fr', '0002_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='Mapping', field_name='rules'), |
|
18 |
] |
passerelle/base/migrations/0019_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('base', '0018_smslog'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='ResourceLog', field_name='extra'), |
|
18 |
EnsureJsonbType(model_name='Job', field_name='parameters'), |
|
19 |
EnsureJsonbType(model_name='Job', field_name='status_details'), |
|
20 |
] |
passerelle/contrib/fake_family/migrations/0006_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('fake_family', '0005_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='FakeFamily', field_name='jsondatabase'), |
|
18 |
] |
passerelle/contrib/meyzieu_newsletters/migrations/0005_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('meyzieu_newsletters', '0004_remove_meyzieunewsletters_log_level'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='MeyzieuNewsletters', field_name='transport_titles_mapping'), |
|
18 |
] |
passerelle/contrib/planitech/migrations/0006_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('planitech', '0005_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='planitechconnector', field_name='custom_fields'), |
|
18 |
] |
passerelle/contrib/teamnet_axel/migrations/0009_text_to_jsonb.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2020-05-04 12:06 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations |
|
6 | ||
7 |
from passerelle.utils.db import EnsureJsonbType |
|
8 | ||
9 | ||
10 |
class Migration(migrations.Migration): |
|
11 | ||
12 |
dependencies = [ |
|
13 |
('teamnet_axel', '0008_auto_20200504_1402'), |
|
14 |
] |
|
15 | ||
16 |
operations = [ |
|
17 |
EnsureJsonbType(model_name='TeamnetAxel', field_name='billing_regies'), |
|
18 |
] |
passerelle/utils/db.py | ||
---|---|---|
1 |
from django.db.migrations.operations.base import Operation |
|
2 | ||
3 | ||
4 |
class EnsureJsonbType(Operation): |
|
5 | ||
6 |
reversible = False |
|
7 | ||
8 |
def __init__(self, model_name, field_name): |
|
9 |
self.model_name = model_name |
|
10 |
self.field_name = field_name |
|
11 | ||
12 |
def state_forwards(self, app_label, state): |
|
13 |
pass |
|
14 | ||
15 |
def database_forwards(self, app_label, schema_editor, from_state, to_state): |
|
16 |
model = from_state.apps.get_model(app_label, self.model_name) |
|
17 |
table_name = model._meta.db_table |
|
18 |
field = model._meta.get_field(self.field_name) |
|
19 |
_, column_name = field.get_attname_column() |
|
20 |
with schema_editor.connection.cursor() as cursor: |
|
21 |
cursor.execute( |
|
22 |
'SELECT data_type FROM information_schema.columns WHERE table_name = %s AND ' |
|
23 |
'column_name = %s;', (table_name, column_name) |
|
24 |
) |
|
25 |
current_type = cursor.fetchone()[0].lower() |
|
26 |
if current_type != 'jsonb': |
|
27 |
assert current_type in ('json', 'text') |
|
28 |
cursor.execute( |
|
29 |
'ALTER TABLE {table} ALTER COLUMN {col} TYPE jsonb USING {col}::jsonb;' |
|
30 |
.format(table=table_name, col=column_name) |
|
31 |
) |
|
32 | ||
33 |
def describe(self): |
|
34 |
return "Migrate to postgres jsonb type" |
|
0 |
- |