flyway upgrade from 4.X to 5.x runs the already ran migration scripts again - spring-boot

I was upgrading springboot 2 from 1.5. For that, I upgraded the flyway from 4.X to 5.24. When I run the springboot application after that, it's executing scripts which were already executed. Below is the logs I am seeing. removing project specific names as I am not allowed to post it:
myproject INFO 2019-03-11T16:08:11-0400 main [org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory] Creating Schema History table: "PUBLIC"."flyway_schema_history"
myproject INFO 2019-03-11T16:08:11-0400 main [org.flywaydb.core.internal.command.DbMigrate] Current version of schema "PUBLIC": << Empty Schema >>
myproject INFO 2019-03-11T16:08:11-0400 main [org.flywaydb.core.internal.command.DbMigrate] Migrating schema "PUBLIC" to version 1 - CREATE mything
myproject ERROR 2019-03-11T16:08:11-0400 main [org.flywaydb.core.internal.command.DbMigrate] Migration of schema "PUBLIC" to version 1 - CREATE mything failed! Please restore backups and roll back database and code!
myproject WARN 2019-03-11T16:08:11-0400 main [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException:
Migration V1__CREATE_mything.sql failed
---------------------------------------
SQL State : 42509
Error Code : -5509
Message : type not found or user lacks privilege: SERIAL

I guess You are using default value for parameter table.name, which changed in v. 5.0.0.
Refer to https://flywaydb.org/documentation/releaseNotes
Issue 1848 The default for flyway.table has been changed from schema_version to flyway_schema_history

Related

Liquibase in a Spring Application doesn't fail on unknown change type

We’ve recently ran into an issue where we had a typo in a Liquibase change type and nothing caught this issue. We used the addNonNullConstraint change type, which does not exist, instead of addNotNullConstraint.
The issue here is that we're using YAML format for the changeset file, which doesn't have any validation. With the XML format, we would at least get an error in the editor.
Executing the Liquibase CLI validate command finds the faulty change set:
➜ git: ✗ liquibase validate
Starting Liquibase at 13:46:47 (version 4.17.0 #4922 built at 2022-10-05 14:56+0000)
Liquibase Version: 4.17.0
Liquibase Community 4.17.0 by Liquibase
Unexpected error running Liquibase: Error parsing db/changelog.yaml
- Caused by: Error parsing /db/changes/0019_mark-column-non-null.yaml
- Caused by: Error parsing /db/changes/0019_mark-column-non-null.yaml: Unknown change type 'addNonNullConstraint'. Check for spelling or capitalization errors and missing extensions such as liquibase-commercial.
For more information, please use the --log-level flag
But when starting up the Spring Boot app, there’s no hint that something went wrong with one of the new changesets that need to be applied:
INFO Liquibase.database : Set default schema name to public
INFO liquibase.lockservice : Successfully acquired change log lock
INFO liquibase.changelog : Reading from public.databasechangelog
Running Changeset: /db/changes/0019_mark-column-non-null.yaml::Mark column as non-null::Dev
INFO liquibase.changelog : ChangeSet /db/changes/0019_mark-column-non-null.yaml::Mark column as non-null::Dev ran successfully in 0ms
Ideally, the Spring Boot app would validate the change sets before applying them, and fail if the change type is unknown. But I could not find out how to run the Liquibase validate command in the context of the Spring integration.

H2 and flyway crush on tests after upgrade from gradle 4 to 6

I am in the process of upgrading from gradle 4 to 6.
This forced me to upgrade many stuff like spring, h2, mySql connector, etc..
Now I have this problem:
on runtime, using MySQL all works fine.
but on tests, I get:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in com.bluerbn.wallet.infra.SpringTestConfiguration: Invocation of init method failed; nested exception is org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException:
Migration V9__fixIndex.sql failed
------------------------------------------------
SQL State : 42S22
Error Code : 42122
Message : Column "INDEX" not found; SQL statement:
ALTER TABLE table1 DROP INDEX ACC_INDEX [42122-200]
Location : db/migration/V9__fixIndex.sql (/Users/.../resources/db/migration/V9__fixIndex.sql)
Line : 1
Statement : ALTER TABLE table1 DROP INDEX ACC_INDEX
This is an old script that was working fine before the upgrade.
versions:
spring boot: 2.3.0
org.flywaydb:flyway-core:6.4.1 (though in gradle I put 6.4.2)
com.h2database:h2:1.4.200
mysql:mysql-connector-java:8.0.18
Any ideas?
H2 since the version 1.4.200 allows MySQL-style ALTER TABLE tableName DROP INDEX indexName only in MySQL compatibility mode. In 1.4.199 and older versions this invalid (for H2) command was incorrectly accepted in all modes.
You need to append ;MODE=MySQL to JDBC URL for H2.

How do I find out which schema script spring-boot is running?

I have an application based on spring-boot 1.4 with spring-jdbc.
I've added Flyway, which works in the application itself, but I get errors for my JdbcDAO test cases.
Question: I know spring-boot overrides 'dataSource' to embedded HSQLDB datasource, but I have no idea where it finds the SQL scripts to populate the empty database when I run tests.
Documentation says that it looks for 'schema.sql' or 'data.sql' in classpath, but I've renamed all of the script files in both main and test resource paths, but I still get this error:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed;
nested exception is org.flywaydb.core.api.FlywayException: Found non-empty schema(s) "PUBLIC" without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
This error leads me to believe that Spring-boot had created a schema definition BEFORE Flyway scripts were applied.
UPDATE: I'm getting a different error now, this is a Bad SQL error:
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [INSERT INTO BLUECOST_SSCDATA (SSCDATAID,PROCESSGROUPID,COSTINGAMOUNT,CHRG_TYP_CD,CONTROL_GROUP_CD,ACCOUNT_ID,CHRGHS_END_DT,ORIG_LOC_CD,SERVICE_TYP_CD,SERVICE_CD,SERVICE_GROUP_ID,SERVICE_ENV_CD,SERVICE_ADDER_CD,SERVICE_RESTYP_CD,RATECLAS_CD,PRICELST_UP_AMT,CHRGHS_USAGE_QTY,EMP_FA_CD,EMP_DIV_CD,EMP_DPT_CD,EMP_COUNTRY_CD,EMP_COMPANY_CD,EMP_NUM,EMP_INITS,EMP_LASTNAME,USER_ID,ADJUSTMENT_ID,CUST_REFERENCE_ID,ORIG_DIV_CD,ORIG_DPT_ID,ORIG_COUNTRY_CD,ORIG_COMPANY_CD,LOCAL_FIELD_1,LOCAL_FIELD_2,LOCAL_FIELD_3,LOCAL_FIELD_4,LOCAL_FIELD_5,LOCAL_FIELD_6,CREATETIME,PROCESSTIME,LAST_ALTER_TMS,TRX_TYP_CD,FILENAME) VALUES (100,null,368.60,'CTA','EMEA ','D286148 ','2018-03-19','SLR','SLR','SLIC','BASE',null,null,null,'OGS',null,null,null,null,null,null,null,null,null,'IBM SLIC BV',null,null,null,null,null,'653','SOFTLAYR','INVCE ID','X91927','ACCNT ID','FILENAME1.XLS',null,null,{ts '2018-04-22 01:30:21.437000'},null,{ts '2018-03-22 01:32:21.437000'},'I','FILENAME1.XLS')]; nested exception is java.sql.SQLSyntaxErrorException: requires either DEFAULT keyword or OVERRIDING clause
at com.ibm.cio.cloud.cost.spreadsheet.dao.UTJdbcBluecostSSCDataDAOTest.testDeleteBluecostSSCDataByLocalField2AndLocalField4(UTJdbcBluecostSSCDataDAOTest.java:265)
Caused by: java.sql.SQLSyntaxErrorException: requires either DEFAULT keyword or OVERRIDING clause
at com.ibm.cio.cloud.cost.spreadsheet.dao.UTJdbcBluecostSSCDataDAOTest.testDeleteBluecostSSCDataByLocalField2AndLocalField4(UTJdbcBluecostSSCDataDAOTest.java:265)
Caused by: org.hsqldb.HsqlException: requires either DEFAULT keyword or OVERRIDING clause
at com.ibm.cio.cloud.cost.spreadsheet.dao.UTJdbcBluecostSSCDataDAOTest.testDeleteBluecostSSCDataByLocalField2AndLocalField4(UTJdbcBluecostSSCDataDAOTest.java:265)
This gives me a clue: looks like my latest Flyway script is not applied to the schema when running the 'mvn test' goal.
How do I turn on the debugging to see what is happening with Flyway when running mvn test goal?
Fixed - retracting this question now.
<logger name="org.flywaydb" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>

Exception occurs at the end of test cases

I'm using Maven for dependency management. When I run the test cases an exception occurs at the end of test cases though test cases pass successfully.
Following is my stack trace:
2013-10-08 16:04:22,839 [Thread-15] ERROR plugins.DefaultGrailsPlugin - Error configuration scaffolding: Error creating bean with name 'instanceControllersApi': Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
Message: Error creating bean with name 'instanceControllersApi': Singleton bean creation not allowed while the singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
Line | Method
->> 662 | run in java.lang.Thread
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I'm using Grails 2.1.3. I have tried both, "static" and "dynamic" scaffolding but it did not resolve the issue.
I also referred to What does this exception mean? issue but no luck.
One user with a similar error fixed it by deleting the project folder in his ~/.grails directory.
http://grails.1312388.n4.nabble.com/Database-migration-plugin-Running-dbm-gorm-diff-results-Error-creating-bean-with-name-instanceContro-td4637567.html
A good ol' grails clean might help too, and be less invasive.
Also, if you can share the project through source control (git, mercurial, svn), you might try reproducing the issue on another machine. If you can't, that's a good sign that the issue is peculiar to your environment, and could be resolved through some sort of cleanup.
I have resolved my issue. I am not sure why it was occurring but i had many controller where scaffold=true. I generated the all controller and view and it resolved my issue.

How to install the admin panel in 1.0

I'm trying to install it but with no success.
Steps:
1. copied admin.jsp to /red5/webapps/root
2. Pasted all the jars from adminplugin-1.0.zip to /red5/plugins
3. started the server. ERROR:
[INFO] [main] org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1fa490e: defining beans [global.clientRegistry,global.serviceInvoker,global.mappingStrategy,global.context,global.handler,global.scope,red5.scopeResolver]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#be49e0
[WARN] [main] org.red5.server.ContextLoader - Context destroy failed for: default.context
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'default.context' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
So what's the procedure, i can't find it. I've been trying for the whole month to accomplish this!
You should check if the adminpanel does work with the red5 version you are using. Where did you download adminpanel from? I guess you might contact the mailing list to find the author of the adminpanel.
You can see the last commits / changes of the admin application have been done in 2008:
https://code.google.com/p/red5/source/browse/#svn%2Fflash%2Ftrunk%2Fadmin
I don't think that it is actively maintained at the moment, so it is actually your job to get it running and debug it if you need it.

Resources