CREATE OR REPLACE ALERT fails with "Incomplete statement" - ALERT keyword potentially missing in SnowflakeParser.java
Flyway Version: Flyway OSS Edition 11.8.2
Database Name and Version: Snowflake - Version 9.13
OS: Running Flyway via Docker image in a GitLab CI pipeline.
Description of the Bug: Flyway's parser (version 11.8.2 OSS) fails to correctly parse even an extremely simplified CREATE OR REPLACE ALERT DDL statement for Snowflake. This results in an "Incomplete statement" error. The SQL syntax is valid for Snowflake and executes correctly when run directly against a Snowflake instance (e.g., via Snowsight/SnowSQL).
The issue was also present in older Flyway versions (e.g., 10.17.0) and critically, persists in the recent 11.8.2 OSS release with a minimal test case. Other DDL statements in the same migration script (e.g., CREATE TABLE, CREATE PROCEDURE, CREATE TASK) are parsed and executed correctly.
Steps to Reproduce: Include the following minimal SQL snippet in a Flyway migration file for Snowflake (e.g., R__minimal_alert_test.sql):
SQL
-- Minimal reproducible SQL for CREATE OR REPLACE ALERT
CREATE OR REPLACE ALERT MY_DB.MY_SCHEMA.MINIMAL_TEST_ALERT -- Replace MY_DB.MY_SCHEMA with valid identifiers
WAREHOUSE = MY_WAREHOUSE -- Replace MY_WAREHOUSE with a valid warehouse name
SCHEDULE = '1 minute'
IF( EXISTS(SELECT 1 ))
THEN
SELECT 1; -- Simplest possible valid action for testingActual Behavior: Flyway fails during the parsing phase of the migration with the following error (or very similar):
ERROR: Unexpected error
org.flywaydb.core.api.FlywayException: Unable to parse statement in ./R__01__migration_test.sql at line 1 col 1. See https://rd.gt/3ipi7Pm for more information. Incomplete statement at line 1 col 1:
CREATE OR REPLACE ALERT MY_DB.MY_SCHEMA.MINIMAL_TEST_ALERT
WAREHOUSE = MY_WAREHOUSE
SCHEDULE = '1 minute'
IF( EXISTS(SELECT 1 ))
THEN
SELECT 1;
at org.flywaydb.core.internal.parser.Parser.getNextStatement(Parser.java:299)
at org.flywaydb.core.internal.parser.Parser$ParserSqlStatementIterator.next(Parser.java:727)
at org.flywaydb.core.internal.parser.Parser$ParserSqlStatementIterator.next(Parser.java:692)
at org.flywaydb.core.internal.sqlscript.ParserSqlScript.parse(ParserSqlScript.java:75)
at org.flywaydb.core.internal.sqlscript.ParserSqlScript.validate(ParserSqlScript.java:116)
at org.flywaydb.core.internal.sqlscript.ParserSqlScript.executeInTransaction(ParserSqlScript.java:181)
at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.canExecuteInTransaction(SqlMigrationExecutor.java:80)
at org.flywaydb.core.internal.command.DbMigrate.isExecuteGroupInTransaction(DbMigrate.java:315)
at org.flywaydb.core.internal.command.DbMigrate.applyMigrations(DbMigrate.java:278)
at org.flywaydb.core.internal.command.DbMigrate.migrateGroup(DbMigrate.java:255)
at org.flywaydb.core.internal.command.DbMigrate.lambda$migrateAll$0(DbMigrate.java:153)
at org.flywaydb.core.internal.jdbc.TableLockingExecutionTemplate$1.call(TableLockingExecutionTemplate.java:40)
at org.flywaydb.core.internal.jdbc.TransactionalExecutionTemplate.execute(TransactionalExecutionTemplate.java:59)
at org.flywaydb.core.internal.jdbc.TableLockingExecutionTemplate.execute(TableLockingExecutionTemplate.35)
at org.flywaydb.core.internal.database.base.Connection.lock(Connection.java:106)(The error points to the beginning of the CREATE OR REPLACE ALERT statement).
Expected Behavior: Flyway should correctly parse the CREATE OR REPLACE ALERT statement and apply the migration successfully to the Snowflake database.
Hypothesis & Potential Root Cause: Upon investigating, it appears the ALERT keyword might be missing from the KEYWORDS set within Flyway's SnowflakeParser.java. For example, in SnowflakeParser.java, the KEYWORDS list does not seem to include ALERT.
Source: flyway/flyway