Compare commits

...

1 Commits

Author SHA1 Message Date
Frédéric Péters 247f091b80 migrations: don't check existing type before jsonb migration (#43131)
gitea-wip/passerelle/pipeline/head There was a failure building this commit Details
gitea/passerelle/pipeline/head Something is wrong with the build of this commit Details
2020-05-20 09:56:36 +02:00
1 changed files with 2 additions and 9 deletions

View File

@ -35,16 +35,9 @@ class EnsureJsonbType(Operation):
_, column_name = field.get_attname_column()
with schema_editor.connection.cursor() as cursor:
cursor.execute(
'SELECT data_type FROM information_schema.columns WHERE table_name = %s AND '
'column_name = %s;', (table_name, column_name)
'ALTER TABLE {table} ALTER COLUMN {col} TYPE jsonb USING {col}::jsonb;'
.format(table=table_name, col=column_name)
)
current_type = cursor.fetchone()[0].lower()
if current_type != 'jsonb':
assert current_type in ('json', 'text')
cursor.execute(
'ALTER TABLE {table} ALTER COLUMN {col} TYPE jsonb USING {col}::jsonb;'
.format(table=table_name, col=column_name)
)
def database_backwards(self, app_label, schema_editor, from_state, to_state):
pass