@@ -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
@@ -1200,15 +1200,16 @@ WHERE
1200
1200
const insertNewOrEditedProfile = `
1201
1201
INSERT INTO
1202
1202
mdm_apple_configuration_profiles (
1203
- profile_uuid, team_id, identifier, name, mobileconfig, checksum
1203
+ profile_uuid, team_id, identifier, name, mobileconfig, checksum, uploaded_at
1204
1204
)
1205
1205
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() )
1208
1208
ON DUPLICATE KEY UPDATE
1209
+ uploaded_at = IF(checksum = VALUES(checksum) AND name = VALUES(name), uploaded_at, CURRENT_TIMESTAMP()),
1210
+ checksum = VALUES(checksum),
1209
1211
name = VALUES(name),
1210
- mobileconfig = VALUES(mobileconfig),
1211
- checksum = UNHEX(MD5(VALUES(mobileconfig)))
1212
+ mobileconfig = VALUES(mobileconfig)
1212
1213
`
1213
1214
1214
1215
// use a profile team id of 0 if no-team
@@ -2346,16 +2347,18 @@ func (ds *Datastore) BulkUpsertMDMAppleConfigProfiles(ctx context.Context, paylo
2346
2347
2347
2348
args = append (args , teamID , cp .Identifier , cp .Name , cp .Mobileconfig )
2348
2349
// 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() )," )
2350
2351
}
2351
2352
2352
2353
stmt := fmt .Sprintf (`
2353
2354
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 )
2355
2356
VALUES %s
2356
2357
ON DUPLICATE KEY UPDATE
2358
+ uploaded_at = IF(checksum = VALUES(checksum) AND name = VALUES(name), uploaded_at, CURRENT_TIMESTAMP()),
2357
2359
mobileconfig = VALUES(mobileconfig),
2358
- checksum = UNHEX(MD5(VALUES(mobileconfig)))` , strings .TrimSuffix (sb .String (), "," ))
2360
+ checksum = VALUES(checksum)
2361
+ ` , strings .TrimSuffix (sb .String (), "," ))
2359
2362
2360
2363
if _ , err := ds .writer (ctx ).ExecContext (ctx , stmt , args ... ); err != nil {
2361
2364
return ctxerr .Wrapf (ctx , err , "upsert mdm config profiles" )
@@ -2592,7 +2595,7 @@ SELECT
2592
2595
identifier,
2593
2596
mobileconfig,
2594
2597
created_at,
2595
- updated_at
2598
+ uploaded_at
2596
2599
FROM
2597
2600
mdm_apple_configuration_profiles
2598
2601
WHERE
0 commit comments