mirror of
https://github.com/ansible/awx.git
synced 2026-04-07 02:59:21 -02:30
Drop primary key index before creating partition table
* Partition tables require unique contstraints to include the partition key (uniqueness can only be enforced _inside_ of a given partition table)
This commit is contained in:
@@ -37,13 +37,27 @@ def migrate_event_data(apps, schema_editor):
|
|||||||
f'ALTER TABLE {tblname} RENAME TO {tblname}_old'
|
f'ALTER TABLE {tblname} RENAME TO {tblname}_old'
|
||||||
)
|
)
|
||||||
|
|
||||||
# hacky creation of parent table for partition
|
# drop primary key constraint; in a partioned table
|
||||||
|
# constraints must include the partition key itself
|
||||||
|
# TODO: do more generic search for pkey constraints
|
||||||
|
# instead of hardcoding this one that applies to main_jobevent
|
||||||
|
cursor.execute(
|
||||||
|
f'ALTER TABLE {tblname}_old DROP CONSTRAINT {tblname}_pkey1'
|
||||||
|
)
|
||||||
|
|
||||||
|
# create parent table
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
f'CREATE TABLE {tblname} '
|
f'CREATE TABLE {tblname} '
|
||||||
f'(LIKE {tblname}_old INCLUDING ALL, job_created TIMESTAMP WITH TIME ZONE NOT NULL) '
|
f'(LIKE {tblname}_old INCLUDING ALL, job_created TIMESTAMP WITH TIME ZONE NOT NULL) '
|
||||||
f'PARTITION BY RANGE(job_created);'
|
f'PARTITION BY RANGE(job_created);'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# recreate primary key constraint
|
||||||
|
cursor.execute(
|
||||||
|
f'ALTER TABLE ONLY {tblname} '
|
||||||
|
f'ADD CONSTRAINT {tblname}_pkey PRIMARY KEY (id, job_created);'
|
||||||
|
)
|
||||||
|
|
||||||
# .. as well as initial partition containing all existing events
|
# .. as well as initial partition containing all existing events
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
f'CREATE TABLE {tblname}_part0 '
|
f'CREATE TABLE {tblname}_part0 '
|
||||||
|
|||||||
Reference in New Issue
Block a user