public void AlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            var tempResources = WriteOutFirebirdEmbeddedLibrariesToCurrentWorkingDirectory();
            var tempFile      = Path.GetTempFileName();

            using (var deleter = new AutoDeleter(tempFile))
            {
                File.Delete(tempFile);
                deleter.Add(tempResources);
                var connectionString = GetConnectionStringToTempDatabaseAt(tempFile);

                var runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations"
                };
                try
                {
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        options.TruncateLongNames = false;
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                        processor.CommitTransaction();
                        FbConnection.ClearPool(connection);
                    }
                    //---------------Assert Precondition----------------
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                                  "Foreign key does not exist after first migration");
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichAltersTableWithFK());
                        processor.CommitTransaction();
                    }
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                                  "Foreign key does not exist after second migration");
                }
                catch (Exception ex)
                {
                    try { File.Copy(tempFile, "C:\\tmp\\fm_tests.fdb", true); }
                    catch { }
                    throw ex;
                }
            }
        }
        public FirebirdColumn([NotNull] FirebirdOptions fbOptions, FirebirdQuoter quoter) : base(new FirebirdTypeMap(), quoter)
        {
            FBOptions = fbOptions;

            //In firebird DEFAULT clause precedes NULLABLE clause
            ClauseOrder = new List <Func <ColumnDefinition, string> > {
                FormatString, FormatType, FormatDefaultValue, FormatNullable, FormatPrimaryKey, FormatIdentity
            };
        }
        private static FirebirdGenerator CreateFixture(QuoterOptions options = null)
        {
            var fbOptions = FirebirdOptions.StandardBehaviour();

            return(new FirebirdGenerator(
                       new FirebirdQuoter(fbOptions, new OptionsWrapper <QuoterOptions>(options)),
                       FirebirdOptions.StandardBehaviour(),
                       new OptionsWrapper <GeneratorOptions>(new GeneratorOptions())));
        }
Ejemplo n.º 4
0
        public FirebirdColumn(FirebirdOptions fbOptions) : base(new FirebirdTypeMap(), new FirebirdQuoter(fbOptions.ForceQuote))
        {
            FBOptions = fbOptions ?? throw new ArgumentNullException(nameof(fbOptions));

            //In firebird DEFAULT clause precedes NULLABLE clause
            ClauseOrder = new List <Func <ColumnDefinition, string> > {
                FormatString, FormatType, FormatDefaultValue, FormatNullable, FormatPrimaryKey, FormatIdentity
            };
        }
        public static bool ColumnTypesMatch(ColumnDefinition col1, ColumnDefinition col2)
        {
            var            fbOptions = new FirebirdOptions();
            FirebirdColumn column    = new FirebirdColumn(fbOptions, new FirebirdQuoter(fbOptions, new OptionsWrapper <QuoterOptions>(new QuoterOptions())));
            string         colDef1   = column.GenerateForTypeAlter(col1);
            string         colDef2   = column.GenerateForTypeAlter(col2);

            return(colDef1 == colDef2);
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            if (!System.IO.File.Exists("fbtest.fdb"))
            {
                FbConnection.CreateDatabase(IntegrationTestOptions.Firebird.ConnectionString);
            }
            Connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString);
            var options = FirebirdOptions.AutoCommitBehaviour();

            Processor = new FirebirdProcessor(Connection, new FirebirdGenerator(options), new TextWriterAnnouncer(System.Console.Out), new ProcessorOptions(), new FirebirdDbFactory(), options);
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            FbDatabase.CreateDatabase(IntegrationTestOptions.Firebird.ConnectionString);

            Connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString);
            var options = FirebirdOptions.AutoCommitBehaviour();

            Processor = new FirebirdProcessor(Connection, new FirebirdGenerator(options), new TextWriterAnnouncer(System.Console.Out), new ProcessorOptions(), new FirebirdDbFactory(), options);
            Connection.Open();
            Processor.BeginTransaction();
        }
Ejemplo n.º 8
0
        public FirebirdGenerator(
            [NotNull] FirebirdQuoter quoter,
            [NotNull] FirebirdOptions fbOptions,
            [NotNull] IOptions <GeneratorOptions> generatorOptions)
            : base(new FirebirdColumn(fbOptions), quoter, new EmptyDescriptionGenerator(), generatorOptions)
        {
            FBOptions = fbOptions ?? throw new ArgumentNullException(nameof(fbOptions));
#pragma warning disable 618
            truncator = new FirebirdTruncator(FBOptions.TruncateLongNames, FBOptions.PackKeyNames);
#pragma warning restore 618
        }
Ejemplo n.º 9
0
        private static MigrationRunner CreateFirebirdEmbeddedRunnerFor(FbConnection connection, RunnerContext runnerContext, out FirebirdProcessor processor)
        {
            var announcer = new TextWriterAnnouncer(System.Console.Out);

            announcer.ShowSql = true;
            var options = FirebirdOptions.AutoCommitBehaviour();

            processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                              new ProcessorOptions(), new FirebirdDbFactory(), options);
            var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);

            return(runner);
        }
        public void ConfigureEntityFramework(IServiceCollection services)
        {
            Console.WriteLine($"Using Batch Size: {AppConfig.EfBatchSize}");
            if (AppConfig.EfSchema != null)
            {
                Console.WriteLine($"Using Schema: {AppConfig.EfSchema}");
            }

            services.AddDbContext <AppDb>(
                options => options.UseFirebird(AppConfig.Config["Data:ConnectionString"],
                                               FirebirdOptions => FirebirdOptions.MaxBatchSize(AppConfig.EfBatchSize)),
                ServiceLifetime.Scoped);
        }
        public void ObsoleteAlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            using (var tempDb = new TemporaryDatabase(IntegrationTestOptions.Firebird, _firebirdLibraryProber))
            {
                var connectionString = tempDb.ConnectionString;

                var runnerContext = new RunnerContext(new TextWriterAnnouncer(TestContext.Out))
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations"
                };

                using (var connection = new FbConnection(connectionString))
                {
                    var announcer = new TextWriterAnnouncer(TestContext.Out)
                    {
                        ShowSql = true
                    };
                    var options = FirebirdOptions.AutoCommitBehaviour();
                    options.TruncateLongNames = false;
                    var processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                    var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                    runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                    processor.CommitTransaction();
                    FbConnection.ClearPool(connection);
                }

                //---------------Assert Precondition----------------
                Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                              "Foreign key does not exist after first migration");
                using (var connection = new FbConnection(connectionString))
                {
                    var announcer = new TextWriterAnnouncer(TestContext.Out)
                    {
                        ShowSql = true
                    };
                    var options   = FirebirdOptions.AutoCommitBehaviour();
                    var processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                    var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                    runner.Up(new MigrationWhichAltersTableWithFK());
                    processor.CommitTransaction();
                }

                Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                              "Foreign key does not exist after second migration");
            }
        }
        public void SetUp()
        {
            if (!IntegrationTestOptions.Firebird.IsEnabled)
            {
                Assert.Ignore();
            }
            _temporaryDatabase = new TemporaryDatabase(
                IntegrationTestOptions.Firebird,
                _prober);
            Connection = new FbConnection(_temporaryDatabase.ConnectionString);
            var options = FirebirdOptions.AutoCommitBehaviour();

            Processor = new FirebirdProcessor(Connection, new FirebirdGenerator(options), new TextWriterAnnouncer(TestContext.Out), new ProcessorOptions(), new FirebirdDbFactory(), options);
            Connection.Open();
            Processor.BeginTransaction();
        }
        public static bool DefaultValuesMatch(ColumnDefinition col1, ColumnDefinition col2)
        {
            if (col1.DefaultValue is ColumnDefinition.UndefinedDefaultValue && col2.DefaultValue is ColumnDefinition.UndefinedDefaultValue)
            {
                return(true);
            }
            if (col1.DefaultValue is ColumnDefinition.UndefinedDefaultValue || col2.DefaultValue is ColumnDefinition.UndefinedDefaultValue)
            {
                return(true);
            }

            var            fbOptions = new FirebirdOptions();
            FirebirdColumn column    = new FirebirdColumn(fbOptions, new FirebirdQuoter(fbOptions, new OptionsWrapper <QuoterOptions>(new QuoterOptions())));
            string         col1Value = column.GenerateForDefaultAlter(col1);
            string         col2Value = column.GenerateForDefaultAlter(col2);

            return(col1Value != col2Value);
        }
Ejemplo n.º 14
0
        protected static void ExecuteWithFirebird(Action <IMigrationProcessor> test, IntegrationTestOptions.DatabaseServerOptions serverOptions)
        {
            if (!serverOptions.IsEnabled)
            {
                return;
            }

            var announcer = new TextWriterAnnouncer(System.Console.Out);

            announcer.ShowSql = true;
            announcer.Heading("Testing Migration against Firebird Server");

            if (!System.IO.File.Exists("fbtest.fdb"))
            {
                FbConnection.CreateDatabase(serverOptions.ConnectionString);
            }

            using (var connection = new FbConnection(serverOptions.ConnectionString))
            {
                var options   = FirebirdOptions.AutoCommitBehaviour();
                var processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer, new ProcessorOptions(), new PostgresDbFactory(), options);

                try
                {
                    test(processor);
                }
                catch (Exception e)
                {
                    if (!processor.WasCommitted)
                    {
                        processor.RollbackTransaction();
                    }
                    throw e;
                }


                if (!processor.WasCommitted)
                {
                    processor.RollbackTransaction();
                }

                connection.Close();
            }
        }
Ejemplo n.º 15
0
 public void Setup()
 {
     Generator = new FirebirdGenerator(FirebirdOptions.StandardBehaviour());
 }
Ejemplo n.º 16
0
        public void CanParseFoceQuoteFromProviderOptions(string options, bool expectedValue)
        {
            var fbOpt = new FirebirdOptions().ApplyProviderSwitches(options);

            Assert.AreEqual(expectedValue, fbOpt.ForceQuote);
        }
Ejemplo n.º 17
0
 public FirebirdGenerator(
     [NotNull] FirebirdOptions fbOptions,
     [NotNull] IOptions <GeneratorOptions> generatorOptions)
     : this(new FirebirdQuoter(fbOptions.ForceQuote), fbOptions, generatorOptions)
 {
 }
Ejemplo n.º 18
0
 public FirebirdGenerator(
     [NotNull] FirebirdOptions fbOptions)
     : this(fbOptions, new OptionsWrapper <GeneratorOptions>(new GeneratorOptions()))
 {
 }
Ejemplo n.º 19
0
        private FirebirdProcessor MakeProcessor()
        {
            var options = FirebirdOptions.AutoCommitBehaviour();

            return(new FirebirdProcessor(_connection, new FirebirdGenerator(options), new TextWriterAnnouncer(TestContext.Out), new ProcessorOptions(), new FirebirdDbFactory(), options));
        }
 public FirebirdGeneratorTests()
 {
     generator = new FirebirdGenerator(FirebirdOptions.StandardBehaviour());
 }
Ejemplo n.º 21
0
 public FirebirdQuoter(FirebirdOptions options)
     : this(options.ForceQuote)
 {
 }
Ejemplo n.º 22
0
        public void AlterTable_MigrationRequiresAutomaticDelete_AndProcessorHasUndoDisabled_ShouldNotThrow()
        {
            // this test was originally created to investigate an issue with foreign key names but in the process,
            // I found that FirebirdProcessor.CreateSequenceForIdentity doesn't respect FBOptions.UndoEnabled. Since
            // Undo isn't implemented for Firebird, a migration runner always has to turn it off, but even with it off,
            // the migrations below will fail unless CreateSequenceForIdentity is appropriately altered
            var tempResources = WriteOutFirebirdEmbeddedLibrariesToCurrentWorkingDirectory();
            var tempFile      = Path.GetTempFileName();

            using (var deleter = new AutoDeleter(tempFile))
            {
                File.Delete(tempFile);
                deleter.Add(tempResources);
                var connectionString = GetConnectionStringToTempDatabaseAt(tempFile);

                var runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                {
                    Namespace = "FluentMigrator.Tests.Integration.Migrations"
                };


                try
                {
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        options.TruncateLongNames = false;
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichCreatesTwoRelatedTables());
                        processor.CommitTransaction();
                        FbConnection.ClearPool(connection);
                    }
                    //---------------Assert Precondition----------------
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                                  "Foreign key does not exist after first migration");
                    using (var connection = new FbConnection(connectionString))
                    {
                        FirebirdProcessor processor;
                        var announcer = new TextWriterAnnouncer(System.Console.Out);
                        announcer.ShowSql = true;
                        var options = FirebirdOptions.AutoCommitBehaviour();
                        processor = new FirebirdProcessor(connection, new FirebirdGenerator(options), announcer,
                                                          new ProcessorOptions(), new FirebirdDbFactory(), options);
                        processor.FBOptions.UndoEnabled = false;
                        var runner = new MigrationRunner(Assembly.GetExecutingAssembly(), runnerContext, processor);
                        runner.Up(new MigrationWhichAltersTableWithFK());
                        processor.CommitTransaction();
                    }
                    Assert.IsTrue(ForeignKeyExists(connectionString, MigrationWhichCreatesTwoRelatedTables.ForeignKeyName),
                                  "Foreign key does not exist after second migration");
                }
                catch (Exception ex)
                {
                    try { File.Copy(tempFile, "C:\\tmp\\fm_tests.fdb", true); }
                    catch { }
                    throw ex;
                }
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirebirdQuoter"/> class.
 /// </summary>
 /// <param name="options">The firebird specific options</param>
 /// <param name="quoterOptions">Options how SQL text is handled</param>
 public FirebirdQuoter(
     FirebirdOptions options,
     IOptions <QuoterOptions> quoterOptions)
     : this(options.ForceQuote, quoterOptions)
 {
 }
 public FirebirdGenerator(
     [NotNull] FirebirdOptions fbOptions,
     [NotNull] IOptions <GeneratorOptions> generatorOptions)
     : this(new FirebirdQuoter(fbOptions.ForceQuote, new OptionsWrapper <QuoterOptions>(new QuoterOptions())), fbOptions, generatorOptions)
 {
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Adds Firebird support
        /// </summary>
        /// <param name="builder">The builder to add the Firebird-specific services to</param>
        /// <param name="fbOptions">Firebird options</param>
        /// <returns>The migration runner builder</returns>
        public static IMigrationRunnerBuilder AddFirebird(this IMigrationRunnerBuilder builder, FirebirdOptions fbOptions)
        {
            builder.Services
            .AddScoped(
                sp =>
            {
                var processorOptions = sp.GetRequiredService <IOptions <ProcessorOptions> >();
                return(((FirebirdOptions)fbOptions.Clone()).ApplyProviderSwitches(processorOptions.Value.ProviderSwitches));
            })
            .AddScoped <FirebirdDbFactory>()
            .AddScoped <FirebirdProcessor>()
            .AddScoped <IMigrationProcessor>(sp => sp.GetRequiredService <FirebirdProcessor>())
            .AddScoped <FirebirdQuoter>()
            .AddScoped <FirebirdGenerator>()
            .AddScoped <IMigrationGenerator>(sp => sp.GetRequiredService <FirebirdGenerator>());

            return(builder);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Adds Firebird support
 /// </summary>
 /// <param name="builder">The builder to add the Firebird-specific services to</param>
 /// <returns>The migration runner builder</returns>
 public static IMigrationRunnerBuilder AddFirebird(this IMigrationRunnerBuilder builder)
 {
     return(builder.AddFirebird(FirebirdOptions.AutoCommitBehaviour()));
 }