-- Migration: Cleanup old device management structures
-- Date: 2025-01-03
-- Description: Remove old tables and compatibility views after successful migration

BEGIN;

-- Drop compatibility view
DROP VIEW IF EXISTS v_activations CASCADE;

-- Drop old activations table
DROP TABLE IF EXISTS activations CASCADE;

-- Drop any backup tables if they exist
DROP TABLE IF EXISTS device_registrations_backup CASCADE;
DROP TABLE IF EXISTS licenses_backup CASCADE;

-- Drop old columns that might still exist
ALTER TABLE licenses DROP COLUMN IF EXISTS max_devices CASCADE;
ALTER TABLE licenses DROP COLUMN IF EXISTS max_activations CASCADE;

-- Add comment to document the cleanup
COMMENT ON TABLE device_registrations IS 'Main table for device management - replaces old activations table';
COMMENT ON COLUMN device_registrations.hardware_fingerprint IS 'Unique hardware identifier - replaces old hardware_id/hardware_hash';
COMMENT ON COLUMN device_registrations.device_name IS 'Device name - replaces old machine_name/machine_id';

COMMIT;