I having troubles to set up my new dev environment.
I was working with flyway for an simple web app. The process worked well since now. I have a new work environment and I've used pg_dump and pg_sql to restore the base like the qualification environment to get back with the good set of datas.
even thought my public.schema_version on my local environment is well backed up (with all the line regarding previous migrations) my server won't start and keep saying this :
2017-11-27 15:48:55.476 INFO 12857 --- [ main] o.f.c.i.dbsupport.DbSupportFactory : Database: jdbc:postgresql://localhost:5432/volt (PostgreSQL 9.4)
2017-11-27 15:48:55.572 INFO 12857 --- [ main] o.f.core.internal.command.DbValidate : Successfully validated 110 migrations (execution time 00:00.050s)
2017-11-27 15:48:55.584 INFO 12857 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema "public": << Empty Schema >>
2017-11-27 15:48:55.587 INFO 12857 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "public" to version 1.2 - Changing object type report
2017-11-27 15:48:55.595 ERROR 12857 --- [ main] o.f.core.internal.command.DbMigrate : Migration of schema "public" to version 1.2 - Changing object type report failed! Changes successfully rolled back.
Here 1.2 is the first screep that i've created.. And if I'm looking up to my local base I've all my flyway lines with the success column set to true (included the 1.2 one).
Does flyway keep the current version elsewhere than in the table "schema_version" ?
How do I tell flyway that my schema version is up to date regarding the migrations ?
PS : I'm using a spring-boot environment with only the flyway-core dependency in my pom.xml and this line in my spring-boot properties file
flyway:
baseline-on-migrate: true
I found out that i've used another user existing only in qualification to restore my base.. So my user in my development environment was not on the good schema of my base.
I've re-created my base with the proper user and everything was working again.
Related
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.
I have set jOOQ configuration with Liquibase database, all is working good. I want to execute gradle generateJooq task in silent mode, but there are some other logs got from liquibase for anyway for some reason, is there any property that I can set to prevent them?
jOOQ setup:
jooqConfiguration.apply {
logging = if (gradle.startParameter.logLevel == LogLevel.QUIET)
org.jooq.meta.jaxb.Logging.WARN
else
org.jooq.meta.jaxb.Logging.INFO
generator.apply {
database.apply {
name = "org.jooq.meta.extensions.liquibase.LiquibaseDatabase"
properties = listOf(
Property()
.withKey("scripts")
.withValue("/changelog/changelog-master.yaml")
)
...
}
...
}
...
}
Logs that I still got while running gradle clean build -q:
02:25:43 INFO Set default schema name to PUBLIC
02:25:43 INFO Successfully acquired change log lock
02:25:43 INFO Creating database history table with name: PUBLIC.DATABASECHANGELOG
02:25:43 INFO Reading from PUBLIC.DATABASECHANGELOG
Running Changeset: /changelog/changelog-generated.yaml::empty::tpd
02:25:43 INFO Empty change did nothing
02:25:43 INFO ChangeSet /changelog/changelog-generated.yaml::empty::tpd ran successfully in 0ms
02:25:43 INFO Successfully released change log lock
I am trying to run my spring-boot/liquibase/H2 database with a non-admin user and am having some problems understanding how to do this.
First off, I have seen some information here and tried to set up my application.yml this way.
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:test
username: USERLIMITED
password: user_limited_password
liquibase:
contexts: dev, faker
user: THELIQUIBASEUSER
password: THELIQUIBASEPASSWORD
Also put these sql statements in the changelog to run so that the user I want is created and given proper access controls:
<sql>DROP USER IF EXISTS USERLIMITED</sql>
<sql>CREATE USER USERLIMITED PASSWORD 'user_limited_password'</sql>
<sql>GRANT ALL ON APP TO USERLIMITED</sql>
When trying to start up the app, I get the following error:
2020-10-21 14:41:18.532 DEBUG 8704 --- [ restartedMain] c.c.config.LiquibaseConfiguration : Configuring Liquibase
2020-10-21 14:41:18.617 WARN 8704 --- [ test-task-1] i.g.j.c.liquibase.AsyncSpringLiquibase : Starting Liquibase asynchronously, your database might not be
ready at startup!
2020-10-21 14:41:20.226 ERROR 8704 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : Hikari - Exception during pool initialization.
org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password [28000-200]
What is interesting is if I change the LiquibaseConfiguration file to use synchronous DB configuration vs. the async by default I do not get an error.
// If you don't want Liquibase to start asynchronously, substitute by this:
SpringLiquibase liquibase = SpringLiquibaseUtil.createSpringLiquibase(liquibaseDataSource.getIfAvailable(), liquibaseProperties, dataSource.getIfUnique(), dataSourceProperties);
// SpringLiquibase liquibase = SpringLiquibaseUtil.createAsyncSpringLiquibase(this.env, executor, liquibaseDataSource.getIfAvailable(), liquibaseProperties, dataSource.getIfUnique(), dataSourceProperties);
Then if I go to the H2 console and perform a query to see my users I only have the one admin user (which should be a non-admin).
Trying to log in as the liquibase user that I set up in the yml
user: THELIQUIBASEUSER
password: THELIQUIBASEPASSWORD
is not there and I get the Wrong user name or password [28000-200] error.
This leads me to believe that it is something with how the application starts up and asynchronous task execution priority.
Any help is very much appreciated!
I have h2 and flyway enabled in my Spring Boot 2 project.
I have properties as follows:
spring.datasource.url: jdbc:h2:mem:mydatabasename
spring.datasource.driverClassName: org.h2.Driver
spring.datasource.username: sa
spring.datasource.password:
spring.jpa.database-platform: org.hibernate.dialect.H2Dialect
spring.h2.console.enabled: true
spring.h2.console.path: /h2
spring.flyway.url: ${spring.datasource.url}
spring.flyway.schemas : mydatabasename
spring.flyway.user: ${spring.datasource.username}
spring.flyway.password : ${spring.datasource.password}
db.migration file is usual (resources/db/migration/V1__Initial_version.sql)
CREATE TABLE PRODUCT
(
ID VARCHAR(200) PRIMARY KEY,
PRODUCTID VARCHAR(30)
);
and it works:
o.f.c.internal.license.VersionPrinter : Flyway Community Edition 5.2.4 by Boxfuse
o.f.c.internal.database.DatabaseFactory : Database: jdbc:h2:mem:mydatabasename (H2 1.4)
o.f.c.internal.database.base.Database : Flyway upgrade recommended: H2 1.4.199 is newer than this version of Flyway and support has not been tested.
o.f.core.internal.command.DbSchemas : Creating schema "mydatabasename" ...
o.f.c.i.s.JdbcTableSchemaHistory : Creating Schema History table: "mydatabasename"."flyway_schema_history"
o.f.core.internal.command.DbMigrate : Current version of schema "mydatabasename": null
o.f.core.internal.command.DbMigrate : Migrating schema "mydatabasename" to version 1 - Initial version
o.f.core.internal.command.DbMigrate : Successfully applied 1 migration to schema "mydatabasename" (execution time 00:00.021s)
However when I log in to the H2 console (I use exactly the same url,jdbc:h2:mem:mydatabasename) I do log in, but I do not see anything, only INFORMATION_SCHEMA. Additionally, 'show schemas' show INFORMATION_SCHEMA and
PUBLIC, and PUBLIC not present in the left-hand column also.
I found the fix myself:
making this instruction
spring.datasource.url: "jdbc:h2:mem:mydatabasename;DB_CLOSE_DELAY=-1;"
made the newly created schema and table to appear.
Additionally, if I remove
spring.flyway.schemas : mydatabasename // remove
then the tables created at "root" level when viewing from the console.
I'm using Spring-boot and configured database in application.properties file like below
spring.datasource.primary.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.primary.username=postgres
spring.datasource.primary.password=pass
spring.datasource.primary.driver-class-name=org.postgresql.Driver
spring.datasource.primary.maxActive=10
spring.datasource.primary.testWhileIdle = true
spring.datasource.primary.validationQuery = SELECT 1
spring.jpa.properties.hibernate.default-schema=public
spring.jpa.hibernate.ddl-auto:update
It works perfect in windows, but when I run it in Mac it shows some errors and does not create table
[ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000388: Unsuccessful:
create table sample_table (table_id serial not null, name varchar(255))
2017-07-07 10:52:51.145 ERROR 1446 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate :
ERROR: permission denied to create "pg_catalog.sample_table"
Detail: System catalog modifications are currently disallowed.
I tried below things to resolve the issue
By changing default schema in properties to something else.
By changing ddl-auto to create, create-drop and none.
but have no success.
I don't know why it is trying to create table in pg_catalog schema?
I've solved it by changing below line from application.properties file
spring.jpa.properties.hibernate.default-schema=public
to
spring.jpa.properties.hibernate.default_schema=public
and it worked.