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

Split multi-tenancy quickstart into two projects #1493

Open
wants to merge 8 commits into
base: development
Choose a base branch
from

Conversation

tobHai
Copy link

@tobHai tobHai commented Jan 19, 2025

Fixes quarkusio/quarkus#41759

Check list:

Your pull request:

  • targets the development branch
  • uses the 999-SNAPSHOT version of Quarkus
  • has tests (mvn clean test)
  • works in native (mvn clean package -Pnative)
  • has integration/native tests (mvn clean verify -Pnative)
  • makes sure the associated guide must not be updated
  • links the guide update pull request (if needed)
  • updates or creates the README.md file (with build and run instructions)
  • for new quickstart, is located in the directory component-quickstart
  • for new quickstart, is added to the root pom.xml and README.md

I split the existing quickstart into two:

  • schema approach
  • database approach

Additionally, I used dev services for the database connections.
The only real code change I did was fixing a warning in: d939238 (#1493)

I am not sure to which guide the checklist is referring to - do I need to update another project as well?

@yrodiere
Copy link
Member

I am not sure to which guide the checklist is referring to - do I need to update another project as well?

It refers to the Quarkus guide. The documentation.
In this case this file: https://github.com/quarkusio/quarkus/blob/main/docs/src/main/asciidoc/hibernate-orm.adoc
In particular you'll see reference to quickstarts for multitenancy here: https://github.com/quarkusio/quarkus/blob/cc10bd920755824b94437e88ac01da8651eb7ea0/docs/src/main/asciidoc/hibernate-orm.adoc?plain=1#L1085

So you'd need to:

  1. Remove that reference (it's now invalid)
  2. Introduce references to your newly introduced quickstarts in the relevant subsections
  3. Make sure any code examples mentioned in these subsections is consistent with your newly introduced quickstarts

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

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

Thanks, that's a nice cleanup. I added a few comments below.

Before merging, I think we'll need:

  1. Comments to be addressed/dismissed.
  2. A PR to be sent to the main Quarkus repo to make sure the documentation (hibernate-orm.adoc) is updated consistently.
  3. Ideally, all commits in this PR to be squashed into at most two: the splitting, and the addition of @PersistenceUnitExtension on tenant resolvers. EDIT: Okay maybe three if you want to keep the devservice thing separate, but that seems like it could be annoying to do properly, so I'd just squash that together in the same commit as the splitting.

I created a follow-up issue (quarkusio/quarkus#45715), but it's out of scope: just a few pre-existing problems that your PR reminded me of (thanks!).

Comment on lines +34 to +46
### DATABASE Multitenancy

Approach that uses a separate database (datasource 'base' and 'mycompany') for storing the tenant's data.

#### Start Quarkus in development mode

The Maven Quarkus plugin provides a development mode that supports live coding. To try this out:

> ./mvnw quarkus:dev

In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.

#### Run Quarkus as native executable
Copy link
Member

Choose a reason for hiding this comment

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

You can probably remove the section header since the whole project is about database multitenancy.

Suggested change
### DATABASE Multitenancy
Approach that uses a separate database (datasource 'base' and 'mycompany') for storing the tenant's data.
#### Start Quarkus in development mode
The Maven Quarkus plugin provides a development mode that supports live coding. To try this out:
> ./mvnw quarkus:dev
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.
#### Run Quarkus as native executable
### Start Quarkus in development mode
The Maven Quarkus plugin provides a development mode that supports live coding. To try this out:
> ./mvnw quarkus:dev
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.
### Run Quarkus as native executable

Comment on lines +156 to +200
<profile>
<id>eclipse</id>
<activation>
<property>
<!-- This is a trick to have the profile automatically activated by Eclipse -->
<name>m2e.version</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>io.fabric8</groupId>
<artifactId>
docker-maven-plugin
</artifactId>
<versionRange>
[0.28.0,)
</versionRange>
<goals>
<goal>start</goal>
<goal>stop</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed, since you removed docker-maven-plugin.

Suggested change
<profile>
<id>eclipse</id>
<activation>
<property>
<!-- This is a trick to have the profile automatically activated by Eclipse -->
<name>m2e.version</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>io.fabric8</groupId>
<artifactId>
docker-maven-plugin
</artifactId>
<versionRange>
[0.28.0,)
</versionRange>
<goals>
<goal>start</goal>
<goal>stop</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>

Comment on lines +5 to +7
When serving multiple customers from a same application (e.g.: SaaS), each customer is a tenant with a separate database or a separate schema in the same database.

For the schema per tenant approach see [Schema Quickstart](../hibernate-orm-multi-tenancy-schema-quickstart/README.md).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
When serving multiple customers from a same application (e.g.: SaaS), each customer is a tenant with a separate database or a separate schema in the same database.
For the schema per tenant approach see [Schema Quickstart](../hibernate-orm-multi-tenancy-schema-quickstart/README.md).
When serving multiple customers from a same application (e.g.: SaaS), each customer is a tenant with a separate database.
For the schema per tenant approach see [Schema Quickstart](../hibernate-orm-multi-tenancy-schema-quickstart/README.md).

Comment on lines +33 to +56
### SCHEMA Multitenancy

Approach that uses a single database (default datasource) with two schemas ('base' and 'mycompany') for storing the tenant's data.

#### Start Quarkus in development mode (Profile 'development')

The Maven Quarkus plugin provides a development mode that supports live coding. To try this out:

> ./mvnw quarkus:dev
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.

#### Run Quarkus as native executable

You can also create a native executable from this application without making any source code changes. A native executable removes the dependency on the JVM:
everything needed to run the application on the target platform is included in the executable, allowing the application to run with minimal resource overhead.

Compiling a native executable takes a bit longer, as GraalVM performs additional steps to remove unnecessary codepaths. Use the `native` profile to compile a
native executable:

> ./mvnw package -Pnative

After getting a cup of coffee, you'll be able to run this executable directly:

> ./target/hibernate-orm-schema-multi-tenancy-quickstart-1.0.0-SNAPSHOT-runner
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, the heading probably isn't necessary anymore.

Suggested change
### SCHEMA Multitenancy
Approach that uses a single database (default datasource) with two schemas ('base' and 'mycompany') for storing the tenant's data.
#### Start Quarkus in development mode (Profile 'development')
The Maven Quarkus plugin provides a development mode that supports live coding. To try this out:
> ./mvnw quarkus:dev
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.
#### Run Quarkus as native executable
You can also create a native executable from this application without making any source code changes. A native executable removes the dependency on the JVM:
everything needed to run the application on the target platform is included in the executable, allowing the application to run with minimal resource overhead.
Compiling a native executable takes a bit longer, as GraalVM performs additional steps to remove unnecessary codepaths. Use the `native` profile to compile a
native executable:
> ./mvnw package -Pnative
After getting a cup of coffee, you'll be able to run this executable directly:
> ./target/hibernate-orm-schema-multi-tenancy-quickstart-1.0.0-SNAPSHOT-runner
### Start Quarkus in development mode (Profile 'development')
The Maven Quarkus plugin provides a development mode that supports live coding. To try this out:
> ./mvnw quarkus:dev
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.
### Run Quarkus as native executable
You can also create a native executable from this application without making any source code changes. A native executable removes the dependency on the JVM:
everything needed to run the application on the target platform is included in the executable, allowing the application to run with minimal resource overhead.
Compiling a native executable takes a bit longer, as GraalVM performs additional steps to remove unnecessary codepaths. Use the `native` profile to compile a
native executable:
> ./mvnw package -Pnative
After getting a cup of coffee, you'll be able to run this executable directly:
> ./target/hibernate-orm-schema-multi-tenancy-quickstart-1.0.0-SNAPSHOT-runner

Copy link
Member

Choose a reason for hiding this comment

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

You should probably align this file on the docs, since that's where we'll explain the quickstart:

One thing you'll want to change compared to the docs though (and maybe update in the docs): the JDBC URL property needs to be prefixed with %prod, otherwise dev services will be disabled and Quarkus will just try to connect to that URL.

So this:

quarkus.datasource.base.jdbc.url=jdbc:postgresql://localhost:5432/quarkus_test
...
quarkus.datasource.mycompany.jdbc.url=jdbc:postgresql://localhost:5433/mycompany

Should be this instead:

%prod.quarkus.datasource.base.jdbc.url=jdbc:postgresql://localhost:5432/quarkus_test
...
%prod.quarkus.datasource.mycompany.jdbc.url=jdbc:postgresql://localhost:5433/mycompany

Copy link
Member

Choose a reason for hiding this comment

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

Same here, ideally the whole file should be made consistent with the one at https://quarkus.io/guides/hibernate-orm#schema-approach

Here too, the JDBC URL should be limited to the prod profile, otherwise dev services will be disabled.

Comment on lines +10 to +17
/**
* Workaround to allow launching the Quarkus application inside the IDE.
*
* @see https://github.com/quarkusio/quarkus/issues/2143
*/
@Disabled("You can enable this pseudo test to run the app in your IDE")
@QuarkusTest
public class IdeTestApp {
Copy link
Member

Choose a reason for hiding this comment

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

This issue appears to have been fixed. I'd suggest removing this class from both Maven modules?

Copy link
Member

Choose a reason for hiding this comment

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

You should probably use @PersistenceUnitExtension here too?

@yrodiere
Copy link
Member

Also, I tested locally, it works great! Much better experience than the previous docker-compose setup with Maven profiles.

@yrodiere yrodiere self-assigned this Jan 20, 2025
Copy link

quarkus-bot bot commented Jan 20, 2025

Status for workflow Pull Request Build - development

This is the status report for running Pull Request Build - development on commit 8871672.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

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

Successfully merging this pull request may close these issues.

2 participants