Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hibernate schema validation after migration #250

Open
TimothyL96 opened this issue Mar 25, 2022 · 0 comments
Open

Allow hibernate schema validation after migration #250

TimothyL96 opened this issue Mar 25, 2022 · 0 comments

Comments

@TimothyL96
Copy link

TimothyL96 commented Mar 25, 2022

dataSource:
  url: jdbc:mysql://...
  driverClassName: com.mysql.cj.jdbc.Driver
  username: 
  password: 

hibernate:
  hbm2ddl:
    auto: validate

With Micronaut Hibernate GORM, configuring hbm2ddl to validate will cause startup to fail if schema is invalid.


I think is useful if we can enable validation and liquibase will run the migration before the validation and not after.

I found a similar ticket but I guess this is not for GORM? [https://github.com//issues/1]


The current workaround will be to retrieve the Hibernate metadata from GORM and run the schema validator manually.
class ValidatorService
{
	@Inject
	HibernateDatastore hibernateDatastore
	
	void validate()
	{
                // retrieve existing metadata
                def metadata = hibernateDatastore.getMetadata()

                // throw exception on failed validation
		new SchemaValidator().validate(metadata)
	}
}

and then call the validate() on startup with something like a startup listener:

void onApplicationEvent(StartupEvent event)
{
    validator.validate()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant