Wrap CREATE EXTENSION in a PL/pgSQL DO block that catches
insufficient_privilege so the migration completes successfully
even when the DB user is not a superuser.
- Add missing env vars to migration init container (PHX_HOST, PORT,
APRS_PORT, APRS_CALLSIGN, APRS_PASSCODE) so runtime.exs config
provider doesn't fail due to Kubernetes service discovery injecting
APRS_PORT as a full URL
- Guard ConnectionMonitor.accepting_connections?/0 with Process.whereis
to avoid crashing when the GenServer isn't started (e.g. cluster
enabled but no libcluster topologies configured)
Adds an init container that runs `bin/migrate` before app pods start,
ensuring migrations are applied on every deployment. Uses the existing
advisory lock in MigrationLock so only one pod runs migrations during
a rolling update.
Kubernetes manifests for deploying to home cluster in the aprs
namespace with Forgejo Actions CI pipeline for building and
pushing container images to git.mcintire.me registry.
Replace case/cond/if blocks with multi-clause function dispatch
and pattern matching in function heads across 9 modules:
- WeatherUnits: case to multi-clause unit_system/1, unit_labels via do_unit_labels/1
- PacketUtils: if to pattern match on %{"id" => id}, multi-clause threshold/callsign
- SetLocale: case to multi-clause extract_locale/1
- IPGeolocation: if/cond to pattern match on conn, binary prefix matching for private_ip?
- DeviceIdentification: cond to extracted pattern_matches?/2
- MobileChannel: cond to multi-clause do_callsign_match/2
- PacketProcessor: cond to dispatch_visibility/6 on {in_bounds, has_marker} tuple
- PacketManager: destructure packet_state in heads, multi-clause maybe_cleanup/3
- AprsSymbol: case/if to multi-clause get_table_id/1, normalize_symbol_code/1
Resolves the final 5 Credo cyclomatic complexity issues by:
1. packet.ex: Create get_field_value/2 helper function
- Replaces all `data[:field] || data["field"]` patterns
- Reduces complexity in put_equipment_fields (11 -> 9)
- Reduces complexity in put_phg_fields (12 -> 9)
- Reduces complexity in put_standard_parser_fields (11 -> 9)
2. query_builder.ex: Use SQL fragment for weather_only query
- Replaces multiple Elixir `or` operators with single SQL fragment
- Reduces complexity from 10 to within limits
3. packet_utils.ex: Use SQL fragment for weather check query
- Replaces multiple Elixir `or` operators with single SQL fragment
- Reduces complexity from 11 to within limits
All 71 Credo issues now resolved:
- 14/14 warnings ✓
- 14/14 design suggestions ✓
- 40/40 refactoring issues ✓
- 3/3 code readability issues ✓
100% Credo compliance achieved!
Extract helper functions to reduce complexity in functions with
complexity 10-15:
- packet.ex: Extract add_symbol_data/2
Moves symbol data extraction into separate function
Reduces complexity from 10 to 9
- mobile_channel.ex: Extract bounds validation helpers
Creates all_numeric?/4, valid_latitudes?/2, valid_longitudes?/2
Moves complex boolean conditions into readable helper functions
Reduces complexity from 15 to within limits
- historical_loader.ex: Extract packet_has_valid_coordinates?/1
Moves coordinate validation logic with multiple conditions
Reduces complexity from 15 to within limits
Fixes 3 more Credo cyclomatic complexity issues.
Extract helper functions to reduce cyclomatic complexity:
- telemetry/database_metrics.ex: Extract emit_packets_table_telemetry/7
Moves multiple || 0 operators into separate function
Reduces complexity from 10 to within limits
- packet_utils.ex: Extract build_weather_check_query/1
Moves Ecto query building with multiple or conditions
Reduces complexity from 11 to within limits
- packet.ex: Extract merge_extracted_data/3
Moves telemetry and parser data merging logic
Reduces complexity from 11 to within limits
Fixes 3 Credo cyclomatic complexity issues (7 remaining).
Extract device attribute addition into helper function to reduce
cyclomatic complexity from 10 to 9:
- callsign_json.ex: Extract add_device_attributes/2 helper
Moves device.model, device.vendor, device.contact, and device.class
attribute additions into separate function
This reduces complexity by isolating the && operators in a dedicated
helper function.
Fixes 1 Credo cyclomatic complexity issue (10 remaining).
Refactor decode_path_element from 217 lines with complexity 72 to clean helpers:
- Add @q_constructs module attribute with all 39 Q-construct descriptions
- Extract decode_wide_element/1 for WIDE digipeater patterns
- Extract decode_trace_element/1 for TRACE digipeater patterns
- Extract decode_relay_element/1 for RELAY digipeater patterns
- Extract decode_tcpip_element/1 for TCPIP gateway patterns
- Main function now has simple map lookup and pattern-based routing
Reduced from 217 lines to 66 lines while improving readability and maintainability.
Co-Authored-By: Graham <noreply@anthropic.com>
Simplify timestamp comparison and weather value formatting:
- Extract compare_timestamps with pattern matching for different types
- Remove duplicate formatter code (was a bug)
- Extract format_string_value and format_numeric_value helpers
Co-Authored-By: Graham <noreply@anthropic.com>
Extract each metric collection into separate helper functions:
- collect_database_size: Database size metrics
- collect_connection_stats: Connection pool statistics
- collect_packets_table_stats: Table-level statistics
- collect_query_performance_stats: Query performance metrics
- collect_replication_lag: Replication lag metrics
This breaks down the complexity 27 function into manageable pieces.
Co-Authored-By: Graham <noreply@anthropic.com>
Extract packet query logic into helper functions:
- query_historical_packets: Main query orchestration with error handling
- build_query_params: Build query parameters with callsign filtering
- maybe_include_latest_packet: Include latest packet for tracked callsigns
This breaks down the complex do_load_historical_batch function.
Co-Authored-By: Graham <noreply@anthropic.com>
Simplify private IP range checking by extracting helper functions:
- is_private_ip?: Check if IP is in private ranges
- is_172_private_range?: Properly check 172.16.0.0/12 range
This replaces 20+ String.starts_with? checks with intelligent range parsing.
Co-Authored-By: Graham <noreply@anthropic.com>
Simplify complex functions to improve readability and maintainability:
- clustering.ex: Convert case statement to map lookup for cluster radii
- encoding.ex: Extract codepoint validation into separate function clauses
- leader_election.ex: Extract PID liveness checking and cleanup logic into helpers
Co-Authored-By: Graham <noreply@anthropic.com>
Extract nested logic into helper functions to improve readability:
- regex_cache.ex: Extract compile_and_cache/1 for regex compilation and caching
- connection_monitor.ex: Extract calculate_scheduler_utilization/1 for CPU stat calculation
- device_identification.ex: Extract fetch_devices_from_url/0 for HTTP request handling
Co-Authored-By: Graham <noreply@anthropic.com>
- Fix length/1 check in mobile_channel.ex
- Add LeaderElection alias in connection_manager.ex
All warnings and design suggestions now complete!
Remaining: 40 refactoring opportunities (complex/nested functions)