Skip to content

Commit a8ec3e5

Browse files
mnageorgekarrv
authored andcommitted
Rename mdm profiles updated_at to uploaded_at and remove automatic setting (#16425)
1 parent 50a594c commit a8ec3e5

14 files changed

+383
-108
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
@@ -1212,15 +1212,16 @@ WHERE
12121212
const insertNewOrEditedProfile = `
12131213
INSERT INTO
12141214
mdm_apple_configuration_profiles (
1215-
profile_uuid, team_id, identifier, name, mobileconfig, checksum
1215+
profile_uuid, team_id, identifier, name, mobileconfig, checksum, uploaded_at
12161216
)
12171217
VALUES
1218-
-- see https://stackoverflow.com/a/51393124/1094941
1219-
( CONCAT('a', CONVERT(uuid() USING utf8mb4)), ?, ?, ?, ?, UNHEX(MD5(mobileconfig)) )
1218+
-- see https://stackoverflow.com/a/51393124/1094941
1219+
( CONCAT('a', CONVERT(uuid() USING utf8mb4)), ?, ?, ?, ?, UNHEX(MD5(mobileconfig)), CURRENT_TIMESTAMP() )
12201220
ON DUPLICATE KEY UPDATE
1221+
uploaded_at = IF(checksum = VALUES(checksum) AND name = VALUES(name), uploaded_at, CURRENT_TIMESTAMP()),
1222+
checksum = VALUES(checksum),
12211223
name = VALUES(name),
1222-
mobileconfig = VALUES(mobileconfig),
1223-
checksum = UNHEX(MD5(VALUES(mobileconfig)))
1224+
mobileconfig = VALUES(mobileconfig)
12241225
`
12251226

12261227
// use a profile team id of 0 if no-team
@@ -2380,16 +2381,18 @@ func (ds *Datastore) BulkUpsertMDMAppleConfigProfiles(ctx context.Context, paylo
23802381

23812382
args = append(args, teamID, cp.Identifier, cp.Name, cp.Mobileconfig)
23822383
// see https://stackoverflow.com/a/51393124/1094941
2383-
sb.WriteString("(CONCAT('a', CONVERT(uuid() USING utf8mb4)), ?, ?, ?, ?, UNHEX(MD5(mobileconfig))),")
2384+
sb.WriteString("( CONCAT('a', CONVERT(uuid() USING utf8mb4)), ?, ?, ?, ?, UNHEX(MD5(mobileconfig)), CURRENT_TIMESTAMP() ),")
23842385
}
23852386

23862387
stmt := fmt.Sprintf(`
23872388
INSERT INTO
2388-
mdm_apple_configuration_profiles (profile_uuid, team_id, identifier, name, mobileconfig, checksum)
2389+
mdm_apple_configuration_profiles (profile_uuid, team_id, identifier, name, mobileconfig, checksum, uploaded_at)
23892390
VALUES %s
23902391
ON DUPLICATE KEY UPDATE
2392+
uploaded_at = IF(checksum = VALUES(checksum) AND name = VALUES(name), uploaded_at, CURRENT_TIMESTAMP()),
23912393
mobileconfig = VALUES(mobileconfig),
2392-
checksum = UNHEX(MD5(VALUES(mobileconfig)))`, strings.TrimSuffix(sb.String(), ","))
2394+
checksum = VALUES(checksum)
2395+
`, strings.TrimSuffix(sb.String(), ","))
23932396

23942397
if _, err := ds.writer(ctx).ExecContext(ctx, stmt, args...); err != nil {
23952398
return ctxerr.Wrapf(ctx, err, "upsert mdm config profiles")
@@ -2626,7 +2629,7 @@ SELECT
26262629
identifier,
26272630
mobileconfig,
26282631
created_at,
2629-
updated_at
2632+
uploaded_at
26302633
FROM
26312634
mdm_apple_configuration_profiles
26322635
WHERE

0 commit comments

Comments
 (0)