bmc_hub/migrations/200_internet_ip_unique.sql
Christian 3311b8e590 Add comprehensive tests for internet connections module, invoice parsing, and subscription provisioning
- Implement tests for the internet connections module, covering routes, IP range creation, and connection validation.
- Add tests for the Invoice2DataService to validate extraction from GlobalConnect invoices.
- Create tests for subscription network provisioning, ensuring proper handling of network items and IP allocations.
- Include validation checks for subtotal mismatches and ensure error handling for missing IP selections.
2026-07-09 23:44:30 +02:00

32 lines
919 B
SQL

WITH ranked AS (
SELECT
id,
ip_address,
ROW_NUMBER() OVER (
PARTITION BY ip_address
ORDER BY
CASE WHEN deleted_at IS NULL THEN 0 ELSE 1 END,
id
) AS row_no
FROM internet_connections_ip_addresses
),
duplicates AS (
SELECT id
FROM ranked
WHERE row_no > 1
)
UPDATE internet_connections_ip_addresses ipa
SET deleted_at = CURRENT_TIMESTAMP,
updated_at = CURRENT_TIMESTAMP,
comment = CONCAT(
COALESCE(ipa.comment, ''),
CASE WHEN COALESCE(ipa.comment, '') = '' THEN '' ELSE E'\n' END,
'Automatisk deaktiveret som dublet-IP før unikregel.'
)
WHERE ipa.id IN (SELECT id FROM duplicates)
AND ipa.deleted_at IS NULL;
CREATE UNIQUE INDEX IF NOT EXISTS uq_internet_connections_ip_addresses_ip_address_active
ON internet_connections_ip_addresses (ip_address)
WHERE deleted_at IS NULL;