One time Fix Script to create relationship

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2024 04:21 AM
Hi,
I wanted to write a one time fix script to create relationship between cmdb_ci_ec2_instance table and corresponding cmdb_ci_aws_account ci (this is a reference field in the form of ec2 instance record) if the install status of ec2 instance record is 'Installed''. I've prepared a fix script as below -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2024 04:46 AM
How many installed ec2 instance records do you have? When running the script do you suddenly have many new relationship records? If so, are they correct or the same parent/child?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2024 06:00 AM
Hi @Brad Bowman ,
Total I've 2.5 lac of records are there in cmdb_ci_ec2_instance table and out of which around 7k are having install status = installed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2024 06:41 AM
Are you seeing the start of 7K relationship records get created when you attempted to run this, or what happened while it was running for awhile? You can add a line to test prior to the ec2.query() if you are uncertain:
ec2.setLimit(10);
There are probably Business Rules that are running with each insert, and you probably want to allow those to run. This will likely cause a performance hit with 7K insertions, so best to schedule it during off hours.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2024 05:07 AM
Hi @Bijay Kumar Sha,
When you run this script, is it creating the relationships as you want? and It's running continuously because your 'cmdb_ci_ec2_instance' table has many records with 'install_status=1'. When the condition is no longer satisfied, it will automatically stop running. Your code is very simple, so I don't see any issues with it, and it doesn't impact performance either.