liquibase change existing changelog from mysql to mssql - java

I have all my liquibase changelogs with respect to MySQL database now we are planning to move to MSSQL so when I try to run the existing changelogs which is working fine for MySQL is failing for MSSQL. Is there any configuration in liquibase to handle database migration?
getting below error when I run changelogs on MSSQL
addAfterColumn is not allowed on mssql

you can use dbms attribute and configure changelogs to be executed only on given databases.

Related

How to use flyway to manage schema in OceanBase

I try to use flyway to manage database schema in OceanBase, but failed.
The version I used
Flyway compile("org.flywaydb:flyway-core:5.2.1")
MySQL driver runtime 'mysql:mysql-connector-java:5.1.41'
Is there anyway to use database schema management in OceanBase?
I'm not sure if oceanbase supports flyway. If you are trying to perform migration, try using OMS(Oceanbase migration service) instead, or you are trying to manage the database itself, try using ODC(Oceanbase developer center). Both are GUI tools to manage oceanbase databases. You can find more details on official website of Oceanbase.

Cannot populate database with liquibase

I'm building a small spring-boot application. I'm using spring-data-jpa to create the database schema and liquibase to populate it with test data.
application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/book-db
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=admin
spring.datasource.password=lTIDDYz3n3jD3BeYaAJz
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
According to the documentation no configuration for liquibase is required if I have a gradle dependency and master changeLog under the default path.
db.changelog-master.yaml:
databaseChangeLog:
- changeSet:
id: 1
author: jb
changes:
- sqlFile:
path: db/migration/insert-books.sql
insert-books.sql:
--liquibase formatted sql
--changeset admin:1
delete from book;
insert into book (id, title)
values (nextval('seq'), 'Functional Programming for Mortals');
commit;
I have tried it with and without commit. The tables databasechangelog and databasechangelog are created successfully and contain the migration (insert-books).
The migration goes through, because if I add an invalid insert (to some table that does not exist), I get the exception:
ERROR: relation "xxx" does not exist
How to populate the database with data in insert-books.sql script using liquibase?
Don't use both, liquibase and JPA, to manage the DB structure. If you want to use liquibase, set JPA (Hibernate) to just validate the schema and manage the schema within liquibase.
spring.jpa.hibernate.ddl-auto=validate
The problem with your solution is in the order of operations. When your application starts, it first runs liquibase, which inserts the data, then JPA is started and the schema is created from scratch.
Try dropping the schema before running the app, I bet the migration (liquibase) will fail.
Liquibase has to be in charge of the schema, there is a way to add liquibase to an existing database, but it again makes liquibase the owner of the schema:
Using liquibase on the existing database

How to create table postgresql Heroku?

I have database postgresql in Heroku and i have local app. My entity is "Product".
When i wanna open my application in spring boot i get ERROR: relation "product" does not exist.
I dont have any idea how create new table "product" in postgresql.
In mysql everythink is good
You can with do it manually by running heroku pg:psql and then running the appropriate SQL statements. Or you can use a migration framework in your app.
For more information on running database migrations see the Heroku docs.

How to export data from Oracle to HSQL

I want to export data from a Oracle database to a HSQL database to use in a test environment (which doesn't have oracle).
What would be the way to proceed?
You can create an ETL package using SQL Server Integration Services.

running "virtual" database in Java code with Hibernate

I used to run my Java code with Hibernate to mysql.
Some logical changes led me to decide that I don't need to save the data in the database, but in java class that will handle it as a database (The data is delete in every startup of the application).
How can I do in Hibernate? is there a way to create an in memory database?
Consider H2 (recommended) or HSQLDB. You can certainly use Hibernate with them. In fact, HSQLDB was the database used by default in Hibernate for their test suite (I think they just changed to H2).
Take a look at Apache Derby.
You could also use SqlLite, which is an in-memory database. I'm just about to start using it with NHibernate for the same purpose in unit tests.
You just need to:
add the driver for the database you want to use and change the hibernate settings for this driver,
change the setting hibernate database dialect,
change the jdbc connection String
(add the jars for the database)
For example for Hypersonic H2 Database:
driverClassName = org.h2.Driver
dialect = org.hibernate.dialect.H2Dialect
connection string = jdbc:h2:mem:test

Categories

Resources