mirror of
https://github.com/ansible/awx.git
synced 2026-05-10 02:47:36 -02:30
bump partition migration to 135
This commit is contained in:
@@ -19,35 +19,24 @@ def migrate_event_data(apps, schema_editor):
|
|||||||
# All events for a given job should be placed in
|
# All events for a given job should be placed in
|
||||||
# a partition based on the job's _created time_.
|
# a partition based on the job's _created time_.
|
||||||
|
|
||||||
for tblname in (
|
for tblname in ('main_jobevent', 'main_inventoryupdateevent', 'main_projectupdateevent', 'main_adhoccommandevent', 'main_systemjobevent'):
|
||||||
'main_jobevent', 'main_inventoryupdateevent',
|
|
||||||
'main_projectupdateevent', 'main_adhoccommandevent',
|
|
||||||
'main_systemjobevent'
|
|
||||||
):
|
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
# mark existing table as _unpartitioned_*
|
# mark existing table as _unpartitioned_*
|
||||||
# we will drop this table after its data
|
# we will drop this table after its data
|
||||||
# has been moved over
|
# has been moved over
|
||||||
cursor.execute(
|
cursor.execute(f'ALTER TABLE {tblname} RENAME TO _unpartitioned_{tblname}')
|
||||||
f'ALTER TABLE {tblname} RENAME TO _unpartitioned_{tblname}'
|
|
||||||
)
|
|
||||||
|
|
||||||
# create a copy of the table that we will use as a reference for schema
|
# create a copy of the table that we will use as a reference for schema
|
||||||
# otherwise, the schema changes we would make on the old jobevents table
|
# otherwise, the schema changes we would make on the old jobevents table
|
||||||
# (namely, dropping the primary key constraint) would cause the migration
|
# (namely, dropping the primary key constraint) would cause the migration
|
||||||
# to suffer a serious performance degradation
|
# to suffer a serious performance degradation
|
||||||
cursor.execute(
|
cursor.execute(f'CREATE TABLE tmp_{tblname} ' f'(LIKE _unpartitioned_{tblname} INCLUDING ALL)')
|
||||||
f'CREATE TABLE tmp_{tblname} '
|
|
||||||
f'(LIKE _unpartitioned_{tblname} INCLUDING ALL)'
|
|
||||||
)
|
|
||||||
|
|
||||||
# drop primary key constraint; in a partioned table
|
# drop primary key constraint; in a partioned table
|
||||||
# constraints must include the partition key itself
|
# constraints must include the partition key itself
|
||||||
# TODO: do more generic search for pkey constraints
|
# TODO: do more generic search for pkey constraints
|
||||||
# instead of hardcoding this one that applies to main_jobevent
|
# instead of hardcoding this one that applies to main_jobevent
|
||||||
cursor.execute(
|
cursor.execute(f'ALTER TABLE tmp_{tblname} DROP CONSTRAINT tmp_{tblname}_pkey')
|
||||||
f'ALTER TABLE tmp_{tblname} DROP CONSTRAINT tmp_{tblname}_pkey'
|
|
||||||
)
|
|
||||||
|
|
||||||
# create parent table
|
# create parent table
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
@@ -63,14 +52,10 @@ def migrate_event_data(apps, schema_editor):
|
|||||||
cursor.execute(f'DROP INDEX IF EXISTS {tblname}_job_id_brin_idx;')
|
cursor.execute(f'DROP INDEX IF EXISTS {tblname}_job_id_brin_idx;')
|
||||||
|
|
||||||
# recreate primary key constraint
|
# recreate primary key constraint
|
||||||
cursor.execute(
|
cursor.execute(f'ALTER TABLE ONLY {tblname} ' f'ADD CONSTRAINT {tblname}_pkey_new PRIMARY KEY (id, job_created);')
|
||||||
f'ALTER TABLE ONLY {tblname} '
|
|
||||||
f'ADD CONSTRAINT {tblname}_pkey_new PRIMARY KEY (id, job_created);'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class FakeAddField(migrations.AddField):
|
class FakeAddField(migrations.AddField):
|
||||||
|
|
||||||
def database_forwards(self, *args):
|
def database_forwards(self, *args):
|
||||||
# this is intentionally left blank, because we're
|
# this is intentionally left blank, because we're
|
||||||
# going to accomplish the migration with some custom raw SQL
|
# going to accomplish the migration with some custom raw SQL
|
||||||
@@ -80,7 +65,7 @@ class FakeAddField(migrations.AddField):
|
|||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('main', '0131_undo_org_polymorphic_ee'),
|
('main', '0134_unifiedjob_ansible_version'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -211,9 +211,8 @@ def memoize_delete(function_name):
|
|||||||
@memoize(ttl=3600 * 24) # in practice, we only need this to load once at process startup time
|
@memoize(ttl=3600 * 24) # in practice, we only need this to load once at process startup time
|
||||||
def get_event_partition_epoch():
|
def get_event_partition_epoch():
|
||||||
from django.db.migrations.recorder import MigrationRecorder
|
from django.db.migrations.recorder import MigrationRecorder
|
||||||
return MigrationRecorder.Migration.objects.filter(
|
|
||||||
app='main', name='0132_event_partitions'
|
return MigrationRecorder.Migration.objects.filter(app='main', name='0135_event_partitions').first().applied
|
||||||
).first().applied
|
|
||||||
|
|
||||||
|
|
||||||
@memoize()
|
@memoize()
|
||||||
|
|||||||
Reference in New Issue
Block a user