/// <summary>
 /// Initializes a new instance of the <see cref="InstallDatabaseMigrationComponent"/> class.
 /// </summary>
 /// <param name="scopeProvider">
 /// The scope provider.
 /// </param>
 /// <param name="migrationBuilder">
 /// The migration builder.
 /// </param>
 /// <param name="keyValueService">
 /// The key value service.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 public InstallDatabaseMigrationComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     ScopeProvider    = scopeProvider;
     MigrationBuilder = migrationBuilder;
     KeyValueService  = keyValueService;
     Logger           = logger;
 }
Beispiel #2
0
 public InitializePlan(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     _scopeProvider    = scopeProvider;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
     _logger           = logger;
 }
Beispiel #3
0
        public static OperationBuilderSurface <AddColumnOperation> AddColumn <T>(this IMigrationBuilder builder,
                                                                                 string name, string table, string schema = null, string catalog = null,
                                                                                 string storeType     = null, bool?unicode = null, int?size = null, int?precision = null, bool nullable = false,
                                                                                 object defaultValue  = null, string defaultValueSql = null, string computedColumnExpression = null,
                                                                                 string collationName = null, DbType?explicitDbType  = null)
        {
            var op = new AddColumnOperation
            {
                Column = new ColumnDefinition
                {
                    Name = new SubObjectName {
                        Catalog = catalog, ParentName = table, Name = name, Schema = schema
                    },
                    Type                        = ColumnDefinition.InferType(explicitDbType, typeof(T), storeType, size, precision),
                    DefaultValue                = defaultValue,
                    IsNullable                  = nullable,
                    Unicode                     = unicode,
                    DefaultValueSql             = defaultValueSql,
                    ComputedColumnExpressionSql = computedColumnExpression,
                    CollationName               = null,
                }
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <AddColumnOperation>(op));
        }
Beispiel #4
0
 public DatabaseUpgradeComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     _scopeProvider    = scopeProvider;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
     _logger           = logger;
 }
Beispiel #5
0
 public MigrationsRunnerComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     _scopeProvider    = scopeProvider;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
     _logger           = logger;
 }
Beispiel #6
0
 public MaintenanceModeManagerComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     _scopeProvider    = scopeProvider;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
     _logger           = logger;
 }
Beispiel #7
0
        public void DeleteKeysAndIndexesOfTDto()
        {
            IMigrationBuilder builder = Mock.Of <IMigrationBuilder>();

            Mock.Get(builder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                switch (t.Name)
                {
                case "CreateTableOfTDtoMigration":
                    return(new CreateTableOfTDtoMigration(c));

                case "DeleteKeysAndIndexesMigration":
                    return(new DeleteKeysAndIndexesMigration(c));

                default:
                    throw new NotSupportedException();
                }
            });

            using (IScope scope = ScopeProvider.CreateScope())
            {
                var upgrader = new Upgrader(
                    new MigrationPlan("test")
                    .From(string.Empty)
                    .To <CreateTableOfTDtoMigration>("a")
                    .To <DeleteKeysAndIndexesMigration>("done"));

                upgrader.Execute(MigrationPlanExecutor, ScopeProvider, Mock.Of <IKeyValueService>());
                scope.Complete();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MigrationComponent"/> class.
 /// </summary>
 /// <param name="scopeProvider">
 /// The scope provider.
 /// </param>
 /// <param name="migrationBuilder">
 /// The migration builder.
 /// </param>
 /// <param name="keyValueService">
 /// The key value service.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 public MigrationComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     this.scopeProvider    = scopeProvider;
     this.migrationBuilder = migrationBuilder;
     this.keyValueService  = keyValueService;
     this.logger           = logger;
 }
Beispiel #9
0
        public void CreateTableOfTDto()
        {
            IMigrationBuilder builder = Mock.Of <IMigrationBuilder>();

            Mock.Get(builder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                if (t != typeof(CreateTableOfTDtoMigration))
                {
                    throw new NotSupportedException();
                }

                return(new CreateTableOfTDtoMigration(c));
            });

            using (ScopeProvider.CreateScope(autoComplete: true))
            {
                var upgrader = new Upgrader(
                    new MigrationPlan("test")
                    .From(string.Empty)
                    .To <CreateTableOfTDtoMigration>("done"));

                upgrader.Execute(MigrationPlanExecutor, ScopeProvider, Mock.Of <IKeyValueService>());

                var db     = ScopeAccessor.AmbientScope.Database;
                var exists = ScopeAccessor.AmbientScope.SqlContext.SqlSyntax.DoesTableExist(db, "umbracoUser");

                Assert.IsTrue(exists);
            }
        }
 // We will need to interface with a few Umbraco services, we will use dependency injection to achieve this
 public BlogPostHighFiveComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     _scopeProvider    = scopeProvider;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
     _logger           = logger;
 }
        public void CreateTableOfTDto()
        {
            IMigrationBuilder builder = Mock.Of <IMigrationBuilder>();

            Mock.Get(builder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                if (t != typeof(CreateTableOfTDtoMigration))
                {
                    throw new NotSupportedException();
                }

                return(new CreateTableOfTDtoMigration(c));
            });

            using (IScope scope = ScopeProvider.CreateScope())
            {
                var upgrader = new Upgrader(
                    new MigrationPlan("test")
                    .From(string.Empty)
                    .To <CreateTableOfTDtoMigration>("done"));

                upgrader.Execute(MigrationPlanExecutor, ScopeProvider, Mock.Of <IKeyValueService>());

                var  helper = new DatabaseSchemaCreator(scope.Database, LoggerFactory.CreateLogger <DatabaseSchemaCreator>(), LoggerFactory, UmbracoVersion, EventAggregator);
                bool exists = helper.TableExists("umbracoUser");
                Assert.IsTrue(exists);

                scope.Complete();
            }
        }
 public UmbracoStartup(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     _scopeProvider    = scopeProvider;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
     _logger           = logger;
 }
Beispiel #13
0
 public UiExamplesMigrationComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, IProfilingLogger profilingLogger)
 {
     _scopeProvider    = scopeProvider;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
     _profilingLogger  = profilingLogger;
 }
Beispiel #14
0
 public PersonalisationMigrationComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     _scopeProvider    = scopeProvider ?? throw new ArgumentNullException(nameof(scopeProvider));
     _migrationBuilder = migrationBuilder ?? throw new ArgumentNullException(nameof(migrationBuilder));
     _keyValueService  = keyValueService ?? throw new ArgumentNullException(nameof(keyValueService));
     _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
 }
        public void MigrationCanAddPostMigration()
        {
            IMigrationBuilder builder = Mock.Of <IMigrationBuilder>();

            Mock.Get(builder)
            .Setup(x => x.Build(It.IsAny <Type>(), It.IsAny <IMigrationContext>()))
            .Returns <Type, IMigrationContext>((t, c) =>
            {
                switch (t.Name)
                {
                case nameof(NoopMigration):
                    return(new NoopMigration(c));

                case nameof(TestMigration):
                    return(new TestMigration(c));

                case nameof(TestPostMigration):
                    return(new TestPostMigration(c));

                default:
                    throw new NotSupportedException();
                }
            });

            var    database = new TestDatabase();
            IScope scope    = Mock.Of <IScope>(x => x.Notifications == Mock.Of <IScopedNotificationPublisher>());

            Mock.Get(scope)
            .Setup(x => x.Database)
            .Returns(database);

            var sqlContext = new SqlContext(
                new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())),
                DatabaseType.SQLCe,
                Mock.Of <IPocoDataFactory>());
            var scopeProvider = new MigrationTests.TestScopeProvider(scope)
            {
                SqlContext = sqlContext
            };

            MigrationPlan plan = new MigrationPlan("Test")
                                 .From(string.Empty).To <TestMigration>("done");

            TestMigration.MigrateCount     = 0;
            TestPostMigration.MigrateCount = 0;

            new MigrationContext(plan, database, s_loggerFactory.CreateLogger <MigrationContext>());

            var upgrader = new Upgrader(plan);
            IMigrationPlanExecutor executor = GetMigrationPlanExecutor(scopeProvider, scopeProvider, builder);

            upgrader.Execute(
                executor,
                scopeProvider,
                Mock.Of <IKeyValueService>());

            Assert.AreEqual(1, TestMigration.MigrateCount);
            Assert.AreEqual(1, TestPostMigration.MigrateCount);
        }
Beispiel #16
0
 public ConfigureDatabase(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder,
                          IKeyValueService keyValueService, ILogger logger)
 {
     this.scopeProvider    = scopeProvider;
     this.migrationBuilder = migrationBuilder;
     this.keyValueService  = keyValueService;
     this.logger           = logger;
 }
Beispiel #17
0
 public MigrationUpgradeComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
 {
     this.scopeProvider             = scopeProvider;
     this.migrationBuilder          = migrationBuilder;
     this.keyValueService           = keyValueService;
     this.logger                    = logger;
     ConnectorContext.ScopeProvider = scopeProvider;
 }
 public TagManagerStartup(IScopeProvider scopeProvider, ILogger logger, IMigrationBuilder migrationBuilder,
                          IKeyValueService keyValueService)
 {
     _scopeProvider    = scopeProvider;
     _logger           = logger;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
 }
Beispiel #19
0
        protected override void ConfigureUpgrade(IMigrationBuilder builder)
        {
            var db = Context.Container.Resolve <IConnectionMultiplexer>().GetDatabase();

            builder.Step("Add thirteen", () =>
            {
                db.StringSetAsync("thirteen", "OMG OMG OMG");
            });
        }
Beispiel #20
0
        /// <summary>
        /// Executes.
        /// </summary>
        /// <param name="scopeProvider">A scope provider.</param>
        /// <param name="migrationBuilder">A migration builder.</param>
        /// <param name="keyValueService">A key-value service.</param>
        /// <param name="logger">A logger.</param>
        public void Execute(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
        {
            if (scopeProvider == null)
            {
                throw new ArgumentNullException(nameof(scopeProvider));
            }
            if (migrationBuilder == null)
            {
                throw new ArgumentNullException(nameof(migrationBuilder));
            }
            if (keyValueService == null)
            {
                throw new ArgumentNullException(nameof(keyValueService));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            var plan = Plan;

            using (var scope = scopeProvider.CreateScope())
            {
                BeforeMigrations(scope, logger);

                // read current state
                var currentState = keyValueService.GetValue(StateValueKey);
                var forceState   = false;

                if (currentState == null)
                {
                    currentState = plan.InitialState;
                    forceState   = true;
                }

                // execute plan
                var state = plan.Execute(scope, currentState, migrationBuilder, logger);
                if (string.IsNullOrWhiteSpace(state))
                {
                    throw new Exception("Plan execution returned an invalid null or empty state.");
                }

                // save new state
                if (forceState)
                {
                    keyValueService.SetValue(StateValueKey, state);
                }
                else if (currentState != state)
                {
                    keyValueService.SetValue(StateValueKey, currentState, state);
                }

                AfterMigrations(scope, logger);

                scope.Complete();
            }
        }
Beispiel #21
0
 public MigrationPlanExecutor(
     IScopeProvider scopeProvider,
     ILoggerFactory loggerFactory,
     IMigrationBuilder migrationBuilder)
 {
     _scopeProvider    = scopeProvider;
     _loggerFactory    = loggerFactory;
     _migrationBuilder = migrationBuilder;
     _logger           = _loggerFactory.CreateLogger <MigrationPlanExecutor>();
 }
Beispiel #22
0
        public static OperationBuilderSurface <DropSequenceOperation> DropSequence(this IMigrationBuilder builder, string name, string schema = null, string catalog = null)
        {
            var op = new DropSequenceOperation
            {
                Name = new ObjectName(catalog, schema, name)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <DropSequenceOperation>(op));
        }
Beispiel #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseBuilder"/> class.
 /// </summary>
 public DatabaseBuilder(IScopeProvider scopeProvider, IGlobalSettings globalSettings, IUmbracoDatabaseFactory databaseFactory, IRuntimeState runtime, ILogger logger, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService)
 {
     _scopeProvider    = scopeProvider;
     _globalSettings   = globalSettings;
     _databaseFactory  = databaseFactory;
     _runtime          = runtime;
     _logger           = logger;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
 }
        public static OperationBuilderSurface <CreateSchemaOperation> CreateSchema(this IMigrationBuilder builder, string schema, string catalog = null)
        {
            var op = new CreateSchemaOperation
            {
                Name = new ObjectName(catalog, schema, null)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <CreateSchemaOperation>(op));
        }
 public PageNotFoundManagerComponent(IScopeProvider scopeProvider,
                                     IMigrationBuilder migrationBuilder,
                                     IKeyValueService keyValueService,
                                     ILogger logger)
 {
     this.scopeProvider    = scopeProvider ?? throw new System.ArgumentNullException(nameof(scopeProvider));
     this.migrationBuilder = migrationBuilder ?? throw new System.ArgumentNullException(nameof(migrationBuilder));
     this.keyValueService  = keyValueService ?? throw new System.ArgumentNullException(nameof(keyValueService));
     this.logger           = logger ?? throw new System.ArgumentNullException(nameof(logger));
 }
 public void Up(IMigrationBuilder migrationBuilder)
 {
     var patient = migrationBuilder.CreateTable("patient")
         .InSchema("adt");
     patient.AddColumn("id")
         .HasType("int")
         .IsPrimaryKey();
     patient.AddColumn("name")
         .HasType("text");
 }
        public static OperationBuilderSurface <DropColumnOperation> DropColumn(this IMigrationBuilder builder, string name, string table, string schema = null, string catalog = null)
        {
            var op = new DropColumnOperation
            {
                Name = new SubObjectName(catalog, schema, table, name)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <DropColumnOperation>(op));
        }
Beispiel #28
0
 public DoStuffRepoPatternComponent(
     IScopeProvider scopeProvider,
     IMigrationBuilder migrationBuilder,
     IKeyValueService keyValueService,
     IProfilingLogger logger)
 {
     this.scopeProvider    = scopeProvider;
     this.migrationBuilder = migrationBuilder;
     this.keyValueService  = keyValueService;
     this.logger           = logger;
 }
Beispiel #29
0
 public ContentmentComponent(
     IScopeProvider scopeProvider,
     IMigrationBuilder migrationBuilder,
     IKeyValueService keyValueService,
     IProfilingLogger logger)
 {
     _scopeProvider    = scopeProvider;
     _migrationBuilder = migrationBuilder;
     _keyValueService  = keyValueService;
     _logger           = logger;
 }
Beispiel #30
0
        public static OperationBuilderSurface <RenameColumnOperation> RenameColumn(this IMigrationBuilder builder, string oldName, string newName, string table, string schema = null, string catalog = null)
        {
            var op = new RenameColumnOperation
            {
                OldName = new SubObjectName(catalog, schema, table, oldName),
                NewName = new SubObjectName(catalog, schema, table, newName)
            };

            builder.AddOperation(op);
            return(new OperationBuilderSurface <RenameColumnOperation>(op));
        }
 public MigrationComponent(
     IScopeProvider scopeProvider,
     IMigrationBuilder migrationBuilder,
     IMigrationPlanExecutor migrationPlanExecutor,
     IKeyValueService keyValueService)
 {
     _scopeProvider         = scopeProvider;
     _migrationBuilder      = migrationBuilder;
     _migrationPlanExecutor = migrationPlanExecutor;
     _keyValueService       = keyValueService;
 }