mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-05 16:01:50 -05:00
migrate data from mongo to postgres
This commit is contained in:
21
awx/main/migrations/_system_tracking.py
Normal file
21
awx/main/migrations/_system_tracking.py
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
from awx.fact.models import FactVersion
|
||||
|
||||
def migrate_facts(apps, schema_editor):
|
||||
Fact = apps.get_model('main', "Fact")
|
||||
Host = apps.get_model('main', "Host")
|
||||
|
||||
migrated_count = 0
|
||||
not_migrated_count = 0
|
||||
for factver in FactVersion.objects.all():
|
||||
fact_obj = factver.fact
|
||||
try:
|
||||
host = Host.objects.only('id').get(inventory__id=factver.host.inventory_id, name=factver.host.hostname)
|
||||
Fact.objects.create(host_id=host.id, timestamp=fact_obj.timestamp, module=fact_obj.module, facts=fact_obj.fact).save()
|
||||
migrated_count += 1
|
||||
except Host.DoesNotExist:
|
||||
# TODO: Log this. No host was found to migrate the facts to.
|
||||
# This isn't a hard error. Just something the user would want to know.
|
||||
not_migrated_count += 1
|
||||
|
||||
return (migrated_count, not_migrated_count)
|
||||
Reference in New Issue
Block a user