@@ -26,8 +26,8 @@ func (ds *Datastore) NewMDMAppleConfigProfile(ctx context.Context, cp fleet.MDMA
26
26
profUUID := "a" + uuid .New ().String ()
27
27
stmt := `
28
28
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
31
31
NOT EXISTS (
32
32
SELECT 1 FROM mdm_windows_configuration_profiles WHERE name = ? AND team_id = ?
33
33
)
@@ -116,7 +116,7 @@ SELECT
116
116
identifier,
117
117
mobileconfig,
118
118
created_at,
119
- updated_at ,
119
+ uploaded_at ,
120
120
checksum
121
121
FROM
122
122
mdm_apple_configuration_profiles
@@ -163,7 +163,7 @@ SELECT
163
163
mobileconfig,
164
164
checksum,
165
165
created_at,
166
- updated_at
166
+ uploaded_at
167
167
FROM
168
168
mdm_apple_configuration_profiles
169
169
WHERE
@@ -1212,15 +1212,16 @@ WHERE
1212
1212
const insertNewOrEditedProfile = `
1213
1213
INSERT INTO
1214
1214
mdm_apple_configuration_profiles (
1215
- profile_uuid, team_id, identifier, name, mobileconfig, checksum
1215
+ profile_uuid, team_id, identifier, name, mobileconfig, checksum, uploaded_at
1216
1216
)
1217
1217
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() )
1220
1220
ON DUPLICATE KEY UPDATE
1221
+ uploaded_at = IF(checksum = VALUES(checksum) AND name = VALUES(name), uploaded_at, CURRENT_TIMESTAMP()),
1222
+ checksum = VALUES(checksum),
1221
1223
name = VALUES(name),
1222
- mobileconfig = VALUES(mobileconfig),
1223
- checksum = UNHEX(MD5(VALUES(mobileconfig)))
1224
+ mobileconfig = VALUES(mobileconfig)
1224
1225
`
1225
1226
1226
1227
// use a profile team id of 0 if no-team
@@ -2380,16 +2381,18 @@ func (ds *Datastore) BulkUpsertMDMAppleConfigProfiles(ctx context.Context, paylo
2380
2381
2381
2382
args = append (args , teamID , cp .Identifier , cp .Name , cp .Mobileconfig )
2382
2383
// 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() )," )
2384
2385
}
2385
2386
2386
2387
stmt := fmt .Sprintf (`
2387
2388
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 )
2389
2390
VALUES %s
2390
2391
ON DUPLICATE KEY UPDATE
2392
+ uploaded_at = IF(checksum = VALUES(checksum) AND name = VALUES(name), uploaded_at, CURRENT_TIMESTAMP()),
2391
2393
mobileconfig = VALUES(mobileconfig),
2392
- checksum = UNHEX(MD5(VALUES(mobileconfig)))` , strings .TrimSuffix (sb .String (), "," ))
2394
+ checksum = VALUES(checksum)
2395
+ ` , strings .TrimSuffix (sb .String (), "," ))
2393
2396
2394
2397
if _ , err := ds .writer (ctx ).ExecContext (ctx , stmt , args ... ); err != nil {
2395
2398
return ctxerr .Wrapf (ctx , err , "upsert mdm config profiles" )
@@ -2626,7 +2629,7 @@ SELECT
2626
2629
identifier,
2627
2630
mobileconfig,
2628
2631
created_at,
2629
- updated_at
2632
+ uploaded_at
2630
2633
FROM
2631
2634
mdm_apple_configuration_profiles
2632
2635
WHERE
0 commit comments