コード例 #1
0
ファイル: Migration.cs プロジェクト: silky/Hadoken
 public void ExecuteResource(DataPlatformType dataPlatformType, string name)
 {
     if (String.IsNullOrEmpty(name) == false)
     {
         MigrationRunner.ExecuteResource($"{dataPlatformType.ToString()}.{name}");
     }
 }
コード例 #2
0
        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}...");
                    }
                }
            }
        }
コード例 #3
0
ファイル: M0001.cs プロジェクト: silky/Hadoken
        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");
        }
コード例 #4
0
ファイル: Migration.cs プロジェクト: silky/Hadoken
 public virtual void Rollback(DataPlatformType dataPlatformType)
 {
 }
コード例 #5
0
ファイル: Migration.cs プロジェクト: silky/Hadoken
 public virtual void Apply(DataPlatformType dataPlatformType)
 {
 }
コード例 #6
0
 public DataPlatformAttribute(DataPlatformType dataPlatformType)
 {
     _dataPlatformType = dataPlatformType;
 }