mirror of
https://github.com/ansible/awx.git
synced 2026-04-05 18:19:21 -02:30
Rename / remove old main_jobevent table
This commit is contained in:
@@ -30,28 +30,39 @@ def migrate_event_data(apps, schema_editor):
|
|||||||
#):
|
#):
|
||||||
for tblname in ('main_jobevent',):
|
for tblname in ('main_jobevent',):
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
|
# mark existing table as *_old;
|
||||||
|
# we will drop this table after its data
|
||||||
|
# has been moved over
|
||||||
|
cursor.execute(
|
||||||
|
f'ALTER TABLE {tblname} RENAME TO {tblname}_old'
|
||||||
|
)
|
||||||
|
|
||||||
# hacky creation of parent table for partition
|
# hacky creation of parent table for partition
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
f'CREATE TABLE {tblname}_parent '
|
f'CREATE TABLE {tblname} '
|
||||||
f'(LIKE {tblname}, job_created TIMESTAMP WITH TIME ZONE NOT NULL) '
|
f'(LIKE {tblname}_old, job_created TIMESTAMP WITH TIME ZONE NOT NULL) '
|
||||||
f'PARTITION BY RANGE(job_created);'
|
f'PARTITION BY RANGE(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 '
|
||||||
f'PARTITION OF {tblname}_parent '
|
f'PARTITION OF {tblname} '
|
||||||
f'FOR VALUES FROM (\'2000-01-01 00:00:00.000000+00\') to (\'2021-02-01 00:00:00.000000+00\');'
|
f'FOR VALUES FROM (\'2000-01-01 00:00:00.000000+00\') to (\'2021-02-01 00:00:00.000000+00\');'
|
||||||
)
|
)
|
||||||
|
|
||||||
# copy over all job events into partitioned table
|
# copy over all job events into partitioned table
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
f'INSERT INTO {tblname}_parent '
|
f'INSERT INTO {tblname} '
|
||||||
f'SELECT {tblname}.*, main_unifiedjob.created '
|
f'SELECT {tblname}_old.*, main_unifiedjob.created '
|
||||||
f'FROM {tblname} '
|
f'FROM {tblname}_old '
|
||||||
f'INNER JOIN main_unifiedjob ON {tblname}.job_id = main_unifiedjob.id;'
|
f'INNER JOIN main_unifiedjob ON {tblname}_old.job_id = main_unifiedjob.id;'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# drop old table
|
||||||
|
cursor.execute(
|
||||||
|
f'DROP TABLE {tblname}_old'
|
||||||
|
)
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
Reference in New Issue
Block a user