Ejemplo n.º 1
0
        /// <summary>
        /// Create an instance of the migrator object after validation are completed
        /// </summary>
        /// <param name="options"></param>
        internal Migrator(Options options)
        {
            output      = options.Output;
            inputSchema = options.MigrationsTableSchema;

            options.AssertValid();

            isPreview            = options.IsPreview;
            useGlobalTransaction = options.UseGlobalTransaction || isPreview; // always run preview in a global transaction so previous migrations are seen
            force = options.Force;

            string dir = options.GetFolder();

            Log("Minimig Migrator");
            Log($"    Directory:        {dir}");
            Log($"    Provider:         {options.Provider}");

            db = new ConnectionContext(options);

            Migrations = GetAllMigrations(dir, db.CommandSplitter);

            Log($"    Database:         {db.Database}");

            db.Open();

            Log($"    Transaction Mode: {(useGlobalTransaction ? "Global" : "Individual")}");

            if (!ValidateMigrationsSchemaIsAvailable())
            {
                return;
            }

            EnsureMigrationsTableExists();

            alreadyRan = tableExists ? db.GetAlreadyRan() : new AlreadyRan(Enumerable.Empty <MigrationRow>());
            Log($"    Prior Migrations: {alreadyRan.Count}");
            if (alreadyRan.Count > 0)
            {
                var last = alreadyRan.Last;
                Log($"    Last Migration:   \"{last.Filename}\" on {last.ExecutionDate:u}");
            }

            Log();

            if (isPreview && !options.UseGlobalTransaction)
            {
                Log("Using global transaction mode because of preview mode");
                Log();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Classify migrations in order to determine action to take
        /// </summary>
        /// <param name="alreadyRan"></param>
        /// <returns>An enum with the migration mode to execute</returns>
        internal MigrateMode GetMigrateMode(AlreadyRan alreadyRan)
        {
            if (alreadyRan.ByFilename.TryGetValue(Filename, out MigrationRow row))
            {
                return(row.Hash == Hash ? MigrateMode.Skip : MigrateMode.HashMismatch);
            }

            if (alreadyRan.ByHash.TryGetValue(Hash, out _))
            {
                return(MigrateMode.Rename);
            }

            return(MigrateMode.Run);
        }
Ejemplo n.º 3
0
        Migrator(Options options)
        {
            _output = options.Output;

            options.AssertValid();

            _isPreview            = options.IsPreview;
            _useGlobalTransaction = options.UseGlobalTransaction || _isPreview; // always run preview in a global transaction so previous migrations are seen
            _force = options.Force;

            var dir = options.GetFolder();

            Log("Minimig Migrator");
            Log("    Directory:        " + dir);
            Log("    Provider:         " + options.Provider);

            _db = new ConnectionContext(options);

            Migrations = GetAllMigrations(dir, _db.CommandSplitter).ToList();

            Log("    Database:         " + _db.Database);
            _db.Open();

            Log("    Transaction Mode: " + (_useGlobalTransaction ? "Global" : "Individual"));

            EnsureMigrationsTableExists();

            _alreadyRan = _tableExists ? _db.GetAlreadyRan() : new AlreadyRan(Enumerable.Empty <MigrationRow>());
            Log("    Prior Migrations: " + _alreadyRan.Count);
            if (_alreadyRan.Count > 0)
            {
                var last = _alreadyRan.Last;
                Log($"    Last Migration:   \"{last.Filename}\" on {last.ExecutionDate:u}");
            }

            Log();

            if (_isPreview && !options.UseGlobalTransaction)
            {
                Log("Using global transaction mode because of preview mode");
                Log();
            }
        }