private static List <UpgradeHint> GetTypeRenameHints(string oldVersionSuffix, string newVersionSuffix) { var upgradeContext = UpgradeContext.Demand(); var oldTypes = upgradeContext.ExtractedDomainModel.Types; var hints = new List <UpgradeHint>(); foreach (var type in oldTypes) { var fullName = type.UnderlyingType; int lastDotIndex = fullName.LastIndexOf("."); if (lastDotIndex < 0) { lastDotIndex = 1; } var ns = fullName.Substring(0, lastDotIndex); var name = fullName.Substring(lastDotIndex + 1); if (ns.EndsWith(oldVersionSuffix)) { string newNs = ns.Substring(0, ns.Length - oldVersionSuffix.Length) + newVersionSuffix; string newFullName = newNs + "." + name; Type newType = upgradeContext.Configuration.Types.SingleOrDefault(t => t.FullName == newFullName); if (newType != null) { hints.Add(new RenameTypeHint(fullName, newType)); } } } return(hints); }
public override void OnSchemaReady() { base.OnSchemaReady(); var context = UpgradeContext.Demand(); if (context.Stage != UpgradeStage.Final) { return; } if (ConcreteTableSchemaModifier.IsEnabled || SingleTableSchemaModifier.IsEnabled) { return; } var targetModel = (StorageModel)context.SchemaHints.TargetModel; var schema = targetModel; var tableA = schema.Tables["A"]; var tableB = schema.Tables["B"]; var tableC = schema.Tables["C"]; var tableD = schema.Tables["D"]; var tableE = schema.Tables["E"]; var tableF = schema.Tables["F"]; var tableG = schema.Tables["G"]; var tableH = schema.Tables["H"]; var tableAE = schema.Tables["A-ZeroToMany-E"]; var tableAG = schema.Tables["A-ManyToManyMaster-G"]; // ZeroToOne (A -> B) Assert.AreEqual(0, tableB.ForeignKeys.Count); Assert.AreEqual(1, tableA.ForeignKeys.Count(fk => fk.PrimaryKey == tableB.PrimaryIndex)); // OneToOnePaired (A -> C, C -> A) Assert.AreEqual(1, tableA.ForeignKeys.Count(fk => fk.PrimaryKey == tableC.PrimaryIndex)); Assert.AreEqual(2, tableC.ForeignKeys.Count(fk => fk.PrimaryKey == tableA.PrimaryIndex)); // ManyToOnePaired (A -> D) Assert.AreEqual(1, tableA.ForeignKeys.Count(fk => fk.PrimaryKey == tableD.PrimaryIndex)); Assert.AreEqual(0, tableD.ForeignKeys.Count); // OneToManyPaired (A -> F) Assert.AreEqual(0, tableA.ForeignKeys.Count(fk => fk.PrimaryKey == tableF.PrimaryIndex)); Assert.AreEqual(1, tableF.ForeignKeys.Count(fk => fk.PrimaryKey == tableA.PrimaryIndex)); // ZeroToOne (AE -> A, AE -> E) Assert.AreEqual(1, tableAE.ForeignKeys.Count(fk => fk.PrimaryKey == tableA.PrimaryIndex)); Assert.AreEqual(1, tableAE.ForeignKeys.Count(fk => fk.PrimaryKey == tableE.PrimaryIndex)); // ManyToMany (AG -> A, AG -> G) Assert.AreEqual(1, tableAG.ForeignKeys.Count(fk => fk.PrimaryKey == tableA.PrimaryIndex)); Assert.AreEqual(1, tableAG.ForeignKeys.Count(fk => fk.PrimaryKey == tableG.PrimaryIndex)); // ManyToOneSelfPaired (H -> H) Assert.AreEqual(1, tableH.ForeignKeys.Count(fk => fk.PrimaryKey == tableH.PrimaryIndex)); }
public override void OnSchemaReady() { var context = UpgradeContext.Demand(); hints.ForEach(context.SchemaHints.Add); }