56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
import pytest
|
|
from django.core.management import call_command
|
|
from django.db import connection
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
@pytest.mark.skipif(connection.vendor != 'postgresql', reason='only postgresql is supported')
|
|
def test_ensure_jsonb_fields():
|
|
json_fields = (
|
|
'bank_data',
|
|
'bank_result',
|
|
'cached_json',
|
|
'categories',
|
|
'filter_params',
|
|
'filters',
|
|
'manual_order',
|
|
'parameters',
|
|
'push_notifications_infos',
|
|
'related_cells',
|
|
'request_data',
|
|
'_search_services',
|
|
'serialization',
|
|
'service_options',
|
|
'subscription_info',
|
|
'transaction_options',
|
|
)
|
|
|
|
with connection.cursor() as cursor:
|
|
query = '''SELECT table_name, column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE column_name IN %(json_fields)s'''
|
|
cursor.execute(query, {'json_fields': json_fields})
|
|
|
|
# make sure the data_type is correct
|
|
for line in cursor.fetchall():
|
|
assert line[2] == 'jsonb'
|
|
|
|
# alter columns
|
|
cursor.execute(
|
|
'''ALTER TABLE wcs_wcsformsofcategorycell
|
|
ALTER COLUMN manual_order TYPE text USING manual_order::text'''
|
|
)
|
|
|
|
call_command('ensure_jsonb')
|
|
|
|
with connection.cursor() as cursor:
|
|
query = '''SELECT table_name, column_name, data_type
|
|
FROM information_schema.columns
|
|
WHERE column_name IN %(json_fields)s'''
|
|
cursor.execute(query, {'json_fields': json_fields})
|
|
|
|
# check the data_type is correct
|
|
for line in cursor.fetchall():
|
|
assert line[2] == 'jsonb'
|