/// <param name="migration">Migration parameter</param>
        public void Add(Migration migration)
        {
            if (_migrations.Any(m => m.Type == migration.Type && m.Version == migration.Version))
                throw new NotSupportedException("Migration versions for same type must differ");

            _migrations.AddLast(migration);
        }
Exemple #2
0
        private bool Execute(Migration migration)
        {
            var type = migration.Type;
            var version = migration.Version;
            var dbVersion = _versioner.CurrentVersion(type);

            _logger.Info(string.Format("Database {0} version is : {1}", type, dbVersion));

            if (version <= dbVersion)
            {
                _logger.Debug(string.Format("{0} migration version {1} is less than database version", type, version));
                return true;
            }

            Stopwatch sw = new Stopwatch();
            sw.Start();

            _logger.Info("Executing migration to version " + version);
            try
            {
                migration.Execute(_conn);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Failed to execute {0} migration to version {1}", type, version), ex);
                return false;
            }

            sw.Stop();
            _logger.Info(string.Format("migration to version {0} took {1} seconds.", version, sw.Elapsed.TotalSeconds));

            if (!_versioner.SetVersion(migration))
            {
                _logger.Error("Failed to update database version. Leaving...");
                return false;
            }

            return true;
        }