mirror of
https://github.com/ansible/awx.git
synced 2026-01-29 23:34:42 -03:30
Give new primary key constraint unique name, create first live partition
This commit is contained in:
parent
ba45592d93
commit
0c289205de
@ -60,12 +60,18 @@ def migrate_event_data(apps, schema_editor):
|
||||
# recreate primary key constraint
|
||||
cursor.execute(
|
||||
f'ALTER TABLE ONLY {tblname} '
|
||||
f'ADD CONSTRAINT {tblname}_pkey PRIMARY KEY (id, job_created);'
|
||||
f'ADD CONSTRAINT {tblname}_pkey_new PRIMARY KEY (id, job_created);'
|
||||
)
|
||||
|
||||
current_time = now()
|
||||
|
||||
# .. as well as initial partition containing all existing events
|
||||
epoch = datetime(1980, 1, 1, 0, 0)
|
||||
create_partition('old_events', epoch, now())
|
||||
create_partition(epoch, current_time, 'old_events')
|
||||
|
||||
# .. and first partition
|
||||
# .. which is a special case, as it only covers remainder of current hour
|
||||
create_partition(current_time)
|
||||
|
||||
# copy over all job events into partitioned table
|
||||
# TODO: https://github.com/ansible/awx/issues/9257
|
||||
|
||||
@ -1009,7 +1009,6 @@ def truncate_stdout(stdout, size):
|
||||
|
||||
return stdout + u'\u001b[0m' * (set_count - reset_count)
|
||||
|
||||
|
||||
def deepmerge(a, b):
|
||||
"""
|
||||
Merge dict structures and return the result.
|
||||
@ -1027,12 +1026,16 @@ def deepmerge(a, b):
|
||||
return b
|
||||
|
||||
|
||||
def create_partition(partition_label, start, end=None):
|
||||
"""Creates new partition tables for events."""
|
||||
def create_partition(start, end=None, partition_label=None):
|
||||
"""Creates new partition tables for events.
|
||||
If not specified, end is set to the end of the current hour."""
|
||||
if not end:
|
||||
end = (now() + timedelta(hours=1))
|
||||
start_timestamp = start.strftime('%Y-%m-%d %H:00:00.000000%z')
|
||||
end_timestamp = end.strftime('%Y-%m-%d %H:00:00.000000%z')
|
||||
end = start.replace(microsecond=0, second=0, minute=0) + timedelta(hours=1)
|
||||
start_timestamp = str(start)
|
||||
end_timestamp = str(end)
|
||||
|
||||
if not partition_label:
|
||||
partition_label = start.strftime('%Y_%m_%d_%H')
|
||||
|
||||
with connection.cursor() as cursor:
|
||||
# Only partitioning main_jobevent on first pass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user