mirror of
https://github.com/ansible/awx.git
synced 2026-01-23 23:41:23 -03:30
Updating old migrations for psycopg3
We have both psycopg2 and 3 installed in the AWX venv. Old versions of Django only used psycopg2 but 4.2 now supports 3 Django 4.2 detects psycopg3 first and will use that over psycopg2 So old migrations needed to be updated to support psycopg3
This commit is contained in:
parent
27024378bc
commit
c3045b1169
@ -3,7 +3,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
# Psycopg2
|
||||
from psycopg2.extensions import AsIs
|
||||
from psycopg import sql
|
||||
|
||||
# Django
|
||||
from django.db import connection, migrations, models, OperationalError, ProgrammingError
|
||||
@ -136,7 +136,11 @@ class Migration(migrations.Migration):
|
||||
),
|
||||
),
|
||||
migrations.RunSQL(
|
||||
[("CREATE INDEX host_ansible_facts_default_gin ON %s USING gin" "(ansible_facts jsonb_path_ops);", [AsIs(Host._meta.db_table)])],
|
||||
[
|
||||
"CREATE INDEX host_ansible_facts_default_gin ON {} USING gin(ansible_facts jsonb_path_ops);".format(
|
||||
sql.Identifier(Host._meta.db_table).as_string(connection.cursor())
|
||||
)
|
||||
],
|
||||
[('DROP INDEX host_ansible_facts_default_gin;', None)],
|
||||
),
|
||||
# SCM file-based inventories
|
||||
|
||||
@ -22,10 +22,8 @@ def migrate_event_data(apps, schema_editor):
|
||||
# recreate counter for the new table's primary key to
|
||||
# start where the *old* table left off (we have to do this because the
|
||||
# counter changed from an int to a bigint)
|
||||
cursor.execute(f'DROP SEQUENCE IF EXISTS "{tblname}_id_seq" CASCADE;')
|
||||
cursor.execute(f'CREATE SEQUENCE "{tblname}_id_seq";')
|
||||
cursor.execute(f'ALTER TABLE "{tblname}" ALTER COLUMN "id" ' f"SET DEFAULT nextval('{tblname}_id_seq');")
|
||||
cursor.execute(f"SELECT setval('{tblname}_id_seq', (SELECT MAX(id) FROM _old_{tblname}), true);")
|
||||
cursor.execute(f'CREATE SEQUENCE IF NOT EXISTS "{tblname}_id_seq";')
|
||||
cursor.execute(f"SELECT setval('{tblname}_id_seq', COALESCE((SELECT MAX(id)+1 FROM _old_{tblname}), 1), false);")
|
||||
cursor.execute(f'DROP TABLE _old_{tblname};')
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user