Panel/Website/sql/normalize_billing_order_status.sql

37 lines
1.5 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- normalize_billing_order_status.sql
-- ============================================================
-- Migrate legacy billing_orders.status values to the canonical
-- three-value lifecycle used by GSP billing:
--
-- Active server is provisioned and current
-- Invoiced renewal invoice generated; payment due
-- Expired invoice unpaid past due date; server pending deletion
--
-- Old values and their mappings:
-- installed -> Active (was written by old provisioner)
-- paid -> Active (was written after PayPal capture, before provisioning)
-- suspended -> Expired (was written by old cron when overdue)
--
-- Run this ONCE against the panel database after deploying the updated
-- cron-shop.php and application code. It is safe to re-run (idempotent).
-- ============================================================
-- Map old 'installed' to 'Active'
UPDATE `<PREFIX>billing_orders`
SET `status` = 'Active'
WHERE `status` = 'installed';
-- Map old 'paid' to 'Active'
-- (Orders that were paid but not yet provisioned should be provisioned
-- via the admin orders panel after this migration.)
UPDATE `<PREFIX>billing_orders`
SET `status` = 'Active'
WHERE `status` = 'paid';
-- Map old 'suspended' to 'Expired'
UPDATE `<PREFIX>billing_orders`
SET `status` = 'Expired'
WHERE `status` = 'suspended';
-- Optional: verify counts after migration
-- SELECT status, COUNT(*) AS count FROM gsp_billing_orders GROUP BY status ORDER BY count DESC;