33 lines
1.7 KiB
MySQL
33 lines
1.7 KiB
MySQL
|
|
-- Apple BMC Mobile Recorder provisioning support.
|
||
|
|
-- The serial number remains the physical-device identity. Device-specific values
|
||
|
|
-- (UDID, ECID, IMEI, Wi-Fi MAC and iOS) live in hardware_specs for extensibility.
|
||
|
|
|
||
|
|
ALTER TABLE hardware_assets
|
||
|
|
ADD COLUMN IF NOT EXISTS recorder_number INTEGER,
|
||
|
|
ADD COLUMN IF NOT EXISTS provisioned_at TIMESTAMP,
|
||
|
|
ADD COLUMN IF NOT EXISTS last_provisioned_at TIMESTAMP;
|
||
|
|
|
||
|
|
ALTER TABLE hardware_assets DROP CONSTRAINT IF EXISTS hardware_assets_asset_type_check;
|
||
|
|
ALTER TABLE hardware_assets ADD CONSTRAINT hardware_assets_asset_type_check
|
||
|
|
CHECK (asset_type IN ('pc', 'laptop', 'printer', 'skærm', 'telefon', 'server', 'netværk', 'andet', 'mobile_recorder'));
|
||
|
|
|
||
|
|
ALTER TABLE hardware_assets DROP CONSTRAINT IF EXISTS hardware_assets_status_check;
|
||
|
|
ALTER TABLE hardware_assets ADD CONSTRAINT hardware_assets_status_check
|
||
|
|
CHECK (status IN ('active', 'ready', 'faulty_reported', 'in_repair', 'replaced', 'retired', 'unsupported'));
|
||
|
|
|
||
|
|
CREATE INDEX IF NOT EXISTS idx_hardware_mobile_recorder_number
|
||
|
|
ON hardware_assets(recorder_number)
|
||
|
|
WHERE deleted_at IS NULL AND recorder_number IS NOT NULL;
|
||
|
|
|
||
|
|
CREATE TABLE IF NOT EXISTS hardware_provisioning_history (
|
||
|
|
id BIGSERIAL PRIMARY KEY,
|
||
|
|
hardware_id INTEGER NOT NULL REFERENCES hardware_assets(id) ON DELETE CASCADE,
|
||
|
|
action VARCHAR(16) NOT NULL CHECK (action IN ('created', 'updated')),
|
||
|
|
source VARCHAR(80) NOT NULL DEFAULT 'apple_configurator',
|
||
|
|
payload JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||
|
|
provisioned_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||
|
|
);
|
||
|
|
|
||
|
|
CREATE INDEX IF NOT EXISTS idx_hardware_provisioning_history_asset
|
||
|
|
ON hardware_provisioning_history(hardware_id, provisioned_at DESC);
|