Example #1
0
        public void Visit_with_rename_index_operation()
        {
            var modelBuilder = new BasicModelBuilder();

            modelBuilder.Entity("T",
                                b =>
            {
                b.Property <int>("Id");
                b.Key("Id");
                b.Index("Id").IndexName("IX").IsUnique();
            });

            var renameIndexOperation = new RenameIndexOperation("T", "IX", "IX2");

            var preProcessor = new SQLiteMigrationOperationPreProcessor();
            var context
                = new SQLiteMigrationOperationPreProcessor.Context(
                      new SQLiteMigrationOperationSqlGeneratorFactory().Create(
                          new DatabaseBuilder().GetDatabase(modelBuilder.Model)));

            preProcessor.Visit(renameIndexOperation, context);

            Assert.Equal(2, context.Statements.Count);

            Assert.Equal(@"DROP INDEX ""IX""", context.Statements[0].Sql);
            Assert.Equal(@"CREATE UNIQUE CLUSTERED INDEX ""IX"" ON ""T"" (""Id"")", context.Statements[1].Sql);
        }
Example #2
0
        private static IReadOnlyList <MigrationOperation> PreProcess(
            DatabaseModel database, params MigrationOperation[] operations)
        {
            var context = new SQLiteMigrationOperationPreProcessor.Context(
                new SQLiteMigrationOperationSqlGeneratorFactory().Create(database));

            foreach (var operation in operations)
            {
                operation.Accept(new SQLiteMigrationOperationPreProcessor(), context);
            }

            context.Database = context.Generator.Database.Clone();

            return(context.Handlers.SelectMany(
                       h => h.HandleOperations(context).Concat(context.DeferredOperations)).ToArray());
        }