-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMigration.lua
More file actions
1538 lines (1374 loc) · 54.1 KB
/
Migration.lua
File metadata and controls
1538 lines (1374 loc) · 54.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Schema migration for Enhanced Cooldown Manager
-- Handles versioned SavedVariable namespacing and profile migrations.
local _, ns = ...
local Migration = {}
ns.Migration = Migration
-- Legacy free-mode bars used implicit default positions when offset fields were
-- absent from SavedVariables. Keep these migration-local so the historical
-- fallback data stays coupled to the schema upgrade that needs it.
local LEGACY_FREE_POSITION_DEFAULTS = {
powerBar = { point = "CENTER", x = 0, y = -275 },
resourceBar = { point = "CENTER", x = 0, y = -300 },
runeBar = { point = "CENTER", x = 0, y = -325 },
buffBars = { point = "CENTER", x = 0, y = -350 },
}
--- Migration log buffer. Entries are collected during migration and persisted
--- into the new version's SV slot so they survive across sessions.
---@type string[]
local migrationLog = {}
--- Appends a timestamped message to the migration log buffer and sends it to
--- the normal debug log.
---@param message string
local function log(message)
migrationLog[#migrationLog + 1] = date("%Y-%m-%d %H:%M:%S") .. " " .. message
ns.Log("Migration", message)
end
--------------------------------------------------------------------------------
-- Helpers
--------------------------------------------------------------------------------
--- Aligns copied profile schemaVersion values with the slot they came from.
--- The versioned slot key is the source of truth during reseeding; older slots
--- may contain profiles that were previously migrated forward in-place.
---@param slot table|nil
---@param schemaVersion number
local function alignSlotProfileSchemas(slot, schemaVersion)
if type(slot) ~= "table" or type(slot.profiles) ~= "table" then
return
end
for _, profile in pairs(slot.profiles) do
if type(profile) == "table" then
profile.schemaVersion = schemaVersion
end
end
end
local function normalizeLegacyColor(color, defaultAlpha)
if color == nil then
return nil
end
if type(color) ~= "table" then
return nil
end
if color.r ~= nil or color.g ~= nil or color.b ~= nil then
return {
r = color.r or 0,
g = color.g or 0,
b = color.b or 0,
a = color.a or defaultAlpha or 1,
}
end
if color[1] ~= nil then
return {
r = color[1],
g = color[2],
b = color[3],
a = color[4] or defaultAlpha or 1,
}
end
return nil
end
--- Returns true when the color matches the expected RGBA values.
---@param color ECM_Color|table|nil
---@param r number
---@param g number
---@param b number
---@param a number|nil
---@return boolean
local function isColorMatch(color, r, g, b, a)
if type(color) ~= "table" then
return false
end
local resolved = normalizeLegacyColor(color, a)
if not resolved then
return false
end
if resolved.r ~= r or resolved.g ~= g or resolved.b ~= b then
return false
end
if a == nil then
return true
end
return resolved.a == a
end
local function normalizeColorTable(colorTable, defaultAlpha)
if type(colorTable) ~= "table" then
return
end
for key, value in pairs(colorTable) do
colorTable[key] = normalizeLegacyColor(value, defaultAlpha)
end
end
-- Migration loads before ECM.lua during normal addon startup, so the canonical
-- clone helper may not exist yet when PrepareDatabase reseeds versioned slots.
local function cloneValue(value)
if ns.CloneValue then
return ns.CloneValue(value)
end
if type(value) ~= "table" then
return value
end
local copy = {}
for k, v in pairs(value) do
copy[k] = cloneValue(v)
end
return copy
end
local function normalizeBarConfig(cfg)
if not cfg then
return
end
cfg.bgColor = normalizeLegacyColor(cfg.bgColor, 1)
if cfg.border and cfg.border.color then
cfg.border.color = normalizeLegacyColor(cfg.border.color, 1)
end
if cfg.colors then
normalizeColorTable(cfg.colors, 1)
end
if cfg.color then
cfg.color = normalizeLegacyColor(cfg.color, 1)
end
end
local function forEachClassSpecEntry(store, fn)
if type(store) ~= "table" then
return
end
for classID, classMap in pairs(store) do
if type(classMap) == "table" then
for specID, specMap in pairs(classMap) do
if type(specMap) == "table" then
fn(classID, specID, specMap)
end
end
end
end
end
local function normalizeBuffBarsCache(cfg)
if not (cfg and cfg.colors and type(cfg.colors.cache) == "table") then
return
end
forEachClassSpecEntry(cfg.colors.cache, function(_, _, specMap)
for index, entry in pairs(specMap) do
if type(entry) ~= "table" then
specMap[index] = nil
else
entry.color = nil
local spellName = entry.spellName
if type(spellName) ~= "string" then
specMap[index] = nil
else
spellName = strtrim(spellName)
if spellName == "" or spellName == "Unknown" then
specMap[index] = nil
else
entry.spellName = spellName
end
end
end
end
end)
end
local FrameUtil = ns.FrameUtil
-- Built-in Edit Mode layout indices (frozen for migration stability).
local EDIT_MODE_BUILTIN_NAMES = { "Modern", "Classic" }
---@return string[]|nil names All layout names, or nil if unavailable.
local function resolveAllLayoutNames()
local layoutInfo = C_EditMode.GetLayouts()
if not layoutInfo then
return nil
end
local names = {}
for i, builtin in ipairs(EDIT_MODE_BUILTIN_NAMES) do
names[i] = builtin
end
local customs = layoutInfo.layouts
if customs then
for i = 1, #customs do
local name = customs[i].layoutName
if type(name) == "string" and name ~= "" then
names[#names + 1] = name
end
end
end
return #names > 0 and names or nil
end
local normalizeEditModePosition = FrameUtil.NormalizePosition
--- Migrates profiles from the per-bar color settings to per-spell.
---@param profile table The profile to migrate
local function migrateToPerSpellColors(profile)
local cfg = profile.buffBars
if not cfg then
return
end
local perBar = cfg.colors.perBar
local cache = cfg.colors.cache
if not perBar then
return
end
if not cfg.colors.perSpell then
cfg.colors.perSpell = {}
end
local perSpell = cfg.colors.perSpell
local function doSpellMigration(perBarStore, perSpellStore, cacheStore)
for i, v in ipairs(cacheStore) do
if not v.color and v.spellName then
local bc = perBarStore[i]
if bc then
perSpellStore[v.spellName] = bc
cacheStore[i] = {
lastSeen = v.lastSeen,
spellName = v.spellName,
}
end
end
end
end
forEachClassSpecEntry(perBar, function(classID, specID, perBarStore)
perSpell[classID] = perSpell[classID] or {}
perSpell[classID][specID] = perSpell[classID][specID] or {}
if cache[classID] and cache[classID][specID] then
doSpellMigration(perBarStore, perSpell[classID][specID], cache[classID][specID])
end
end)
cfg.colors.perBar = nil
end
--- Repairs spell-color metadata and fallback tier links for all class/spec stores.
--- This migration runs once and replaces the previous runtime-only repair path.
---@param profile table The profile to repair
local function repairSpellColorStores(profile)
local buffBars = profile.buffBars
if not (buffBars and type(buffBars.colors) == "table") then
return
end
local colors = buffBars.colors
if type(colors.byName) ~= "table" then
colors.byName = {}
end
if type(colors.bySpellID) ~= "table" then
colors.bySpellID = {}
end
if type(colors.byCooldownID) ~= "table" then
colors.byCooldownID = {}
end
if type(colors.byTexture) ~= "table" then
colors.byTexture = {}
end
local tierDefs = {
{ storeKey = "byName", keyType = "spellName" },
{ storeKey = "bySpellID", keyType = "spellID", idField = "spellID" },
{ storeKey = "byCooldownID", keyType = "cooldownID", idField = "cooldownID" },
{ storeKey = "byTexture", keyType = "textureFileID", idField = "textureId" },
}
-- Normalize metadata per stored tier so options/runtime no longer need to infer.
for _, tier in ipairs(tierDefs) do
forEachClassSpecEntry(colors[tier.storeKey], function(_, _, specMap)
for key, entry in pairs(specMap) do
if type(entry) == "table" and type(entry.value) == "table" then
local value = entry.value
if not value.keyType then
value.keyType = tier.keyType
end
if tier.idField and type(key) == "number" and value[tier.idField] == nil then
value[tier.idField] = key
end
end
end
end)
end
local function ensureClassSpecStore(store, classID, specID)
if type(store[classID]) ~= "table" then
store[classID] = {}
end
if type(store[classID][specID]) ~= "table" then
store[classID][specID] = {}
end
return store[classID][specID]
end
-- Backfill fallback tiers from byName entries carrying embedded IDs.
forEachClassSpecEntry(colors.byName, function(classID, specID, specMap)
local bySpellIDSpec = ensureClassSpecStore(colors.bySpellID, classID, specID)
local byCooldownIDSpec = ensureClassSpecStore(colors.byCooldownID, classID, specID)
local byTextureSpec = ensureClassSpecStore(colors.byTexture, classID, specID)
for _, entry in pairs(specMap) do
if type(entry) == "table" and type(entry.value) == "table" then
local value = entry.value
if type(value.spellID) == "number" and bySpellIDSpec[value.spellID] == nil then
bySpellIDSpec[value.spellID] = entry
end
if type(value.cooldownID) == "number" and byCooldownIDSpec[value.cooldownID] == nil then
byCooldownIDSpec[value.cooldownID] = entry
end
if type(value.textureId) == "number" and byTextureSpec[value.textureId] == nil then
byTextureSpec[value.textureId] = entry
end
end
end
end)
end
--- Normalizes spell-color wrapper metadata and collapses duplicate entries.
--- Stored color payloads become color-only (r/g/b/a); identifiers move to entry.meta.
---@param profile table The profile to repair
local function normalizeSpellColorStoresV10(profile)
local stats = {
skipped = false,
skipReason = nil,
tierStoresCreated = {},
tierStoresCreatedCount = 0,
classesProcessed = 0,
specsProcessed = 0,
entriesScanned = 0,
validEntries = 0,
invalidEntries = 0,
canonicalEntries = 0,
aliasLinksMerged = 0,
invalidRetained = 0,
invalidKeyCollisions = 0,
entriesMetaNormalized = 0,
finalEntries = 0,
perTier = {
byName = { scanned = 0, invalid = 0, final = 0 },
bySpellID = { scanned = 0, invalid = 0, final = 0 },
byCooldownID = { scanned = 0, invalid = 0, final = 0 },
byTexture = { scanned = 0, invalid = 0, final = 0 },
},
anomalySpecs = {},
anomalySpecsOverflow = 0,
}
local buffBars = profile.buffBars
if not (buffBars and type(buffBars.colors) == "table") then
stats.skipped = true
stats.skipReason = "buffBars.colors missing"
return stats
end
local colors = buffBars.colors
local tierDefs = {
{ storeKey = "byName", keyType = "spellName" },
{ storeKey = "bySpellID", keyType = "spellID" },
{ storeKey = "byCooldownID", keyType = "cooldownID" },
{ storeKey = "byTexture", keyType = "textureFileID" },
}
local validKeyTypes = {
spellName = true,
spellID = true,
cooldownID = true,
textureFileID = true,
}
local function ensureTierStore(storeKey)
if type(colors[storeKey]) ~= "table" then
colors[storeKey] = {}
if not stats.tierStoresCreated[storeKey] then
stats.tierStoresCreated[storeKey] = true
stats.tierStoresCreatedCount = stats.tierStoresCreatedCount + 1
end
end
return colors[storeKey]
end
local function ensureClassSpec(store, classID, specID)
if type(store[classID]) ~= "table" then
store[classID] = {}
end
if type(store[classID][specID]) ~= "table" then
store[classID][specID] = {}
end
return store[classID][specID]
end
local function validKey(k)
if type(k) == "string" or type(k) == "number" then
return k
end
return nil
end
local function validNumericKey(k)
return type(k) == "number" and k or nil
end
local function countEntries(map)
if type(map) ~= "table" then
return 0
end
local n = 0
for _ in pairs(map) do
n = n + 1
end
return n
end
local function selectPrimary(spellName, spellID, cooldownID, textureFileID)
if spellName ~= nil then
return spellName, "spellName"
end
if spellID ~= nil then
return spellID, "spellID"
end
if cooldownID ~= nil then
return cooldownID, "cooldownID"
end
if textureFileID ~= nil then
return textureFileID, "textureFileID"
end
return nil, nil
end
local function buildKey(spellName, spellID, cooldownID, textureFileID, preferredType)
local keyType = validKeyTypes[preferredType] and preferredType or nil
local primaryKey
if keyType == "spellName" then
primaryKey = spellName
elseif keyType == "spellID" then
primaryKey = spellID
elseif keyType == "cooldownID" then
primaryKey = cooldownID
elseif keyType == "textureFileID" then
primaryKey = textureFileID
end
if primaryKey == nil then
primaryKey, keyType = selectPrimary(spellName, spellID, cooldownID, textureFileID)
end
if keyType == nil or primaryKey == nil then
return nil
end
return {
keyType = keyType,
primaryKey = primaryKey,
spellName = spellName,
spellID = spellID,
cooldownID = cooldownID,
textureFileID = textureFileID,
}
end
local function keysMatch(a, b)
if not (a and b) then
return false
end
if a.spellName and b.spellName and a.spellName == b.spellName then
return true
end
if a.spellID and b.spellID and a.spellID == b.spellID then
return true
end
if a.cooldownID and b.cooldownID and a.cooldownID == b.cooldownID then
return true
end
if a.textureFileID and b.textureFileID and a.textureFileID == b.textureFileID then
return true
end
return false
end
local function mergeKeys(a, b)
if a == nil then
return b
end
if b == nil then
return a
end
if not keysMatch(a, b) then
return nil
end
return buildKey(
a.spellName or b.spellName,
a.spellID or b.spellID,
a.cooldownID or b.cooldownID,
a.textureFileID or b.textureFileID,
nil
)
end
local function entryTs(entry)
return (type(entry) == "table" and type(entry.t) == "number") and entry.t or 0
end
local function scrubValue(value)
if type(value) ~= "table" then
return
end
value.keyType = nil
value.primaryKey = nil
value.spellName = nil
value.spellID = nil
value.cooldownID = nil
value.textureId = nil
value.textureFileID = nil
if value.a == nil then
value.a = 1
end
end
local function buildKeyFromEntry(entry, tierKeyType, rawKey)
if type(entry) ~= "table" or type(entry.value) ~= "table" then
return nil
end
local value = entry.value
local meta = type(entry.meta) == "table" and entry.meta or nil
local spellName = validKey((meta and meta.spellName) or value.spellName)
local spellID = validNumericKey((meta and meta.spellID) or value.spellID)
local cooldownID = validNumericKey((meta and meta.cooldownID) or value.cooldownID)
local textureFileID =
validNumericKey((meta and (meta.textureFileID or meta.textureId)) or value.textureFileID or value.textureId)
local preferredType = (meta and meta.keyType) or value.keyType or tierKeyType
if not validKeyTypes[preferredType] then
preferredType = tierKeyType
end
local vRaw = validKey(rawKey)
if tierKeyType == "spellName" and type(vRaw) == "string" then
spellName = vRaw
elseif tierKeyType == "spellID" and type(vRaw) == "number" then
spellID = vRaw
elseif tierKeyType == "cooldownID" and type(vRaw) == "number" then
cooldownID = vRaw
elseif tierKeyType == "textureFileID" and type(vRaw) == "number" then
textureFileID = vRaw
end
return buildKey(spellName, spellID, cooldownID, textureFileID, preferredType)
end
local function setEntryMeta(entry, key)
if type(entry) ~= "table" or type(entry.value) ~= "table" or not key then
return
end
scrubValue(entry.value)
stats.entriesMetaNormalized = stats.entriesMetaNormalized + 1
entry.meta = {
keyType = key.keyType,
primaryKey = key.primaryKey,
spellName = key.spellName,
spellID = key.spellID,
cooldownID = key.cooldownID,
textureFileID = key.textureFileID,
}
end
for _, tier in ipairs(tierDefs) do
ensureTierStore(tier.storeKey)
end
local classIDs = {}
for _, tier in ipairs(tierDefs) do
local store = colors[tier.storeKey]
for classID, classMap in pairs(store) do
if type(classMap) == "table" then
classIDs[classID] = true
end
end
end
for classID in pairs(classIDs) do
stats.classesProcessed = stats.classesProcessed + 1
local specIDs = {}
for _, tier in ipairs(tierDefs) do
local classMap = colors[tier.storeKey][classID]
if type(classMap) == "table" then
for specID, specMap in pairs(classMap) do
if type(specMap) == "table" then
specIDs[specID] = true
end
end
end
end
for specID in pairs(specIDs) do
stats.specsProcessed = stats.specsProcessed + 1
local groups = {}
local groupByEntry = {}
local invalidPerTier = {}
local newPerTier = {}
local specScanned = 0
local specInvalid = 0
local specInvalidByTier = {}
for tierIndex, tier in ipairs(tierDefs) do
invalidPerTier[tierIndex] = {}
newPerTier[tierIndex] = {}
specInvalidByTier[tier.storeKey] = 0
local specStore = ensureClassSpec(colors[tier.storeKey], classID, specID)
for rawKey, entry in pairs(specStore) do
stats.entriesScanned = stats.entriesScanned + 1
stats.perTier[tier.storeKey].scanned = stats.perTier[tier.storeKey].scanned + 1
specScanned = specScanned + 1
local key = buildKeyFromEntry(entry, tier.keyType, rawKey)
if not key then
invalidPerTier[tierIndex][rawKey] = entry
stats.invalidEntries = stats.invalidEntries + 1
stats.perTier[tier.storeKey].invalid = stats.perTier[tier.storeKey].invalid + 1
specInvalid = specInvalid + 1
specInvalidByTier[tier.storeKey] = specInvalidByTier[tier.storeKey] + 1
else
stats.validEntries = stats.validEntries + 1
local groupIndex = groupByEntry[entry]
if not groupIndex then
for i, group in ipairs(groups) do
if keysMatch(group.key, key) then
groupIndex = i
break
end
end
end
if not groupIndex then
groupIndex = #groups + 1
groups[groupIndex] = {
key = key,
entry = entry,
ts = entryTs(entry),
tierIndex = tierIndex,
}
else
local group = groups[groupIndex]
group.key = mergeKeys(group.key, key) or group.key
local t = entryTs(entry)
if t > group.ts or (t == group.ts and tierIndex < group.tierIndex) then
group.entry = entry
group.ts = t
group.tierIndex = tierIndex
end
end
if type(entry) == "table" then
groupByEntry[entry] = groupIndex
end
end
end
end
stats.canonicalEntries = stats.canonicalEntries + #groups
if specScanned > specInvalid and #groups < (specScanned - specInvalid) then
stats.aliasLinksMerged = stats.aliasLinksMerged + ((specScanned - specInvalid) - #groups)
end
for _, group in ipairs(groups) do
if group.entry and group.key then
setEntryMeta(group.entry, group.key)
if group.key.spellName ~= nil then
newPerTier[1][group.key.spellName] = group.entry
end
if group.key.spellID ~= nil then
newPerTier[2][group.key.spellID] = group.entry
end
if group.key.cooldownID ~= nil then
newPerTier[3][group.key.cooldownID] = group.entry
end
if group.key.textureFileID ~= nil then
newPerTier[4][group.key.textureFileID] = group.entry
end
end
end
for tierIndex, tier in ipairs(tierDefs) do
ensureClassSpec(colors[tier.storeKey], classID, specID)
colors[tier.storeKey][classID][specID] = newPerTier[tierIndex]
for rawKey, entry in pairs(invalidPerTier[tierIndex]) do
if newPerTier[tierIndex][rawKey] == nil then
newPerTier[tierIndex][rawKey] = entry
stats.invalidRetained = stats.invalidRetained + 1
else
stats.invalidKeyCollisions = stats.invalidKeyCollisions + 1
end
end
for _, entry in pairs(newPerTier[tierIndex]) do
if type(entry) == "table" and type(entry.value) == "table" then
scrubValue(entry.value)
end
end
local finalCount = countEntries(newPerTier[tierIndex])
stats.finalEntries = stats.finalEntries + finalCount
stats.perTier[tier.storeKey].final = stats.perTier[tier.storeKey].final + finalCount
end
if specInvalid > 0 or (specScanned > specInvalid and #groups < (specScanned - specInvalid)) then
local invalidTierParts = {}
for _, tier in ipairs(tierDefs) do
local invalidCount = specInvalidByTier[tier.storeKey]
if invalidCount and invalidCount > 0 then
invalidTierParts[#invalidTierParts + 1] = tier.storeKey .. "=" .. invalidCount
end
end
local aliasLinks = 0
if specScanned > specInvalid and #groups < (specScanned - specInvalid) then
aliasLinks = (specScanned - specInvalid) - #groups
end
local msg = string.format(
"class=%s spec=%s scanned=%d valid=%d canonical=%d aliases=%d invalid=%d",
tostring(classID),
tostring(specID),
specScanned,
specScanned - specInvalid,
#groups,
aliasLinks,
specInvalid
)
if #invalidTierParts > 0 then
msg = msg .. " invalidByTier[" .. table.concat(invalidTierParts, ",") .. "]"
end
if #stats.anomalySpecs < 20 then
stats.anomalySpecs[#stats.anomalySpecs + 1] = msg
else
stats.anomalySpecsOverflow = stats.anomalySpecsOverflow + 1
end
end
end
end
return stats
end
--------------------------------------------------------------------------------
-- Schema Migrations
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Schema Migrations — registered per-version steps
--------------------------------------------------------------------------------
--- Registry of migration steps, keyed by target version.
--- Each function receives the profile and returns false to defer (stop the
--- migration chain), or any other value to indicate success.
local _migrations = {}
-- V2 → V3: buffBarColors -> buffBars.colors
_migrations[3] = function(profile)
if profile.buffBarColors then
log("Migrating buffBarColors to buffBars.colors")
profile.buffBars = profile.buffBars or {}
profile.buffBars.colors = profile.buffBars.colors or {}
local src = profile.buffBarColors
local dst = profile.buffBars.colors
dst.perBar = dst.perBar or src.colors or {}
dst.cache = dst.cache or src.cache or {}
dst.defaultColor = dst.defaultColor or src.defaultColor
profile.buffBarColors = nil
end
local colorsConfig = profile.buffBars and profile.buffBars.colors
if colorsConfig and colorsConfig.colors and not colorsConfig.perBar then
log("Renaming buffBars.colors.colors to buffBars.colors.perBar")
colorsConfig.perBar = colorsConfig.colors
colorsConfig.colors = nil
end
end
-- V3 → V4: tick colors, color normalization, powerBarTicks restructure
_migrations[4] = function(profile)
local ticksCfg = profile.powerBarTicks
if ticksCfg and isColorMatch(ticksCfg.defaultColor, 0, 0, 0, 0.5) then
ticksCfg.defaultColor = { r = 1, g = 1, b = 1, a = 0.8 }
end
local resourceCfg = profile.resourceBar
local colors = resourceCfg and resourceCfg.colors
local soulsColor = colors and colors[ns.Constants.RESOURCEBAR_TYPE_VENGEANCE_SOULS]
if isColorMatch(soulsColor, 0.46, 0.98, 1.00, nil) then
colors[ns.Constants.RESOURCEBAR_TYPE_VENGEANCE_SOULS] = { r = 0.259, g = 0.6, b = 0.91, a = 1 }
end
if profile.powerBarTicks then
profile.powerBar = profile.powerBar or {}
if not profile.powerBar.ticks then
profile.powerBar.ticks = profile.powerBarTicks
end
profile.powerBarTicks = nil
end
local gbl = profile.global
if gbl then
gbl.barBgColor = normalizeLegacyColor(gbl.barBgColor, 1)
end
normalizeBarConfig(profile.powerBar)
normalizeBarConfig(profile.resourceBar)
normalizeBarConfig(profile.runeBar)
local powerBar = profile.powerBar
if powerBar and powerBar.ticks then
local tickCfg = powerBar.ticks
tickCfg.defaultColor = normalizeLegacyColor(tickCfg.defaultColor, 1)
if tickCfg.mappings then
for _, specMap in pairs(tickCfg.mappings) do
for _, ticks in pairs(specMap) do
for _, tick in ipairs(ticks) do
if tick and tick.color then
tick.color = normalizeLegacyColor(
tick.color,
tickCfg.defaultColor and tickCfg.defaultColor.a or 1
)
end
end
end
end
end
end
local buffBars = profile.buffBars
if buffBars and buffBars.colors then
buffBars.colors.defaultColor = normalizeLegacyColor(buffBars.colors.defaultColor, 1)
local perBar = buffBars.colors.perBar
if type(perBar) == "table" then
for _, specMap in pairs(perBar) do
for _, bars in pairs(specMap) do
if type(bars) == "table" then
for index, color in pairs(bars) do
bars[index] = normalizeLegacyColor(color, 1)
end
end
end
end
end
end
end
-- V4 → V5: combatFade -> global.outOfCombatFade
_migrations[5] = function(profile)
local legacyCombatFade = profile.combatFade
if legacyCombatFade then
profile.global = profile.global or {}
profile.global.outOfCombatFade = profile.global.outOfCombatFade or {}
local fadeConfig = profile.global.outOfCombatFade
if legacyCombatFade.enabled ~= nil then
fadeConfig.enabled = legacyCombatFade.enabled
end
if legacyCombatFade.opacity ~= nil then
fadeConfig.opacity = legacyCombatFade.opacity
end
if legacyCombatFade.exceptInInstance ~= nil then
fadeConfig.exceptInInstance = legacyCombatFade.exceptInInstance
end
if legacyCombatFade.exceptIfTargetCanBeAttacked ~= nil then
fadeConfig.exceptIfTargetCanBeAttacked = legacyCombatFade.exceptIfTargetCanBeAttacked
end
profile.combatFade = nil
end
end
-- V5 → V6: perBar -> perSpell colors
_migrations[6] = function(profile)
migrateToPerSpellColors(profile)
end
-- V6 → V7: normalize buff bar cache entries
_migrations[7] = function(profile)
local buffBars = profile.buffBars
if buffBars then
normalizeBuffBarsCache(buffBars)
end
end
-- V7 → V8: split flat perSpell map into separate byName / byTexture tables
_migrations[8] = function(profile)
local buffBars = profile.buffBars
if buffBars and type(buffBars.colors) == "table" then
local colors = buffBars.colors
local perSpell = colors.perSpell
if type(perSpell) == "table" then
if type(colors.byName) ~= "table" then
colors.byName = {}
end
if type(colors.byTexture) ~= "table" then
colors.byTexture = {}
end
for classID, specTable in pairs(perSpell) do
if type(specTable) == "table" then
for specID, entries in pairs(specTable) do
if type(entries) == "table" then
colors.byName[classID] = colors.byName[classID] or {}
colors.byName[classID][specID] = colors.byName[classID][specID] or {}
colors.byTexture[classID] = colors.byTexture[classID] or {}
colors.byTexture[classID][specID] = colors.byTexture[classID][specID] or {}
for key, color in pairs(entries) do
local wrapped = { value = color, t = 0 }
if type(key) == "string" then
colors.byName[classID][specID][key] = wrapped
elseif type(key) == "number" then
colors.byTexture[classID][specID][key] = wrapped
end
end
end
end
end
end
colors.perSpell = nil
end
if type(colors.bySpellID) ~= "table" then
colors.bySpellID = {}
end
if type(colors.byCooldownID) ~= "table" then
colors.byCooldownID = {}
end
end
end
-- V8 → V9: repair spell color metadata and fallback tier links
_migrations[9] = function(profile)
repairSpellColorStores(profile)
end
-- V9 → V10: normalize spell color wrapper metadata and collapse fragmented entries
_migrations[10] = function(profile)
local v10Stats = normalizeSpellColorStoresV10(profile)
if v10Stats and v10Stats.skipped then
log("V10 spell color normalization skipped: " .. (v10Stats.skipReason or "unknown reason"))
elseif v10Stats then
local createdTiers = {}
for _, tier in ipairs({ "byName", "bySpellID", "byCooldownID", "byTexture" }) do
if v10Stats.tierStoresCreated[tier] then
createdTiers[#createdTiers + 1] = tier
end
end
log(
string.format(
"V10 spell color normalization summary: classes=%d specs=%d scanned=%d valid=%d canonical=%d aliases=%d invalid=%d invalidRetained=%d invalidKeyCollisions=%d metaNormalized=%d final=%d",
v10Stats.classesProcessed,
v10Stats.specsProcessed,
v10Stats.entriesScanned,
v10Stats.validEntries,
v10Stats.canonicalEntries,
v10Stats.aliasLinksMerged,
v10Stats.invalidEntries,
v10Stats.invalidRetained,
v10Stats.invalidKeyCollisions,
v10Stats.entriesMetaNormalized,