From 9c0520ff2231479d9532211fe3f4153f430c7833 Mon Sep 17 00:00:00 2001 From: Debug <49997488+DebugOk@users.noreply.github.com> Date: Mon, 15 Jan 2024 17:41:08 +0100 Subject: [PATCH] Seperate migrations into multiple files (#673) * Allow for multiple migration files * Split delta migrations * Update migration.yml --- Content.Server/Maps/MapMigrationSystem.cs | 61 +++++++++------ Resources/Migrations/deltaMigrations.yml | 85 +++++++++++++++++++++ Resources/{ => Migrations}/migration.yml | 90 ----------------------- 3 files changed, 125 insertions(+), 111 deletions(-) create mode 100644 Resources/Migrations/deltaMigrations.yml rename Resources/{ => Migrations}/migration.yml (54%) diff --git a/Content.Server/Maps/MapMigrationSystem.cs b/Content.Server/Maps/MapMigrationSystem.cs index 83c2abc5e38..62885cf819d 100644 --- a/Content.Server/Maps/MapMigrationSystem.cs +++ b/Content.Server/Maps/MapMigrationSystem.cs @@ -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() { @@ -33,30 +33,46 @@ 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(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(newId), + $"{newId} is not an entity prototype."); + } } #endif } - private bool TryReadFile([NotNullWhen(true)] out MappingDataNode? mappings) + private bool TryReadFile([NotNullWhen(true)] out List? 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(); + mappings.Add((MappingDataNode)documents.Root); + } + + return mappings != null && mappings.Count > 0; } private void OnBeforeReadEvent(BeforeEntityReadEvent ev) @@ -64,15 +80,18 @@ 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); + } } } } diff --git a/Resources/Migrations/deltaMigrations.yml b/Resources/Migrations/deltaMigrations.yml new file mode 100644 index 00000000000..3efa662b64a --- /dev/null +++ b/Resources/Migrations/deltaMigrations.yml @@ -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 diff --git a/Resources/migration.yml b/Resources/Migrations/migration.yml similarity index 54% rename from Resources/migration.yml rename to Resources/Migrations/migration.yml index 359ba36ea06..17b397ce6da 100644 --- a/Resources/migration.yml +++ b/Resources/Migrations/migration.yml @@ -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