public void SetsRequiresReprojectionOnTablesWithNewColumns()
        {
            Document <Entity>();
            Document <AbstractEntity>();
            Document <DerivedEntity>();
            Document <OtherEntity>();

            store.Initialize();

            using (var session = store.OpenSession())
            {
                session.Store(new Entity());
                session.Store(new Entity());
                session.Store(new DerivedEntity());
                session.Store(new DerivedEntity());
                session.Store(new OtherEntity());
                session.Store(new OtherEntity());
                session.SaveChanges();
            }

            var runner = new SchemaMigrationRunner(store,
                                                   new FakeSchemaDiffer(
                                                       new AddColumn("Entities", new Column("NewCol", typeof(int))),
                                                       new AddColumn("AbstractEntities", new Column("NewCol", typeof(int)))));

            runner.Run();

            store.Database.RawQuery <bool>("select AwaitsReprojection from Entities").ShouldAllBe(x => x);
            store.Database.RawQuery <bool>("select AwaitsReprojection from AbstractEntities").ShouldAllBe(x => x);
            store.Database.RawQuery <bool>("select AwaitsReprojection from OtherEntities").ShouldAllBe(x => !x);
        }
        public void AutomaticallyCreatesMetadataTable()
        {
            var runner = new SchemaMigrationRunner(store, new SchemaDiffer());

            runner.Run();

            configuration.Tables.ShouldContainKey("HybridDb");
            store.Database.RawQuery <int>("select top 1 SchemaVersion from HybridDb").Single().ShouldBe(0);
        }
        public void DoesNotRunUnsafeSchemaMigrations()
        {
            CreateMetadataTable();

            UseMigrations(new InlineMigration(1, new UnsafeThrowingCommand()));

            var runner = new SchemaMigrationRunner(store,
                                                   new FakeSchemaDiffer(new UnsafeThrowingCommand()));

            Should.NotThrow(() => runner.Run());
        }
        public void DoesNothingWhenTurnedOff()
        {
            DisableMigrations();
            CreateMetadataTable();

            var runner = new SchemaMigrationRunner(store, new SchemaDiffer());

            runner.Run();

            configuration.Tables.ShouldNotContainKey("HybridDb");
            store.Database.RawQuery <int>("select top 1 SchemaVersion from HybridDb").Any().ShouldBe(false);
        }
Example #5
0
        public void DoesNothingGivenNoMigrations()
        {
            var runner = new SchemaMigrationRunner(store, new FakeSchemaDiffer());

            runner.Run();

            var schemaAfter = store.Database.QuerySchema();

            // Documents table is not created because of the fake differ
            schemaAfter.Count.ShouldBe(1);
            schemaAfter.ShouldContainKey("HybridDb");
        }
Example #6
0
        public void UnsafeSchemaMigrations_NoRunWhenInferred()
        {
            CreateMetadataTable();

            var command = new UnsafeCountingCommand();

            var runner = new SchemaMigrationRunner(store, new FakeSchemaDiffer(command));

            runner.Run();

            command.NumberOfTimesCalled.ShouldBe(0);
        }
        public void DoesNothingGivenNoMigrations()
        {
            CreateMetadataTable();

            var runner = new SchemaMigrationRunner(store, new FakeSchemaDiffer());

            runner.Run();

            var schema = store.Database.QuerySchema();

            schema.Count.ShouldBe(1);
            schema.ShouldContainKey("HybridDb"); // the metadata table and nothing else
        }
Example #8
0
        public void UnsafeSchemaMigrations_RunsWhenProvided()
        {
            CreateMetadataTable();

            var command = new UnsafeCountingCommand();

            UseMigrations(new InlineMigration(1, command));

            var runner = new SchemaMigrationRunner(store, new FakeSchemaDiffer());

            runner.Run();

            command.NumberOfTimesCalled.ShouldBe(1);
        }
        public void DoesNotRunSchemaMigrationTwice()
        {
            CreateMetadataTable();

            var command = new CountingCommand();

            UseMigrations(new InlineMigration(1, command));

            var runner = new SchemaMigrationRunner(store, new FakeSchemaDiffer());

            runner.Run();
            runner.Run();

            command.NumberOfTimesCalled.ShouldBe(1);
        }
        public void RunsDiffedSchemaMigrations()
        {
            CreateMetadataTable();

            var runner = new SchemaMigrationRunner(store,
                                                   new FakeSchemaDiffer(
                                                       new CreateTable(new Table("Testing", new Column("Id", typeof(Guid), isPrimaryKey: true))),
                                                       new AddColumn("Testing", new Column("Noget", typeof(int)))));

            runner.Run();

            var tables = store.Database.QuerySchema();

            tables.ShouldContainKey("Testing");
            tables["Testing"]["Id"].ShouldNotBe(null);
            tables["Testing"]["Noget"].ShouldNotBe(null);
        }
        public void DoesNotRunProvidedSchemaMigrationsOnTempTables(TableMode mode)
        {
            Use(mode);

            UseTableNamePrefix(Guid.NewGuid().ToString());
            CreateMetadataTable();

            UseMigrations(new InlineMigration(1,
                                              new CreateTable(new Table("Testing", new Column("Id", typeof(Guid), isPrimaryKey: true))),
                                              new AddColumn("Testing", new Column("Noget", typeof(int)))));

            var runner = new SchemaMigrationRunner(store, new FakeSchemaDiffer());

            runner.Run();

            var tables = store.Database.QuerySchema();

            tables.ShouldNotContainKey("Testing");
        }
        public void RollsBackOnExceptions()
        {
            CreateMetadataTable();

            try
            {
                var runner = new SchemaMigrationRunner(store,
                                                       new FakeSchemaDiffer(
                                                           new CreateTable(new Table("Testing", new Column("Id", typeof(Guid), isPrimaryKey: true))),
                                                           new ThrowingCommand()));

                runner.Run();
            }
            catch (Exception)
            {
            }

            store.Database.QuerySchema().ShouldNotContainKey("Testing");
        }
        public void RunsProvidedSchemaMigrationsInOrderThenDiffed()
        {
            CreateMetadataTable();

            var table = new Table("Testing", new Column("Id", typeof(Guid), isPrimaryKey: true));

            UseMigrations(
                new InlineMigration(2, new AddColumn("Testing", new Column("Noget", typeof(int)))),
                new InlineMigration(1, new CreateTable(table)));

            var runner = new SchemaMigrationRunner(store,
                                                   new FakeSchemaDiffer(new RenameColumn(table, "Noget", "NogetNyt")));

            runner.Run();

            var tables = store.Database.QuerySchema();

            tables.ShouldContainKey("Testing");
            tables["Testing"]["Id"].ShouldNotBe(null);
            tables["Testing"]["NogetNyt"].ShouldNotBe(null);
        }