Skip to content

Commit

Permalink
Seperate migrations into multiple files (#673)
Browse files Browse the repository at this point in the history
* Allow for multiple migration files

* Split delta migrations

* Update migration.yml
  • Loading branch information
DebugOk authored Jan 15, 2024
1 parent d53b971 commit 9c0520f
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 111 deletions.
61 changes: 40 additions & 21 deletions Content.Server/Maps/MapMigrationSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class MapMigrationSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IResourceManager _resMan = default!;

private const string MigrationFile = "/migration.yml";
private const string MigrationDir = "/Migrations/";

public override void Initialize()
{
Expand All @@ -33,46 +33,65 @@ public override void Initialize()
return;

// Verify that all of the entries map to valid entity prototypes.
foreach (var node in mappings.Values)
foreach (var mapping in mappings)
{
var newId = ((ValueDataNode) node).Value;
if (!string.IsNullOrEmpty(newId) && newId != "null")
DebugTools.Assert(_protoMan.HasIndex<EntityPrototype>(newId), $"{newId} is not an entity prototype.");
foreach (var node in mapping.Values)
{
var newId = ((ValueDataNode) node).Value;
if (!string.IsNullOrEmpty(newId) && newId != "null")
DebugTools.Assert(_protoMan.HasIndex<EntityPrototype>(newId),
$"{newId} is not an entity prototype.");
}
}
#endif
}

private bool TryReadFile([NotNullWhen(true)] out MappingDataNode? mappings)
private bool TryReadFile([NotNullWhen(true)] out List<MappingDataNode>? mappings)
{
mappings = null;
var path = new ResPath(MigrationFile);
if (!_resMan.TryContentFileRead(path, out var stream))
return false;

using var reader = new StreamReader(stream, EncodingHelpers.UTF8);
var documents = DataNodeParser.ParseYamlStream(reader).FirstOrDefault();
var files = _resMan.ContentFindFiles(MigrationDir)
.Where(f => f.ToString().EndsWith(".yml"))
.ToList();

if (documents == null)
if (files.Count == 0)
return false;

mappings = (MappingDataNode) documents.Root;
return true;
foreach (var file in files)
{
if (!_resMan.TryContentFileRead(file, out var stream))
continue;

using var reader = new StreamReader(stream, EncodingHelpers.UTF8);
var documents = DataNodeParser.ParseYamlStream(reader).FirstOrDefault();

if (documents == null)
continue;

mappings = mappings ?? new List<MappingDataNode>();
mappings.Add((MappingDataNode)documents.Root);
}

return mappings != null && mappings.Count > 0;
}

private void OnBeforeReadEvent(BeforeEntityReadEvent ev)
{
if (!TryReadFile(out var mappings))
return;

foreach (var (key, value) in mappings)
foreach (var mapping in mappings)
{
if (key is not ValueDataNode keyNode || value is not ValueDataNode valueNode)
continue;
foreach (var (key, value) in mapping)
{
if (key is not ValueDataNode keyNode || value is not ValueDataNode valueNode)
continue;

if (string.IsNullOrWhiteSpace(valueNode.Value) || valueNode.Value == "null")
ev.DeletedPrototypes.Add(keyNode.Value);
else
ev.RenamedPrototypes.Add(keyNode.Value, valueNode.Value);
if (string.IsNullOrWhiteSpace(valueNode.Value) || valueNode.Value == "null")
ev.DeletedPrototypes.Add(keyNode.Value);
else
ev.RenamedPrototypes.Add(keyNode.Value, valueNode.Value);
}
}
}
}
85 changes: 85 additions & 0 deletions Resources/Migrations/deltaMigrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 2023-09-29
PosterContrabandSMSyndie: PosterContrabandSafetyMothSyndie
PosterLegitSMPoisoning: PosterLegitSafetyMothPoisoning
PosterLegitSMBoH: PosterLegitSafetyMothBoH
PosterLegitSMHardhats: PosterLegitSafetyMothHardhat
PosterLegitSMFires: PosterLegitSafetyMothFires
PosterLegitSMPiping: PosterLegitSafetyMothPiping
PosterLegitSMMeth: PosterLegitSafetyMothMeth
PosterLegitSMEpi: PosterLegitSafetyMothEpi
PosterLegitSMPills: PosterLegitSafetyMothPills
PosterLegitSMAnomalies: PosterLegitSafetyMothDelam
PosterLegitSMGlimmer: PosterLegitSafetyMothGlimmer
EngineeringTechFab: Autolathe
EngineeringTechFabCircuitboard: AutolatheMachineCircuitboard
ScienceTechFab: Protolathe
ScienceTechFabCircuitboard: ProtolatheMachineCircuitboard
ServiceTechFab: Autolathe
ServiceTechFabCircuitboard: AutolatheMachineCircuitboard

# 2023-10-05
FoodMothTomatoSauce: null
LockerEpistemicsFilled: LockerScienceFilled
LockerMystagogueFilled: LockerResearchDirectorFilled
LockerEpistemics: LockerScientist
LockerMystagogue: LockerResearchDirector
HyperlinkBookAlerts: BookRandom
HyperlinkBookAtmos: BookAtmosDistro
HyperlinkBookBartending: BookBartendersManual
HyperlinkBookBotany: BookLeafLoversSecret
HyperlinkBookChemistry: BookChemicalCompendium
HyperlinkBookCooking: BookChefGaming
HyperlinkBookGlimmer: BookScientistsGuidebook
HyperlinkBookHacking: BookEngineersHandbook
HyperlinkBookMedical: BookMedicalReferenceBook
HyperlinkBookPower: BookEngineersHandbook
HyperlinkBookProcedure: BookRandom
HyperlinkBookShuttle: BookRandom
HyperlinkBookSpaceLaw: BookSecurity
HyperlinkBookSupernanny: BookHowToSurvive
SpawnPointCataloguer: SpawnPointLibrarian
SpawnPointCyborg: SpawnPointBorg
SpawnPointMedicalCyborg: null
SpawnPointEpistemologist: SpawnPointScientist
SpawnPointMystagogue: SpawnPointResearchDirector
SpawnPointSalvageTechnician: SpawnPointSalvageSpecialist
SpawnPointValet: SpawnPointServiceWorker
VendingMachineEpiDrobe: VendingMachineSciDrobe
PlushieMoffRandom: PlushieMothRandom
PlushieMoffbar: PlushieMothBartender
PlushieMoffsician: PlushieMothMusician
PlushieMoff: PlushieMoth
ArachneWeb: SpiderWeb
PowerCellBluespace: PowerCellHigh
CrateMedicalDefib: CrateMedical
WeaponShotgunEnforcerNonLethal: WeaponShotgunEnforcerRubber

# 2023-10-06
FoodMealTaco: FoodMealSoftTaco
FoodTinBeansOpen: FoodTinBeans
FoodBreadMoldy: FoodBreadMoldySlice
FoodMeatPatty: FoodMeatMeatball
ClothingHeadHoodMystic: ClothingHeadHoodMysta

# 2023-11-07
VendingMachineMailDrobe: VendingMachineCourierDrobe

#Delta V temporary changes. Remove When items are added.
MetempsychoticMachine: CloningPod
MetempsychoticMachineCircuitboard: CloningPodMachineCircuitboard
ComputerShipyard: ComputerBroken
ShipyardComputerCircuitboard: null
SpawnMobGolemCult: null
ShogiBoard: CheckerBoard

# 2023-11-21
AirlockBrigLocked: AirlockSecurityLawyerLocked
AirlockBrigGlassLocked: AirlockSecurityLawyerGlassLocked
WindoorSecureBrigLocked: WindoorSecureSecurityLawyerLocked

#Delta V Optional: Remove "#" for specific maps.
#AsteroidRock: AsteroidAltRock
#AsteroidRockMining: AsteroidAltRockMining

# 2023-12-16
PlushieLizardMirrored: PlushieLizard
90 changes: 0 additions & 90 deletions Resources/migration.yml → Resources/Migrations/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,93 +102,3 @@ ReagentContainerMilkOat: DrinkOatMilkCarton

# 2023-12-20
MiasmaCanister: AmmoniaCanister

## Delta V changes follow ##

# 2023-09-29 (Rebase related migrations)
PosterContrabandSMSyndie: PosterContrabandSafetyMothSyndie
PosterLegitSMPoisoning: PosterLegitSafetyMothPoisoning
PosterLegitSMBoH: PosterLegitSafetyMothBoH
PosterLegitSMHardhats: PosterLegitSafetyMothHardhat
PosterLegitSMFires: PosterLegitSafetyMothFires
PosterLegitSMPiping: PosterLegitSafetyMothPiping
PosterLegitSMMeth: PosterLegitSafetyMothMeth
PosterLegitSMEpi: PosterLegitSafetyMothEpi
PosterLegitSMPills: PosterLegitSafetyMothPills
PosterLegitSMAnomalies: PosterLegitSafetyMothDelam
PosterLegitSMGlimmer: PosterLegitSafetyMothGlimmer
EngineeringTechFab: Autolathe
EngineeringTechFabCircuitboard: AutolatheMachineCircuitboard
ScienceTechFab: Protolathe
ScienceTechFabCircuitboard: ProtolatheMachineCircuitboard
ServiceTechFab: Autolathe
ServiceTechFabCircuitboard: AutolatheMachineCircuitboard

# 2023-10-05 (Rebase related migrations)
FoodMothTomatoSauce: null
LockerEpistemicsFilled: LockerScienceFilled
LockerMystagogueFilled: LockerResearchDirectorFilled
LockerEpistemics: LockerScientist
LockerMystagogue: LockerResearchDirector
HyperlinkBookAlerts: BookRandom
HyperlinkBookAtmos: BookAtmosDistro
HyperlinkBookBartending: BookBartendersManual
HyperlinkBookBotany: BookLeafLoversSecret
HyperlinkBookChemistry: BookChemicalCompendium
HyperlinkBookCooking: BookChefGaming
HyperlinkBookGlimmer: BookScientistsGuidebook
HyperlinkBookHacking: BookEngineersHandbook
HyperlinkBookMedical: BookMedicalReferenceBook
HyperlinkBookPower: BookEngineersHandbook
HyperlinkBookProcedure: BookRandom
HyperlinkBookShuttle: BookRandom
HyperlinkBookSpaceLaw: BookSecurity
HyperlinkBookSupernanny: BookHowToSurvive
SpawnPointCataloguer: SpawnPointLibrarian
SpawnPointCyborg: SpawnPointBorg
SpawnPointMedicalCyborg: null
SpawnPointEpistemologist: SpawnPointScientist
SpawnPointMystagogue: SpawnPointResearchDirector
SpawnPointSalvageTechnician: SpawnPointSalvageSpecialist
SpawnPointValet: SpawnPointServiceWorker
VendingMachineEpiDrobe: VendingMachineSciDrobe
PlushieMoffRandom: PlushieMothRandom
PlushieMoffbar: PlushieMothBartender
PlushieMoffsician: PlushieMothMusician
PlushieMoff: PlushieMoth
ArachneWeb: SpiderWeb
PowerCellBluespace: PowerCellHigh
CrateMedicalDefib: CrateMedical
WeaponShotgunEnforcerNonLethal: WeaponShotgunEnforcerRubber

# 2023-10-06 (Merge related migrations)
FoodMealTaco: FoodMealSoftTaco
FoodTinBeansOpen: FoodTinBeans
FoodBreadMoldy: FoodBreadMoldySlice
FoodMeatPatty: FoodMeatMeatball
ClothingHeadHoodMystic: ClothingHeadHoodMysta

# 2023-11-07 (Merge of MailDrobe and CourierDrobe)
VendingMachineMailDrobe: VendingMachineCourierDrobe

#Delta V temporary changes. Remove When items are added.

MetempsychoticMachine: CloningPod
MetempsychoticMachineCircuitboard: CloningPodMachineCircuitboard
ComputerShipyard: ComputerBroken
ShipyardComputerCircuitboard: null
SpawnMobGolemCult: null
ShogiBoard: CheckerBoard


# 2023-11-21 Delta V
AirlockBrigLocked: AirlockSecurityLawyerLocked
AirlockBrigGlassLocked: AirlockSecurityLawyerGlassLocked
WindoorSecureBrigLocked: WindoorSecureSecurityLawyerLocked

#Delta V Optional: Remove "#" for specific maps.
#AsteroidRock: AsteroidAltRock
#AsteroidRockMining: AsteroidAltRockMining

# 2023-12-16 Delta V - Go fuck yourself lmao I'm not manually merging all that. Seperate your changes next time.
PlushieLizardMirrored: PlushieLizard

0 comments on commit 9c0520f

Please sign in to comment.