mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 07:17:40 -02:30
Give new primary key constraint unique name, create first live partition
This commit is contained in:
@@ -60,12 +60,18 @@ def migrate_event_data(apps, schema_editor):
|
|||||||
# recreate primary key constraint
|
# recreate primary key constraint
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
f'ALTER TABLE ONLY {tblname} '
|
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
|
# .. as well as initial partition containing all existing events
|
||||||
epoch = datetime(1980, 1, 1, 0, 0)
|
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
|
# copy over all job events into partitioned table
|
||||||
# TODO: https://github.com/ansible/awx/issues/9257
|
# 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)
|
return stdout + u'\u001b[0m' * (set_count - reset_count)
|
||||||
|
|
||||||
|
|
||||||
def deepmerge(a, b):
|
def deepmerge(a, b):
|
||||||
"""
|
"""
|
||||||
Merge dict structures and return the result.
|
Merge dict structures and return the result.
|
||||||
@@ -1027,12 +1026,16 @@ def deepmerge(a, b):
|
|||||||
return b
|
return b
|
||||||
|
|
||||||
|
|
||||||
def create_partition(partition_label, start, end=None):
|
def create_partition(start, end=None, partition_label=None):
|
||||||
"""Creates new partition tables for events."""
|
"""Creates new partition tables for events.
|
||||||
|
If not specified, end is set to the end of the current hour."""
|
||||||
if not end:
|
if not end:
|
||||||
end = (now() + timedelta(hours=1))
|
end = start.replace(microsecond=0, second=0, minute=0) + timedelta(hours=1)
|
||||||
start_timestamp = start.strftime('%Y-%m-%d %H:00:00.000000%z')
|
start_timestamp = str(start)
|
||||||
end_timestamp = end.strftime('%Y-%m-%d %H:00:00.000000%z')
|
end_timestamp = str(end)
|
||||||
|
|
||||||
|
if not partition_label:
|
||||||
|
partition_label = start.strftime('%Y_%m_%d_%H')
|
||||||
|
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
# Only partitioning main_jobevent on first pass
|
# Only partitioning main_jobevent on first pass
|
||||||
|
|||||||
Reference in New Issue
Block a user