Skip to content

Commit 9abb572

Browse files
authored
Rename mdm profiles updated_at to uploaded_at and remove automatic setting (#16425)
1 parent fa46cfb commit 9abb572

14 files changed

+385
-110
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Renamed the `mdm_windows_configuration_profiles` and `mdm_apple_configuration_profiles` `updated_at` field to `uploaded_at` and removed the automatic setting of the value, set explicity instead.

server/datastore/mysql/apple_mdm.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func (ds *Datastore) NewMDMAppleConfigProfile(ctx context.Context, cp fleet.MDMA
2626
profUUID := "a" + uuid.New().String()
2727
stmt := `
2828
INSERT INTO
29-
mdm_apple_configuration_profiles (profile_uuid, team_id, identifier, name, mobileconfig, checksum)
30-
(SELECT ?, ?, ?, ?, ?, UNHEX(MD5(?)) FROM DUAL WHERE
29+
mdm_apple_configuration_profiles (profile_uuid, team_id, identifier, name, mobileconfig, checksum, uploaded_at)
30+
(SELECT ?, ?, ?, ?, ?, UNHEX(MD5(?)), CURRENT_TIMESTAMP() FROM DUAL WHERE
3131
NOT EXISTS (
3232
SELECT 1 FROM mdm_windows_configuration_profiles WHERE name = ? AND team_id = ?
3333
)
@@ -116,7 +116,7 @@ SELECT
116116
identifier,
117117
mobileconfig,
118118
created_at,
119-
updated_at,
119+
uploaded_at,
120120
checksum
121121
FROM
122122
mdm_apple_configuration_profiles
@@ -163,7 +163,7 @@ SELECT
163163
mobileconfig,
164164
checksum,
165165
created_at,
166-
updated_at
166+
uploaded_at
167167
FROM
168168
mdm_apple_configuration_profiles
169169
WHERE
@@ -1200,15 +1200,16 @@ WHERE
12001200
const insertNewOrEditedProfile = `
12011201
INSERT INTO
12021202
mdm_apple_configuration_profiles (
1203-
profile_uuid, team_id, identifier, name, mobileconfig, checksum
1203+
profile_uuid, team_id, identifier, name, mobileconfig, checksum, uploaded_at
12041204
)
12051205
VALUES
1206-
-- see https://stackoverflow.com/a/51393124/1094941
1207-
( CONCAT('a', CONVERT(uuid() USING utf8mb4)), ?, ?, ?, ?, UNHEX(MD5(mobileconfig)) )
1206+
-- see https://stackoverflow.com/a/51393124/1094941
1207+
( CONCAT('a', CONVERT(uuid() USING utf8mb4)), ?, ?, ?, ?, UNHEX(MD5(mobileconfig)), CURRENT_TIMESTAMP() )
12081208
ON DUPLICATE KEY UPDATE
1209+
uploaded_at = IF(checksum = VALUES(checksum) AND name = VALUES(name), uploaded_at, CURRENT_TIMESTAMP()),
1210+
checksum = VALUES(checksum),
12091211
name = VALUES(name),
1210-
mobileconfig = VALUES(mobileconfig),
1211-
checksum = UNHEX(MD5(VALUES(mobileconfig)))
1212+
mobileconfig = VALUES(mobileconfig)
12121213
`
12131214

12141215
// use a profile team id of 0 if no-team
@@ -2346,16 +2347,18 @@ func (ds *Datastore) BulkUpsertMDMAppleConfigProfiles(ctx context.Context, paylo
23462347

23472348
args = append(args, teamID, cp.Identifier, cp.Name, cp.Mobileconfig)
23482349
// see https://stackoverflow.com/a/51393124/1094941
2349-
sb.WriteString("(CONCAT('a', CONVERT(uuid() USING utf8mb4)), ?, ?, ?, ?, UNHEX(MD5(mobileconfig))),")
2350+
sb.WriteString("( CONCAT('a', CONVERT(uuid() USING utf8mb4)), ?, ?, ?, ?, UNHEX(MD5(mobileconfig)), CURRENT_TIMESTAMP() ),")
23502351
}
23512352

23522353
stmt := fmt.Sprintf(`
23532354
INSERT INTO
2354-
mdm_apple_configuration_profiles (profile_uuid, team_id, identifier, name, mobileconfig, checksum)
2355+
mdm_apple_configuration_profiles (profile_uuid, team_id, identifier, name, mobileconfig, checksum, uploaded_at)
23552356
VALUES %s
23562357
ON DUPLICATE KEY UPDATE
2358+
uploaded_at = IF(checksum = VALUES(checksum) AND name = VALUES(name), uploaded_at, CURRENT_TIMESTAMP()),
23572359
mobileconfig = VALUES(mobileconfig),
2358-
checksum = UNHEX(MD5(VALUES(mobileconfig)))`, strings.TrimSuffix(sb.String(), ","))
2360+
checksum = VALUES(checksum)
2361+
`, strings.TrimSuffix(sb.String(), ","))
23592362

23602363
if _, err := ds.writer(ctx).ExecContext(ctx, stmt, args...); err != nil {
23612364
return ctxerr.Wrapf(ctx, err, "upsert mdm config profiles")
@@ -2592,7 +2595,7 @@ SELECT
25922595
identifier,
25932596
mobileconfig,
25942597
created_at,
2595-
updated_at
2598+
uploaded_at
25962599
FROM
25972600
mdm_apple_configuration_profiles
25982601
WHERE

0 commit comments

Comments
 (0)