public override void RegisterMigrations(DbMigrationSet migrations)
        {
            // In LoginModule v 1.1, email template naming conventions changed; so this migration action renames existing templates
              var templateRenamingMap = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) {
            {"MultiFactorEmailSubject" , LoginMessageTemplates.MultiFactorEmailSubject},
            {"MultiFactorEmailBody" , LoginMessageTemplates.MultiFactorEmailBody},
            {"MultiFactorSmsBody" , LoginMessageTemplates.MultiFactorSmsBody},
            {"OneTimePasswordSubject", LoginMessageTemplates.OneTimePasswordSubject},
            {"OneTimePasswordBody",LoginMessageTemplates.OneTimePasswordBody},
            {"PasswordResetCompleteEmailSubject", LoginMessageTemplates.PasswordResetCompleteEmailSubject},
            {"PasswordResetCompleteEmailBody", LoginMessageTemplates.PasswordResetCompleteEmailBody},
            {"PasswordResetPinEmailSubject", LoginMessageTemplates.PasswordResetPinEmailSubject},
            {"PasswordResetPinEmailBody", LoginMessageTemplates.PasswordResetPinEmailBody},
            {"PasswordResetPinSmsBody", LoginMessageTemplates.PasswordResetPinSmsBody},
            {"VerifyEmailSubject", LoginMessageTemplates.VerifyEmailSubject},
            {"VerifyEmailBody", LoginMessageTemplates.VerifyEmailBody},
            {"VerifyPhoneSmsBody", LoginMessageTemplates.VerifySmsBody},
              };

              migrations.AddPostUpgradeAction("1.1.0.0", "UpdateTemplateNames", "Updates Login text templates to new names", (session) => {
            var templateModule = session.Context.App.GetModule<TemplateModule>();
            if (templateModule == null)
            return;
            var templates = session.GetEntities<ITextTemplate>(take: 100);
            foreach (var t in templates) {
              string newName;
              if (templateRenamingMap.TryGetValue(t.Name.Trim(), out newName))
            t.Name = newName;
            }//foreach
            session.SaveChanges();
              });
        }
 public override void RegisterMigrations(DbMigrationSet migrations)
 {
     if (!migrations.IsNewInstall())
     {
         migrations.AddPostUpgradeAction("1.2.0.0", "FactorsPlainValue", "Switch extra factors to storing unencrypted values",
                                         s => UnencryptFactorValues(s));
     }
 }
Exemple #3
0
 public override void RegisterMigrations(DbMigrationSet migrations)
 {
     migrations.AddPostUpgradeAction("1.3.0.0", "CreateDefaultServers", "Creates records for popular OAuth servers",
                                     session => OAuthServers.CreateUpdatePopularServers(session));
     if (!migrations.IsNewInstall())
     {
         migrations.AddPostUpgradeAction("1.3.0.0", "UnencryptOAuthTokens", "Switch tokens to store unencrypted values",
                                         session => UnencryptTokens(session));
     }
 }
 public override void RegisterMigrations(DbMigrationSet migrations)
 {
     migrations.AddPostUpgradeAction("1.1.0.0", "TextTemplateNullableOwner",
       "TextTemplate: Change OwnerId to Nullable, change all Guid.Empty values to NULL.",
     session => {
       var query = session.EntitySet<ITextTemplate>().Where(tt => tt.OwnerId == Guid.Empty).Select(tt => new { Id = tt.Id, OwnerId = (Guid?)null });
       query.ExecuteUpdate<ITextTemplate>();
     });
       /*
       // Other method: using SQL-based migration command; this might be limited to certain server type
       // Notice the use of GetFullTableName helper function
       if (migrations.ServerType == Data.Driver.DbServerType.MsSql) {
     var sql = string.Format("UPDATE {0} SET OwnerId = NULL WHERE OwnerId = '00000000-0000-0000-0000-000000000000';", migrations.GetFullTableName<ITextTemplate>());
     migrations.AddSql("1.0.1.0", "NullableOwner", "Changed OwnerId to Nullable", sql);
       }
        */
 }
Exemple #5
0
        public override void RegisterMigrations(DbMigrationSet migrations)
        {
            migrations.AddPostUpgradeAction("1.1.0.0", "TextTemplateNullableOwner",
                                            "TextTemplate: Change OwnerId to Nullable, change all Guid.Empty values to NULL.",
                                            session => {
                var query = session.EntitySet <ITextTemplate>().Where(tt => tt.OwnerId == Guid.Empty).Select(tt => new { Id = tt.Id, OwnerId = (Guid?)null });
                query.ExecuteUpdate <ITextTemplate>();
            });

            /*
             * // Other method: using SQL-based migration command; this might be limited to certain server type
             * // Notice the use of GetFullTableName helper function
             * if (migrations.ServerType == Data.Driver.DbServerType.MsSql) {
             * var sql = string.Format("UPDATE {0} SET OwnerId = NULL WHERE OwnerId = '00000000-0000-0000-0000-000000000000';", migrations.GetFullTableName<ITextTemplate>());
             * migrations.AddSql("1.0.1.0", "NullableOwner", "Changed OwnerId to Nullable", sql);
             * }
             */
        }//method
            public override void RegisterMigrations(DbMigrationSet migrations)
            {
                //ChildEntityRenamed has added reference column OtherParent (not null); we have to add a script that initializes the column for existing records,
                // otherwise adding foreign key constraint would fail. We set it to the same reference as Parent_Id column.
                // The script timing is 'Middle' - it will be executed AFTER column is added (as nullable), but before it is switched to NOT NULL and ref constraint is added.
                // SQLite does not allow renaming tables
                string tableName = migrations.ServerType == DbServerType.Sqlite ?
                                   "upd_ChildEntity" : migrations.GetFullTableName <IChildEntityRenamed>();
                var sql = string.Format(
                    @"UPDATE {0} SET ""OtherParent_Id"" = ""Parent_Id"" WHERE ""OtherParent_Id"" IS NULL;", tableName);

                migrations.AddSql("1.1.0.0", "InitOtherParentColumn", "Initialize values of IChildEntityRenamed.OtherParent column.",
                                  sql, timing: DbMigrationTiming.Middlle);

                // Let's add a post-upgrade action - it is a code that will be executed after upgrade is done and entity session is available
                // We add a couple of records to a new table.
                migrations.AddPostUpgradeAction("1.1.0.0", "InitNewTable", "Initializes NewTable", session => {
                    var ent1  = session.NewEntity <INewTable>();
                    ent1.Name = "Name1";
                    var ent2  = session.NewEntity <INewTable>();
                    ent2.Name = "Name2";
                    session.SaveChanges(); // this is optional, SaveChanges will be called after all actions are executed.
                });
            } //method
Exemple #7
0
            public override void RegisterMigrations(DbMigrationSet migrations)
            {
                //ChildEntityRenamed has added reference column OtherParent (not null); we have to add a script that initializes the column for existing records,
                // otherwise adding foreign key constraint would fail. We set it to the same reference as Parent_Id column.
                // The script timing is 'Middle' - it will be executed AFTER column is added (as nullable), but before it is switched to NOT NULL and ref constraint is added.
                // SQLite does not allow renaming tables
                string tableName = migrations.ServerType == DbServerType.Sqlite ? "ChildEntity" : migrations.GetFullTableName<IChildEntityRenamed>();
                var sql = string.Format(@"UPDATE {0} SET ""OtherParent_Id"" = ""Parent_Id"" WHERE ""OtherParent_Id"" IS NULL;", tableName);
                migrations.AddSql("1.1.0.0", "InitOtherParentColumn", "Initialize values of IChildEntityRenamed.OtherParent column.", sql, timing: DbMigrationTiming.Middlle);

                // Let's add a post-upgrade action - it is a code that will be executed after upgrade is done and entity session is available
                // We add a couple of records to a new table.
                migrations.AddPostUpgradeAction("1.1.0.0", "InitNewTable", "Initializes NewTable", session => {
                  var ent1 = session.NewEntity<INewTable>();
                  ent1.Name = "Name1";
                  var ent2 = session.NewEntity<INewTable>();
                  ent2.Name = "Name2";
                  session.SaveChanges(); // this is optional, SaveChanges will be called after all actions are executed.
                });
            }
Exemple #8
0
 /// <summary>
 /// Performs Db model update actions, depending on instance type (dev, staging, production). 
 /// </summary>
 public DbUpgradeInfo BuildUpgradeInfo()
 {
     //Even if we do not do db model upgrades, we still may have migration actions (post upgrate), which we will run after completing connection to db
       var driver = _database.DbModel.Driver;
       var loader = driver.CreateDbModelLoader(_database.Settings, _log);
       _upgradeInfo = new DbUpgradeInfo(_database.Settings, _database.DbModel);
       var oldDbVersion = LoadDbVersionInfo(loader);
       if (!CheckCanUpgrade(oldDbVersion))
     return _upgradeInfo;
       _upgradeInfo.OldDbModel = loader.LoadModel();
       _upgradeInfo.OldDbModel.VersionInfo = oldDbVersion;
       //assign prior versions
       //Compare two models and get changes
       var modelComparer = new DbModelComparer();
       modelComparer.AddDbModelChanges(_upgradeInfo, _log);
       //build scripts
       var updater = driver.CreateDbModelUpdater(_database.Settings);
       updater.BuildScripts(_upgradeInfo);
       //Add migrations
       var migrSet = new DbMigrationSet(_app, _database, _upgradeInfo.OldDbModel);
       foreach (var module in this._database.DbModel.EntityApp.Modules) {
     migrSet.CurrentModule = module;
     module.RegisterMigrations(migrSet);
       }
       migrSet.CurrentModule = null;
       _upgradeInfo.AddMigrations(migrSet);
       //Update final status
       _upgradeInfo.VersionsChanged = _database.DbModel.VersionInfo.VersionChanged(oldDbVersion);
       if (_upgradeInfo.AllScripts.Count > 0 || _upgradeInfo.VersionsChanged)
     _upgradeInfo.Status = UpgradeStatus.ChangesDetected;
       else
     _upgradeInfo.Status = UpgradeStatus.NoChanges;
       //Sort, Clear up
       _upgradeInfo.AllScripts.Sort(DbUpgradeScript.CompareExecutionOrder);
       _database.DbModel.ResetPeerRefs(); //drop refs to old model
       return _upgradeInfo;
 }
Exemple #9
0
 public virtual void RegisterMigrations(DbMigrationSet migrations)
 {
 }
Exemple #10
0
 public void AddMigrations(DbMigrationSet migrations)
 {
     var migrScripts = migrations.GetActiveSqlMigrations().Select(m => new DbUpgradeScript(m));
       AllScripts.AddRange(migrScripts);
       PostUpgradeMigrations = migrations.GetActiveActionMigrations().ToList();
 }
Exemple #11
0
 public override void RegisterMigrations(DbMigrationSet migrations)
 {
     base.RegisterMigrations(migrations);
       migrations.AddPostUpgradeAction("1.2.1.0", "CreateDefault", "Creates records for popular OAuth servers",
       session => OAuthServers.CreateUpdatePopularServers(session));
 }