Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a Django management command to migrate Garmin InReach v1 bridge integrations to the Gundi v2 system. The migration handles both InReach-to-EarthRanger and EarthRanger-to-InReach workflows with detailed logging and error handling.
- Creates a new management command (
inreach_migration_script.py) with transaction-based migration logic - Supports selective migration via command-line options (
--inbounds,--max,--all) - Implements comprehensive error handling and migration summary reporting
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
cdip_admin/integrations/management/commands/inreach_migration_script.py
Outdated
Show resolved
Hide resolved
cdip_admin/integrations/management/commands/inreach_migration_script.py
Outdated
Show resolved
Hide resolved
| # TODO: FOR LOCAL EXECUTION ONLY! Remove if running in pod | ||
| logging.getLogger('django.db.backends').setLevel(logging.WARNING) | ||
| logging.getLogger('activity_log.mixins').setLevel(logging.ERROR) | ||
| logging.getLogger('integrations.tasks').setLevel(logging.WARNING) |
There was a problem hiding this comment.
The TODO comment indicates this logging configuration should be removed for production. Consider removing these lines or making them conditional based on environment variables to avoid accidentally running with modified logging levels in production.
…script.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…script.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
cdip_admin/integrations/management/commands/inreach_migration_script.py
Outdated
Show resolved
Hide resolved
| route_config, _ = RouteConfiguration.objects.get_or_create( | ||
| name=integration.default_route.name + " - Default Configuration", | ||
| defaults={ | ||
| "data": field_mappings_result | ||
| } | ||
| ) |
There was a problem hiding this comment.
I'm still puzzled by this. I think it still leaves open the chance to get an invalid Route Configuration assignment.
You might consider just creating a new one regardless of whether one exists. Or if you absolutely need to use get_or_create with name as the lookup, then do this:
Use integration's ID in the name rather than the human-friendly name. This to ensure it's not associated with a different route.
Consider what will happen if you do get an existing RouteConfiguration. If you do, this current code is not going to update the field mapping. But I suspect that's what you were intending.
There was a problem hiding this comment.
Alternatively, we could force-update the route_config to ensure the field mapping is set properly. As it is now, the value in defaults will only be applied if the route config was created, then leaving old values if re-used.
There was a problem hiding this comment.
I think using integration's ID in the name for searching/creating the route config and if a route config is still found, an update should be done to ensure the data is correct
chrisdoehring
left a comment
There was a problem hiding this comment.
@vgarcia13 I left some comments. please have a look.
…script.py Co-authored-by: Chris Doehring <chrisdoehring@gmail.com>
Relevant Link
https://allenai.atlassian.net/browse/GUNDI-4683
This pull request adds a new Django management command script to automate the migration of Garmin InReach v1 integrations to the Gundi v2 system. The script handles the migration of integration records, configuration, and routing for both InReach-to-EarthRanger and EarthRanger-to-InReach workflows, providing detailed logging and error handling throughout the process.
Key additions and features:
Migration Command Implementation:
inreach_migration_script.py) that migrates Garmin InReach v1 bridge integrations to the v2 integration model, including organizations, integrations, actions, configurations, and routes.Command-line Options and Filtering:
--inbounds,--max, and--alloptions.Migration Logic and Error Handling:
Integration and Configuration Creation:
Organization,Integration,IntegrationAction,IntegrationConfiguration,Route, andRouteConfiguration, ensuring proper association and field mapping between