Пример #1
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("Mayflower.NET Migrator");
            Log("    Directory:        " + dir);
            Log("    Provider:         " + options.Provider);

            _db = new ConnectionContext(options);

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

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

            if (!Migrations.Any())
            {
                Log("No migrations found.");
                return;
            }

            _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();
            }
        }
Пример #2
0
        internal MigrateMode GetMigrateMode(AlreadyRan alreadyRan)
        {
            MigrationRow row;

            if (alreadyRan.ByFilename.TryGetValue(Filename, out row))
            {
                return(row.Hash == Hash ? MigrateMode.Skip : MigrateMode.HashMismatch);
            }

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

            return(MigrateMode.Run);
        }