Flyway + Oracle issues with baseline - flyway

I'm trying to get flyway to work with a Spring Boot application and Oracle.
So far I have been successful in getting flyway working on several databases (postgreSQL, mysql, SQLServer) but on Oracle I keep getting in a chicken and egg problem.
If I run my app for the very first time, I get an error: Found non-empty schema "SPRING" without metadata table! Use baseline() or set baselineOnMigrate to true to initialize the metadata table.
I'm connecting with a user spring to a specific namespace configured on Oracle. and I'd like to have the schema_version table on the same namespace
So if I try to set flyway.baseline-on-migrate=true it does create the migration table, but then, it does not create any of the tables, as it says there's already a version 1 installed on the schema identified by << Flyway Baseline >>
How can I get away from this chicken and egg issue? Seems to happen only with oracle, all other dbs, it worked straight on the first time.
So far I'm running it, the app fails, I then delete entries from the schema_version table and run it again.
Ideas?

You may need to specify the schema in Spring Boot e.g.:
flyway:
schemas: SPRING
Let's say, you have the following setup in Oracle XE:
CREATE TABLESPACE SPRING DATAFILE 'spring.dbf' SIZE 40M ONLINE;
CREATE USER SPRING IDENTIFIED BY SPRING DEFAULT TABLESPACE SPRING TEMPORARY TABLESPACE TEMP;
GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, UNLIMITED TABLESPACE TO SPRING;
You should now be able to populate the database using the following Boot properties:
spring:
datasource:
url: jdbc:oracle:thin:#localhost:1521:xe
username: SPRING
password: SPRING
flyway:
schemas: SPRING

Related

Query method not supported - Redis datasource, Spring boot starter data redis (2.6.3) and CRUD repository

I am using redis as my data store and i am using spring boot starter data redis as the dependency and a crud repository for CRUD operation. When i do deleteById it is working. But when i do deleteByName (Name is not an id column) it is saying query method not supported. When the data source is redis and if we use spring boot starter data redis, it is possible only to deleteById column and not by other columns?
I had the same problem that after a lot of searching and also checking the following link:
Redis 2.1.2.RELEASE doc reference
I realized that since Redis is based on Key and Valve, the following solution should be used:
List<SampleClass> lst = cacheTokenRepository.findAllBySampleFields(... sampleFields);
lst.forEach(item->
SampleRepository.deleteById(item.getId())
);
In this solution we search the list of records that match our conditions and delete them all based on id

validation failure when using mysql as dataSource in Corda

I am running mysql as docker (mysql:8.0.20). Gradle task deployNodes fails with error :
Could not create the DataSource: Validation Failed:
1 changes have validation failures
columnDataType is required for renameColumn on mysql, migration/node-info.changelog-v3.xml::column_host_name::R3.Corda.
Can somebody help me with this error?
As you can see columnDataType is a required attribute for MySql. Corda does not support MySql and hence this is not tested against MySql so you could get these kinds of MySql specific errors.
If you are using Corda enterprise, you could set the runMigration flag to false(which will not run the schema automatically on the db), use the database management tool to manually generate the schema, make changes (add columnDataType to the schema), and then run it manually onto mysql db.
Below image is taken from https://www.liquibase.org/documentation/changes/rename_column.html

Checkpoint table does not exist even after creating it

I have created checkpoint table ggate for replicat rep1 but still I am getting following error:
2014-09-04 23:38:21 ERROR OGG-00446 Oracle GoldenGate Delivery for
Oracle, REP1.prm: Checkpoint table ggate.checkpoint does not exist.
Please create the table or recreate the REP1 group using the correct
table.
2014-09-04 23:38:21 ERROR OGG-01668 Oracle GoldenGate Delivery for
Oracle, REP1.prm: PROCESS ABENDING.
Can anyone tell me how to resolve it?
In this kind of situations you should:
Have you actually run the ADD CHECKPOINTTABLE? if not run it
Check if the checkpoint table actually exists in the database - if it has been created - try to drop it (DROP CHECKPOINTTABLE) and recreate it (ADD CHECKPOINTTABLE)
Check if the checkpoint parameter is correctly set in the GLOBALS config file
Restart the MGR and Extract/Replicat processes
Verify if the user has access on the database to the checkpoint table (insert, update, delete rights)
If nothing works, run 10046 flag on the target database and check what the GoldenGate Replicat process is executing on the database and when it actually fails (what it wants to do on the database and try to do the same commands by yourself)
This is a simple troubleshooting initiative:
Are you using a traditional non-CDB database or a PDB?
Are you using Classic Architecture or Microservices Architecture? - Different approaches when adding a checkpoint table.
How are you running ADD CHECKPOINTTABLE? From GGSCI/AdminClient or from HTML5 page?
In Classic Architecture, do you have CHECKPOINTTABLE parameter set in GLOBALS? (CHECKPOINTTABLE [container.] owner.table)
Who are you logged into the database as when using DBLOGIN USERIDALIAS?
What replicat are you using? - Classic, Coordinated, Integrated, Parallel?
Check the schema where the table is suppose to be? If not there, you can query the DBA_TABLES view for the name of the checkpoint table and see who owns it.
A lot of times when the checkpint table cannot be created it is due to not updating the GLOBALS file and/or connecting as the correct user to the database.

How do I prevent flyway from creating the schema during init

I'm trying to start using flyway v2.3 on an existing Oracle 11g schema that does not contain the schema_history table
In my flyway.properties i've set the flyway.user to the schema owner and i've set the flyway.schemas property to the same value
When running init from the command line I expected flyway to only create the schema_history table but it fails with this message:
$ ./flyway.cmd init
Flyway (Command-line Tool) v.2.3
Creating schema "myschema" ...
ERROR: Unable to create schema "myschema"
ERROR: Caused by: java.sql.SQLSyntaxErrorException: ORA-01031: insufficient privileges
Why is flyway attempting to create the schema? I only want it to create the schema_history table in the schema I configured
The command is correct. Please note that flyway.schemas is case-sensitive and automatically filled with the default schema of the user if left empty.
I suspect the value you put in flyway.schemas is in the wrong case. Just leave it empty and you should be ok.
So you have to be sure you want to work on schema which belongs to user name with which you login. If you want to work in different schema you have to specify inside flyway.properties.
I've just had the same problem in Flyway Maven plugin 3.1.
I turned out that I have created my user with lowercase name
CREATE USER myuser ...
And I gave Flyway
flyway.user=myuser
But while connecting my user's name was cast to uppercase, so Flyway reported that user of name MYUSER did not exist.
Solution: Create and use Oracle DB user with uppercase name.

How to create a small and simple database using Oracle 11 g and SQL Developer?

How to create a small and simple database using Oracle 11 g and SQL Developer ?
I am seeing too many errors and I cannot find any way to make a simple database.
For example
create database company;
Caused the following error:
Error starting at line 1 in command:
create database company
Error at Command Line:1 Column:0
Error report:
SQL Error: ORA-01501: CREATE DATABASE failed
ORA-01100: database already mounted
01501. 00000 - "CREATE DATABASE failed"
*Cause: An error occurred during create database
*Action: See accompanying errors.
EDIT-
This is completely different from MySQL and MS-SQL that I am familiar with.
Not as intuitive as I was expecting.
First off, what Oracle calls a "database" is generally different than what most other database products call a "database". A "database" in MySQL or SQL Server is much closer to what Oracle calls a "schema" which is the set of objects owned by a particular user. In Oracle, you would generally only have one database per server (a large server might have a handful of databases on it) where each database has many different schemas. If you are using the express edition of Oracle, you are only allowed to have 1 database per server. If you are connected to Oracle via SQL Developer, that indicates that you already have the Oracle database created.
Assuming that you really want to create a schema, not a database (using Oracle terminology), you would create the user
CREATE USER company
IDENTIFIED BY <<password>>
DEFAULT TABLESPACE <<tablespace to use for objects by default>>
TEMPORARY TABLESPACE <<temporary tablespace to use>>
You would then assign the user whatever privileges you wanted
GRANT CREATE SESSION TO company;
GRANT CREATE TABLE TO company;
GRANT CREATE VIEW TO company;
...
Once that is done, you can connect to the (existing) database as COMPANY and create objects in the COMPANY schema.
Actually the answer from Justin above could not be more incorrect. SQL Server and MySQL are for smallish databases. Oracle is for large enterprise databases, thus the difference in it's structure. And it is common to have more than one Oracle database on a server provided that the server is robust enough to handle the load. If you received the error posted above then you obviously are trying to create a new Oracle database and if you are doing that then you probably already understand the structure of an Oracle database. The likely scenario is that you attempted to create a database using dbca, it initially failed, but the binaries were created. You then adjusted your initial parameters and re-tried creating the database using dbca. However, the utility sees the binaries and folder structure for the database that you are creating so it thinks that the database already exists but is not mounted. Dropping the database and removing the binaries and folders as well as any other cleanup of the initial attempt should be done first, then try again.
From your question description, I think you were to create a database schema, not a database instance. In Oracle terminology, a database instance is a set of files in the file system. It's more like data files in MySQL. Whereas database in MySQL is somewhat equivalent to Oracle's schema.
To create a schema in Oracle: https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_6014.htm
To create a database instance in Oracle (I personally prefer CDBA):
https://docs.oracle.com/cd/E11882_01/server.112/e25494/create.htm#ADMIN11068
Notice the Oracle Express edition does not support mounting more than one database instance at one time.

Resources