public void ExecuteResource(DataPlatformType dataPlatformType, string name) { if (String.IsNullOrEmpty(name) == false) { MigrationRunner.ExecuteResource($"{dataPlatformType.ToString()}.{name}"); } }
public void ExecuteMigrations() { CheckDatabase(); int migrationState = GetMigrationState(); List <Migration> migrations = new List <Migration>(); _assembly.GetExportedTypes() .Where(m => ( (m.BaseType == typeof(Migration)) && (m.GetCustomAttributes().Select(n => (n.GetType())).Contains(typeof(MigrationAttribute)) == true) )) .ToList() .ForEach(m => migrations.Add((Migration)(_assembly.CreateInstance(m.FullName)))); migrations = migrations.Where(m => (m != null)).ToList(); OutputStreams.WriteLine($"Found {migrations.Count} migrations."); foreach (Migration migration in migrations) { IEnumerable <Attribute> customAttributes = migration.GetType().GetCustomAttributes(); MigrationAttribute migrationAttribute = customAttributes.OfType <MigrationAttribute>().FirstOrDefault(); DataPlatformAttribute dataPlatformAttribute = customAttributes.OfType <DataPlatformAttribute>().FirstOrDefault(); DataPlatformType dataPlatformType = ((dataPlatformAttribute == null) ? DataPlatformType.Unknown : dataPlatformAttribute.DataPlatformType); OutputStreams.WriteLine($"Found migration {migrationAttribute.Value}"); if (dataPlatformType != DataPlatformType.Unknown) { if ((migrationAttribute.Value > migrationState) && (migrationAttribute.IsIgnore == false)) { try { OutputStreams.WriteLine($"Applying migration {migrationAttribute.Value}..."); migration.Apply(dataPlatformType); migrationState = BumpMigrationState(); } catch { migration.Rollback(dataPlatformType); throw; } } else { OutputStreams.WriteLine($"Skipping migration {migrationAttribute.Value}..."); } } } }
public override void Apply(DataPlatformType dataPlatformType) { // Tables ExecuteResource(dataPlatformType, "dbo.Group.sql"); ExecuteResource(dataPlatformType, "dbo.Element.sql"); // Functions ExecuteResource(dataPlatformType, "dbo.spGetElement.sql"); // Data ExecuteResource(dataPlatformType, "Groups.sql"); ExecuteResource(dataPlatformType, "Elements.sql"); }
public virtual void Rollback(DataPlatformType dataPlatformType) { }
public virtual void Apply(DataPlatformType dataPlatformType) { }
public DataPlatformAttribute(DataPlatformType dataPlatformType) { _dataPlatformType = dataPlatformType; }