0
votes

Is there a way to create a trigger using fluentmigrator / firebirdsql?

When I try this

Execute.Sql(@"CREATE TRIGGER TEST_BI FOR 'Test'
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
    IF (NEW.ID IS NULL) THEN
    NEW.ID = GEN_ID(GEN_TEST_ID,1)
END
");

nothing happens. I tried the firebird syntax using SET TERM ^; but I get an error then. I also tried calling the DDL statement from a script, with Execute.Script() but still nothing.

Any suggestions? Thanks!

1
Do you commit the transaction in which you create the trigger? - ain
SET TERM is not part of the Firebird syntax, it is a part of tools like ISQL. Also statements in a PSQL block need to end with a semi-colon (only inside the PSQL block!). - Mark Rotteveel
I use FluentMigrator.TransactionBehavior.Default when defining migration. - H Mihail
I removed the SET TERM statements from the script file and now I don't get any error, but still no changes in the database. In the same migration I create the table and the sequence also, those two are created correctly and also delete on migrate down. Maybe it has to do with something that @ain said, regarding some transaction? - H Mihail

1 Answers

0
votes

I don't know too much about Firebird but I'm guessing that you cannot create triggers within a transaction. Check out this wiki page about how to turn off transactions: https://github.com/schambers/fluentmigrator/wiki/Transaction-modes-for-the-migration-runner

You need to set an attribute on your migration like this:

[Migration(201304210958, TransactionBehavior.None)]