I have posted qu开发者_StackOverflowite a general question about implementing a multi-tenant solution using very specific technologies in the past. I now have a much more specific question that I was hoping to get some input on.
For our multi-tenant application we have a requirement to export a single tenant's data from one database into another database. For example, our DB might contain 10 tenants' data but one of these 10 tenants wants to have his own instance of the application (for whatever reasons, e.g. they require very specific customizations).
So I basically want to be able to write a "tool" to take only the data for tenant X and move that into it's own database.
We are using a MySQL database and also the latest version of Hibernate core and annotations.
The way we have implemented multi-tenancy is basically to add a tenant id to all our tables / the base class from which all our entities extend.
Originally I thought that I could just use something like this:
mysqldump -uusername -ppassword database_name -w "tenant_id=1" > dump.sql
but unfortunately all @JoinTables do not have a tenant_id so this fails.
My question is: does anyone have any good ideas about how to export a single tenant's data and then import this into a new database (which I guess I can create using the standard Hibernate SchemaExport)?
I had one idea but for me to implement it properly I would need Hibernate to create my db schema with no constraints on it and then I could pump the data in and I would then need to put the constraints on the db post import. I have no idea how to get Hibernate to not add constraints at first and then do it later though so if anyone has an idea please let me know.
Thanks
精彩评论