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

Implement multi-schema support #727

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

philipp-kleber-avelios
Copy link

These changes are an initial experiment to resolve issue #248, by allowing multiple schemas during the snapshot.
I added a new test HibernateMultiSchemaTest.java, which currently only checks the exit code of such a multi-schema diffChangelog command.

If somebody could review the code and maybe give their input if the changes are sufficient or if additional ones are required, that would be great, thanks!.

Copy link
Contributor

@MalloD12 MalloD12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Besides the minor comment I posted this looks good to me. Thank you, @philipp-kleber-avelios for contributing with this PR.

Daniel.

Copy link
Collaborator

@filipelautert filipelautert Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philipp-kleber-avelios Why getConnectionCatalogName() and getConnectionSchemaName() are being locked here to constants?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For getConnectionCatalogName(), the behavior is the same as before just without one less indirection (it used to call getDefaultCatalogName() internally).

For getConnectionSchemaName(), the behavior is slightly different from before:
It used to call getDefaultSchemaName() internally, but we can't do this anymore: The new getDefaultSchemaName() implementation calls super.getDefaultSchemaName() and this then calls getConnectionSchemaName(), so we'd have a call-cycle.

@@ -34,6 +34,12 @@ protected void addTo(DatabaseObject foundObject, DatabaseSnapshot snapshot) thro
Schema schema = (Schema) foundObject;
HibernateDatabase database = (HibernateDatabase) snapshot.getDatabase();
for (org.hibernate.boot.model.relational.Namespace namespace : database.getMetadata().getDatabase().getNamespaces()) {
boolean namespaceMatchesSchema = (namespace.getName().getSchema() != null && namespace.getName().getSchema().matches(foundObject.getName()))
Copy link
Collaborator

@filipelautert filipelautert Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is duplicated in SequenceSnapshotGenerator and TableSnapshotGenerator. Could you extract it to a generic method in HibernateSnapshotGenerator , or even move the check there so it's not repeated? As I believe it would be necessary to IndexSnapshotGenerator and other SnapshotGenerators too.. or am I overreacting?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can extract the check. I don't think we need to move the check though, since from my understanding, DatabaseObjects other than Schema, Table and Sequence are added only from those three corresponding snapshot-generators.
So I think if we have the check in those three generators, we don't need the check in the other ones, since the database objects that get to them always already have the correct schema.
I might be wrong though, I don't fully understand the snapshotting mechanism.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Code Review
Development

Successfully merging this pull request may close these issues.

3 participants