flyway migration failing for update sql statement with join - spring-data-jpa

I created the update statement with joins in flywaydb with 8.x version. the update statement is below and the actual database is postgres 14.x. It is showing syntax error.
SQL Query :
update ss s set s_name = csc.name from c_s_category csc where csc.uid
= s.fk_csc_id and s.fk_csc_id is not null;
Can you please suggest, how can i proceed further with flyway script migration.

Related

How to create multiple databases with Postgres in pgAdmin4

I am trying to run the following query in pgAdmin:
CREATE DATABASE abc;
CREATE DATABASE xyz;
And I get the following error:
ERROR: current transaction is aborted, commands ignored until end of transaction block
SQL state: 25P02
I'm relatively new to postgres.
With SQL Server it's possible to create multiple databases in a single query with the "GO" statement in between if necessary.
I've tried to google this error, and most answers are to simply run each line separately.
That would work, but I'm curious why this doesn't work.
It may also be a setting in pgAdmin.
The "autocommit" is currently on. I've tried it off, and same result.
I'm using postgres 14.5 (in aws)

Reverse sql that undo a query

query:
UPDATE "table_name"
SET properties = properties || jsonb_build_object('$ip', ip)
WHERE ip IS NOT NULL;
I am running a Django migration, I need the reverse sql that undo the results of executing this query and restores the table in the previous state.
Because when I run the django migration test for the following operation:
operations = [
# migrations.RunPython(migrate_event_ip_to_property, rollback),
migrations.RunSQL(
"""
UPDATE "table_name"
SET properties = properties || jsonb_build_object('$ip', ip)
WHERE ip IS NOT NULL;
""",
None
)
]
I get IrreversibleError. I think if I provide the reverse sql, instead of None, it might work
I think you are out of luck looking for a raw solution from postgresql as SQL transaction was already commited by Django migration. See Postgresql ROLLBACK
But in this case you can revert to last working migration using:
./manage.py migrate app XXXX_last_working_migration
As stated in Django's django-admin docs migrate section here

Flyway doesn't mark statement in schema_version as fail in DB2

If some script fails during migration , flyway won't add record to schema_version in DB2 db for failed statement.
Do you have any idea how to avoid this situation?
I did a migration, 4th script failed, i expect this script will have status ABORTED/FAILED
One explanation for flyway behavior difference that you observe is the way Oracle handles DDL (implicit commit before/after each DDL) as compared with how Db2 handles DDL (implements DDL under transaction control by default). So with Db2 it's possible to arrange for each migration to be atomic and to rollback upon failure - meaning that there is nothing to repair, and therefore no repair action required as the flyway Oracle implementation may need.

Forcing a failed mvn flyway:migrate to skip failed schema migration, and try executing next schema

I was trying to run flyway:migrate on my projects postgres database. I have made the changes to a table manually and because of that the schema migration using flyway is failing, which is blocking next schema migration execution.
table : foo
required_change : ALTER TABLE foo ALTER COLUMN id DROP NOT NULL
current_schema_version : 2
next_schema_version : 3
Error:
[ERROR] com.googlecode.flyway.core.api.FlywayException: Migration of schema "public" to version 3 failed! Changes successfully rolled back.
How could I skip failing schema and make flyway:migrate execute next schema defined?
It might be simplest to undo the manual change so that Flyway can run successfully. For example, if you dropped the column then add it back in, then run the Flyway script to drop it.
So I found one possible solution to this problem, which goes as follows:
(1). In mysql database there is a table schema_version, which maintains the migration version number , it's status and other related information.
for ex.
mysql> desc schema_version;
version_rank
installed_rank
version
description
type
script
checksum
installed_by
installed_on
execution_time
success
for a failed migration the success field values stores 0, to override that and execute the next flyway:migration you can manually set the value to 1 (this would make sure, you don't lose the data stored on the table you created manually , when migration failed.
(2). Adding following on your pom.xml while running flyway:migration temporarily (while testing) also helps.
<validateOnMigrate>false</validateOnMigrate>

Make HSQLDB Compatibility with DB2

HSQL-2.3.2 is using as in-memory to test the application which is integrated DB2.
So I am setting sql.syntax_db2=true in url as below in order to provide DB2 compatibility
jdbc:hsqldb:file:{path};shutdown=true;sql.syntax_db2=true
when above url using "SET DATABASE SQL SYNTAX DB2 FALSE" statement created in generated script file,but when i am passing db2,ora syntax true as below
jdbc:hsqldb:file:{path};shutdown=true;sql.syntax_db2=true;sql.syntax_ora=true
then both statements SET DATABASE SQL SYNTAX DB2 TRUE and SET DATABASE SQL SYNTAX ORA TRUE are created and db2 syntax is not executing and below exception firing
nested exception is java.sql.SQLSyntaxErrorException: unexpected token: IGNORE
So please share where needs to make change in order to make DB2 compatibility?
Thanks,
Durgesh