Dateien
Hetzner-Backup/migrations/completed/003_migrate_activations_table.sql
2025-07-03 20:38:33 +00:00

27 Zeilen
945 B
SQL

-- Migrate activations table to new column names
-- Add new columns
ALTER TABLE activations
ADD COLUMN IF NOT EXISTS machine_name VARCHAR(255),
ADD COLUMN IF NOT EXISTS hardware_fingerprint VARCHAR(255);
-- Copy data from old to new columns
UPDATE activations
SET machine_name = COALESCE(device_name, machine_id),
hardware_fingerprint = hardware_hash
WHERE machine_name IS NULL OR hardware_fingerprint IS NULL;
-- Make new columns NOT NULL after data is copied
ALTER TABLE activations
ALTER COLUMN machine_name SET NOT NULL,
ALTER COLUMN hardware_fingerprint SET NOT NULL;
-- Drop old columns
ALTER TABLE activations
DROP COLUMN IF EXISTS machine_id,
DROP COLUMN IF EXISTS hardware_hash,
DROP COLUMN IF EXISTS device_name;
-- Update any indexes
CREATE INDEX IF NOT EXISTS idx_activations_machine_name ON activations(machine_name);
CREATE INDEX IF NOT EXISTS idx_activations_hardware_fingerprint ON activations(hardware_fingerprint);