Exemple #1
0
        public void FlagMigrationAsFinished(IUmbracoMigration migration)
        {
            var migrationName = migration.GetType().Name;

            var migrationHistory = UmbracoDatabase.Single <MigrationHistory>("WHERE Name = @Name", new { Name = migrationName });

            migrationHistory.Completed = true;
            UmbracoDatabase.Update(migrationHistory);
        }
Exemple #2
0
        private void ProcessMigration(IUmbracoMigration umbracoMigration)
        {
            if (_databaseUtil.HasMigrationExecuted(umbracoMigration))
            {
                return;
            }

            _databaseUtil.FlagMigrationAsStarted(umbracoMigration);

            _databaseUtil.UmbracoDatabase.OpenSharedConnection();

            try
            {
                _databaseUtil.UmbracoDatabase.BeginTransaction();

                Log.Info(string.Format("========== Executing migration {0} ==========",
                                       umbracoMigration.GetType().FullName));

                umbracoMigration.Migrate();

                Log.Info(string.Format("---------- Executed migration {0} ----------",
                                       umbracoMigration.GetType().FullName));

                _databaseUtil.FlagMigrationAsFinished(umbracoMigration);

                Log.Info("Transaction completed");
                _databaseUtil.UmbracoDatabase.CompleteTransaction();
            }
            catch (Exception exception)
            {
                Log.Error("Transaction aborted.", exception);
                _databaseUtil.UmbracoDatabase.AbortTransaction();
                throw;
            }
            finally
            {
                Log.Info("Shared connection closed.");
                _databaseUtil.UmbracoDatabase.CloseSharedConnection();
            }
        }
Exemple #3
0
        public string GetText(string relativeName)
        {
            var migrationType = _migration.GetType();
            var assembly      = migrationType.Assembly;
            var fullName      = migrationType.Namespace + "." + relativeName;

            using (var stream = assembly.GetManifestResourceStream(fullName)) {
                if (stream == null)
                {
                    throw new FileNotFoundException("Resource '" + fullName + "' was not found in " + assembly + ".", fullName);
                }

                using (var reader = new StreamReader(stream)) {
                    return(reader.ReadToEnd());
                }
            }
        }
Exemple #4
0
        public bool HasMigrationExecuted(IUmbracoMigration migration)
        {
            var migrationName = migration.GetType().Name;

            try
            {
                UmbracoDatabase.OpenSharedConnection();

                using (var transaction = GetTransaction())
                {
                    var migrationHistory     = UmbracoDatabase.FirstOrDefault <MigrationHistory>("WHERE Name = @Name", new { Name = migrationName });
                    var hasMigrationExecuted = migrationHistory != null;

                    Log.Debug(string.Format("HasMigrationExecuted for {0} is {1}", migrationName, hasMigrationExecuted));

                    transaction.Complete();
                    return(hasMigrationExecuted);
                }
            }
            finally
            {
                UmbracoDatabase.CloseSharedConnection();
            }
        }
Exemple #5
0
        public void FlagMigrationAsStarted(IUmbracoMigration migration)
        {
            try
            {
                UmbracoDatabase.OpenSharedConnection();

                using (var transaction = GetTransaction())
                {
                    var row = new MigrationHistory
                    {
                        Completed = false,
                        Name      = migration.GetType().Name,
                        Timestamp = DateTime.UtcNow
                    };

                    UmbracoDatabase.Insert(row);
                    transaction.Complete();
                }
            }
            finally
            {
                UmbracoDatabase.CloseSharedConnection();
            }
        }