mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 21:35:40 +08:00
Add a few more statements to the up and down migrations for the new unique constraints so that the data will fit the constraints if up or downgraded.
Use sql.NullString for UDID and SerialNumber.
This commit is contained in:
@@ -7,19 +7,20 @@ import (
|
||||
|
||||
"github.com/micromdm/dep"
|
||||
//"github.com/micromdm/mdm"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// Device represents an iOS or OS X Computer
|
||||
type Device struct {
|
||||
// Primary key is UUID
|
||||
UUID string `json:"uuid" db:"device_uuid"`
|
||||
UDID string `json:"udid,omitempty"`
|
||||
SerialNumber string `json:"serial_number,omitempty" db:"serial_number,omitempty"`
|
||||
OSVersion string `json:"os_version,omitempty" db:"os_version,omitempty"`
|
||||
BuildVersion string `json:"build_version,omitempty" db:"build_version,omitempty"`
|
||||
ProductName string `json:"product_name,omitempty" db:"product_name,omitempty"`
|
||||
IMEI string `json:"imei,omitempty" db:"imei,omitempty"`
|
||||
MEID string `json:"meid,omitempty" db:"meid,omitempty"`
|
||||
UUID string `json:"uuid" db:"device_uuid"`
|
||||
UDID sql.NullString `json:"udid,omitempty"`
|
||||
SerialNumber sql.NullString `json:"serial_number,omitempty" db:"serial_number,omitempty"`
|
||||
OSVersion string `json:"os_version,omitempty" db:"os_version,omitempty"`
|
||||
BuildVersion string `json:"build_version,omitempty" db:"build_version,omitempty"`
|
||||
ProductName string `json:"product_name,omitempty" db:"product_name,omitempty"`
|
||||
IMEI string `json:"imei,omitempty" db:"imei,omitempty"`
|
||||
MEID string `json:"meid,omitempty" db:"meid,omitempty"`
|
||||
//Apple MDM Protocol Topic
|
||||
MDMTopic string `json:"mdm_topic,omitempty" db:"apple_mdm_topic,omitempty"`
|
||||
PushMagic string `json:"push_magic,omitempty" db:"apple_push_magic,omitempty"`
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
DROP INDEX IF EXISTS serial_idx;
|
||||
DROP INDEX IF EXISTS udid_idx;
|
||||
|
||||
UPDATE devices SET udid = '' WHERE udid IS NULL;
|
||||
UPDATE devices SET serial_number = '' WHERE serial_number IS NULL;
|
||||
|
||||
ALTER TABLE devices
|
||||
ALTER COLUMN udid SET NOT NULL;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS udid_serial_idx ON devices (udid, serial_number);
|
||||
@@ -1,5 +1,11 @@
|
||||
-- Add the UUID and Serial Number back as individual UNIQUE constraints, along with others
|
||||
DROP INDEX udid_serial_idx;
|
||||
|
||||
ALTER TABLE devices
|
||||
ALTER COLUMN udid DROP NOT NULL;
|
||||
|
||||
UPDATE devices SET udid = NULL WHERE udid = '';
|
||||
UPDATE devices SET serial_number = NULL WHERE serial_number = '';
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS serial_idx ON devices (serial_number);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS udid_idx ON devices (udid);
|
||||
|
||||
Reference in New Issue
Block a user