Exemplo n.º 1
0
        private void Init(FirebirdProcessor processor, IEnumerable<string> columnDefinitions)
        {
            Connection = (FbConnection)processor.Connection;
            Transaction = (FbTransaction)processor.Transaction;

            Create(columnDefinitions);
        }
Exemplo n.º 2
0
        private void Init(FirebirdProcessor processor, IEnumerable <string> columnDefinitions)
        {
            Connection  = (FbConnection)processor.Connection;
            Transaction = (FbTransaction)processor.Transaction;

            Create(columnDefinitions);
        }
Exemplo n.º 3
0
 public FirebirdTestTable(FirebirdProcessor processor, string schemaName, params string[] columnDefinitions)
 {
     this.processor = processor;
     string guid = Guid.NewGuid().ToString("N");
     Name = "Table" + guid.Substring(0, Math.Min(guid.Length, 16));
     Init(processor, columnDefinitions);
 }
Exemplo n.º 4
0
        public void Dispose_WasCommited_ShouldNotRollback()
        {
            var createTable = new CreateTableExpression {
                TableName = "silly"
            };

            createTable.Columns.Add(new Model.ColumnDefinition {
                Name = "one", Type = DbType.Int32
            });
            _processor.Process(createTable);

            // this will close the connection
            _processor.CommitTransaction();
            // and this will reopen it again causing Dispose->RollbackTransaction not to throw
            var tableExists = _processor.TableExists("", createTable.TableName);

            tableExists.ShouldBeTrue();

            // Now dispose (->RollbackTransaction)
            _processor.Dispose();

            _processor = MakeProcessor();

            // Check that the table still exists after dispose
            _processor.TableExists("", createTable.TableName).ShouldBeTrue();
        }
        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;
                }
            }
        }
Exemplo n.º 6
0
        public FirebirdTestTable(FirebirdProcessor processor, string schemaName, params string[] columnDefinitions)
        {
            this.processor = processor;
            string guid = Guid.NewGuid().ToString("N");

            Name = "Table" + guid.Substring(0, Math.Min(guid.Length, 16));
            Init(processor, columnDefinitions);
        }
        public void SetUp()
        {
            FbDatabase.CreateDatabase(IntegrationTestOptions.Firebird.ConnectionString);

            _connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString);
            _processor  = MakeProcessor();
            _connection.Open();
            _processor.BeginTransaction();
        }
Exemplo n.º 8
0
        public void SetUp()
        {
            FbDatabase.CreateDatabase(IntegrationTestOptions.Firebird.ConnectionString);

            _connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString);
            _processor = MakeProcessor();
            _connection.Open();
            _processor.BeginTransaction();
        }
 public FirebirdTestTable(string tableName, FirebirdProcessor processor, params string[] columnDefinitions)
 {
     _processor = processor;
     if (_processor.Connection.State != ConnectionState.Open)
     {
         _processor.Connection.Open();
     }
     Name = tableName;
     Init(columnDefinitions);
 }
Exemplo n.º 10
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();
        }
 public FirebirdTableSchema(string tableName, FirebirdProcessor processor)
 {
     TableName = tableName;
     Processor = processor;
     Definition = new TableDefinition()
     {
         Name = tableName,
         SchemaName = String.Empty
     };
     Load();
 }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
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);
        }
        public FirebirdTestTable(FirebirdProcessor processor, params string[] columnDefinitions)
        {
            _processor = processor;
            if (_processor.Connection.State != ConnectionState.Open)
            {
                _processor.Connection.Open();
            }
            string guid = Guid.NewGuid().ToString("N");

            Name = "Table" + guid.Substring(0, Math.Min(guid.Length, 16));
            Init(columnDefinitions);
        }
Exemplo n.º 15
0
 private ColumnInfo(DataRow drColumn, FirebirdProcessor processor)
 {
     Name = AdoHelper.GetStringValue(drColumn["field_name"]).Trim();
     TableName = AdoHelper.GetStringValue(drColumn["relation_name"]).Trim();
     DefaultValue = GetDefaultValue(drColumn["default_source"]);
     Position = AdoHelper.GetIntValue(drColumn["field_position"]) ?? 0;
     IsNullable = AdoHelper.GetIntValue(drColumn["null_flag"]) != 1;
     Precision = AdoHelper.GetIntValue(drColumn["field_precision"]);
     CharacterLength = AdoHelper.GetIntValue(drColumn["field_character_length"]);
     FieldType = AdoHelper.GetIntValue(drColumn["field_type"]);
     FieldSubType = AdoHelper.GetIntValue(drColumn["field_sub_type"]);
     FieldTypeName = AdoHelper.GetStringValue(drColumn["field_type_name"]).Trim();
 }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
 public void SetUp()
 {
     if (!IntegrationTestOptions.Firebird.IsEnabled)
     {
         Assert.Ignore();
     }
     _temporaryDatabase = new TemporaryDatabase(
         IntegrationTestOptions.Firebird,
         _prober);
     _connection = new FbConnection(_temporaryDatabase.ConnectionString);
     _processor  = MakeProcessor();
     _connection.Open();
     _processor.BeginTransaction();
 }
Exemplo n.º 18
0
		public void SetUp()
		{
            if (System.IO.File.Exists("fbtest.fdb"))
            {
                FbConnection.ClearAllPools();
                FbConnection.DropDatabase(IntegrationTestOptions.Firebird.ConnectionString);
            }

            FbConnection.CreateDatabase(IntegrationTestOptions.Firebird.ConnectionString);

			_connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString);
			_processor = MakeProcessor();
			_connection.Open();
			_processor.BeginTransaction();
		}
Exemplo n.º 19
0
        public void SetUp()
        {
            if (System.IO.File.Exists("fbtest.fdb"))
            {
                FbConnection.ClearAllPools();
                FbConnection.DropDatabase(IntegrationTestOptions.Firebird.ConnectionString);
            }

            FbConnection.CreateDatabase(IntegrationTestOptions.Firebird.ConnectionString);

            _connection = new FbConnection(IntegrationTestOptions.Firebird.ConnectionString);
            _processor  = MakeProcessor();
            _connection.Open();
            _processor.BeginTransaction();
        }
        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();
        }
Exemplo n.º 22
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();
            }
        }
        public void SetUp()
        {
            if (!IntegrationTestOptions.Firebird.IsEnabled)
            {
                Assert.Ignore();
            }

            _temporaryDatabase = new TemporaryDatabase(
                IntegrationTestOptions.Firebird,
                _prober);

            var serivces = ServiceCollectionExtensions.CreateServices()
                           .ConfigureRunner(builder => builder.AddFirebird())
                           .AddScoped <IConnectionStringReader>(
                _ => new PassThroughConnectionStringReader(_temporaryDatabase.ConnectionString));

            ServiceProvider = serivces.BuildServiceProvider();
            ServiceScope    = ServiceProvider.CreateScope();
            Processor       = ServiceScope.ServiceProvider.GetRequiredService <FirebirdProcessor>();
        }
Exemplo n.º 24
0
		public void Dispose_WasCommited_ShouldNotRollback()
		{
			var createTable = new CreateTableExpression { TableName = "silly" };
			createTable.Columns.Add(new Model.ColumnDefinition { Name = "one", Type = DbType.Int32 });
			_processor.Process(createTable);

			// this will close the connection
			_processor.CommitTransaction();
			// and this will reopen it again causing Dispose->RollbackTransaction not to throw
			var tableExists = _processor.TableExists("", createTable.TableName); 
			tableExists.ShouldBeTrue();

			// Now dispose (->RollbackTransaction)
			_processor.Dispose();

			_processor = MakeProcessor();

			// Check that the table still exists after dispose
			_processor.TableExists("", createTable.TableName).ShouldBeTrue();
		}
Exemplo n.º 25
0
 public static SequenceInfo Read(FirebirdProcessor processor, string sequenceName)
 {
     using (DataSet ds = processor.Read(query, AdoHelper.FormatValue(sequenceName)))
     {
         return new SequenceInfo(ds.Tables[0].Rows[0], processor);
     }
 }
Exemplo n.º 26
0
 public static List<TriggerInfo> Read(FirebirdProcessor processor, TableInfo table)
 {
     using (DataSet ds = processor.Read(query, AdoHelper.FormatValue(table.Name)))
     {
         List<TriggerInfo> rows = new List<TriggerInfo>();
         foreach (DataRow dr in ds.Tables[0].Rows)
             rows.Add(new TriggerInfo(dr, processor));
         return rows;
     }
 }
Exemplo n.º 27
0
 private TriggerInfo(DataRow drTrigger, FirebirdProcessor processor)
 {
     Name = drTrigger["rdb$trigger_name"].ToString().Trim();
     Sequence = AdoHelper.GetIntValue(drTrigger["rdb$trigger_sequence"]) ?? 0;
     Type = AdoHelper.GetIntValue(drTrigger["rdb$trigger_type"]) ?? 1;
     Body = drTrigger["rdb$trigger_source"].ToString().Trim();
 }
        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;

                }
            }
        }
 public FirebirdSchemaProvider(FirebirdProcessor processor)
 {
     Processor = processor;
 }
Exemplo n.º 30
0
 public FirebirdTestTable(string tableName, FirebirdProcessor processor, string schemaName, params string[] columnDefinitions)
 {
     this.processor = processor;
     Name = tableName;
     Init(processor, columnDefinitions);
 }
Exemplo n.º 31
0
 private IndexInfo(DataRow drIndex, FirebirdProcessor processor)
 {
     Name = drIndex["rdb$index_name"].ToString().Trim();
     TableName = drIndex["rdb$relation_name"].ToString().Trim();
     IsUnique = drIndex["rdb$unique_flag"].ToString().Trim() == "1";
     IsAscending = drIndex["rdb$index_type"].ToString().Trim() == "0";
     Columns = new List<string>();
     using (DataSet dsColumns = processor.Read(indexFieldQuery, AdoHelper.FormatValue(Name)))
     {
         foreach (DataRow indexColumn in dsColumns.Tables[0].Rows)
             Columns.Add(indexColumn["rdb$field_name"].ToString().Trim());
     }
 }
Exemplo n.º 32
0
        private ConstraintInfo(DataRow drConstraint, FirebirdProcessor processor)
        {
            Name = drConstraint["rdb$constraint_name"].ToString().Trim();
            IsPrimaryKey = drConstraint["rdb$constraint_type"].ToString().Trim() == "PRIMARY KEY";
            IsNotNull = drConstraint["rdb$constraint_type"].ToString().Trim() == "NOT NULL";
            IsForeignKey = drConstraint["rdb$constraint_type"].ToString().Trim() == "FOREIGN KEY";
            IsUnique = drConstraint["rdb$constraint_type"].ToString().Trim() == "UNIQUE";
            IndexName = drConstraint["rdb$index_name"].ToString().Trim();

            if (IsForeignKey)
            {
                using (DataSet dsForeign = processor.Read(colQuery, AdoHelper.FormatValue(Name)))
                {
                    DataRow drForeign = dsForeign.Tables[0].Rows[0];
                    ForeignIndex = IndexInfo.Read(processor, IndexName);
                    UpdateRule = GetForeignRule(drForeign["rdb$update_rule"]);
                    DeleteRule = GetForeignRule(drForeign["rdb$delete_rule"]);
                }
            }
        }
Exemplo n.º 33
0
 private void Init(FirebirdProcessor processor, IEnumerable <string> columnDefinitions)
 {
     Create(columnDefinitions);
 }
Exemplo n.º 34
0
 public FirebirdTestTable(string tableName, FirebirdProcessor processor, string schemaName, params string[] columnDefinitions)
 {
     this.processor = processor;
     Name           = tableName;
     Init(processor, columnDefinitions);
 }
        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;

                }
            }
        }
Exemplo n.º 36
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);
 }
Exemplo n.º 37
0
 private void Init(FirebirdProcessor processor, IEnumerable<string> columnDefinitions)
 {
     Create(columnDefinitions);
 }
Exemplo n.º 38
0
 public static IndexInfo Read(FirebirdProcessor processor, string indexName)
 {
     using (DataSet ds = processor.Read(singleQuery, AdoHelper.FormatValue(indexName)))
     {
         return new IndexInfo(ds.Tables[0].Rows[0], processor);
     }
 }
Exemplo n.º 39
0
 public static TableInfo Read(FirebirdProcessor processor, string tableName)
 {
     return new TableInfo(processor.Read(query, AdoHelper.FormatValue(tableName)).Tables[0].Rows[0], processor);
 }
Exemplo n.º 40
0
 private SequenceInfo(DataRow drSequence, FirebirdProcessor processor)
 {
     Name = drSequence["rdb$generator_name"].ToString().Trim();
     using (DataSet ds = processor.Read(queryValue, Name))
     {
         CurrentValue = AdoHelper.GetIntValue(ds.Tables[0].Rows[0]["gen_val"]) ?? 0;
     }
 }
Exemplo n.º 41
0
 public TableInfo(DataRow drMeta, FirebirdProcessor processor)
 {
     Name = drMeta["rdb$relation_name"].ToString().Trim();
 }
Exemplo n.º 42
0
 public static SequenceInfo Read(FirebirdProcessor processor, string sequenceName)
 {
     var fbSequenceName = new FirebirdQuoter().ToFbObjectName(sequenceName);
     using (DataSet ds = processor.Read(query, AdoHelper.FormatValue(fbSequenceName)))
     {
         return new SequenceInfo(ds.Tables[0].Rows[0], processor);
     }
 }
 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;
 }
Exemplo n.º 44
0
 public static TableInfo Read(FirebirdProcessor processor, string tableName)
 {
     var quoter = new FirebirdQuoter();
     var fbTableName = quoter.ToFbObjectName(tableName);
     return new TableInfo(processor.Read(query, AdoHelper.FormatValue(fbTableName)).Tables[0].Rows[0]);
 }
Exemplo n.º 45
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 FirebirdDbFactory(), options);

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

                connection.Close();
            }
        }
Exemplo n.º 46
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;
                }
            }
        }