Ejemplo n.º 1
0
        /// <summary>
        /// The method that executes to apply a migration.
        /// </summary>
        public override void Migrate()
        {
            var template = User.Template();

            var transaction = DatabaseSession.Instance.CreateTransaction();

            DatabaseSession.Instance.Connector.CreateTable(template, transaction);

            DatabaseSession.Instance.Connector.CreateColumn(typeof(User).GetProperty("Uuid"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(User).GetProperty("ModifiedOn"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(User).GetProperty("CreatedOn"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(User).GetProperty("Username"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(User).GetProperty("Email"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(User).GetProperty("Password"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(User).GetProperty("Salt"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(User).GetProperty("Usergroup"), template, transaction);

            DatabaseSession.Instance.Connector.CreatePrimaryKeyConstraint(template, transaction);

            // create foreign key contraint to usergroup
            var usergroupTemplate = Usergroup.Template();

            DatabaseSession.Instance.Connector.CreateForeignKeyConstraint(typeof(User).GetProperty("Usergroup"), template, typeof(Usergroup).GetProperty("Uuid"), usergroupTemplate, FkDeleteBehaviorKind.RESTRICT, transaction: transaction);

            DatabaseSession.Instance.CommitTransaction(transaction);
        }
        /// <summary>
        /// The method that executes if a migration needs to be rolled back.
        /// </summary>
        public override void Reverse()
        {
            var template    = Usergroup.Template();
            var transaction = DatabaseSession.Instance.CreateTransaction();

            DatabaseSession.Instance.Connector.DeleteTable(template, transaction);

            // commit transaction
            DatabaseSession.Instance.Connector.CommitTransaction(transaction);
        }
        /// <summary>
        /// The method that executes to apply a migration.
        /// </summary>
        public override void Migrate()
        {
            var template = Usergroup.Template();

            var transaction = DatabaseSession.Instance.CreateTransaction();

            DatabaseSession.Instance.Connector.CreateTable(template, transaction);

            DatabaseSession.Instance.Connector.CreateColumn(typeof(Usergroup).GetProperty("Uuid"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(Usergroup).GetProperty("ModifiedOn"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(Usergroup).GetProperty("CreatedOn"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(Usergroup).GetProperty("Name"), template, transaction);
            DatabaseSession.Instance.Connector.CreateColumn(typeof(Usergroup).GetProperty("Permissions"), template, transaction);

            DatabaseSession.Instance.Connector.CreatePrimaryKeyConstraint(template, transaction);

            DatabaseSession.Instance.CommitTransaction(transaction);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The method that executes if a migration needs to be rolled back.
        /// </summary>
        public override void Reverse()
        {
            var transaction = DatabaseSession.Instance.CreateTransaction();

            var UsergroupReferencePropertyInfo = typeof(User).GetProperty("Usergroup");
            var usergroupIdPropertyInfo        = typeof(Usergroup).GetProperty("Uuid");

            DatabaseSession.Instance.Connector.DeleteForeignKeyConstraint(UsergroupReferencePropertyInfo, User.Template(), usergroupIdPropertyInfo, Usergroup.Template(), transaction: transaction);
            DatabaseSession.Instance.CommitTransaction(transaction);
        }