-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: development
Are you sure you want to change the base?
Split multi-tenancy quickstart into two projects #1493
Conversation
It refers to the Quarkus guide. The documentation. So you'd need to:
|
There was a problem hiding this 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:
- Comments to be addressed/dismissed.
- A PR to be sent to the main Quarkus repo to make sure the documentation (
hibernate-orm.adoc
) is updated consistently. - 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!).
### 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 |
There was a problem hiding this comment.
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.
### 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 |
<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> |
There was a problem hiding this comment.
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
.
<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> |
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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). |
### 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 |
There was a problem hiding this comment.
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.
### 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 | |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
/** | ||
* 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
Also, I tested locally, it works great! Much better experience than the previous docker-compose setup with Maven profiles. |
Status for workflow
|
Fixes quarkusio/quarkus#41759
Check list:
Your pull request:
development
branch999-SNAPSHOT
version of Quarkusmvn clean test
)mvn clean package -Pnative
)mvn clean verify -Pnative
)README.md
file (with build and run instructions)pom.xml
andREADME.md
I split the existing quickstart into two:
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?