Optimized tenant schema generation
A system includes a memory and a processor, where the processor is in communication with the memory. The processor is configured to receive a request to create a tenant schema within a database, where the database includes one or more tenant schemas associated with one or more tenants. The tenant schema associated with a tenant of the one or more tenants is created, where the tenant schema is empty. It is determined whether the database includes a template schema. Upon determining the template schema exists, command is sent to the database to copy the template schema to the tenant schema associated with the tenant.
1. A system, comprising:
a memory; and a processor in communication with the memory, wherein the processor is configured to:
receive, at an application executed on a virtual machine, a request to create a tenant schema within a database, wherein the database includes one or more tenant schemas associated with one or more tenants;
in response to the request, create the tenant schema associated with a tenant of the one or more tenants, wherein the tenant schema is empty, wherein the one or more tenants have at least one of common access to or privileges to the database;
updating the empty tenant schema according to migration files of other tenant schemas;
determine whether the database includes a template schema, wherein the template schema tracks a previous state and a current state of each tenant schema of the tenant schemas on the database to create new tenant schemas;
upon determining the template schema exists, send by the application executed on the virtual machine, a copy command to the database to copy the template schema to the tenant schema associated with the tenant; and
upon determining that the database lacks a template tenant, migrate a second tenant schema to a new tenant schema, wherein the migration of the second tenant schema includes copying modifications made to another tenant schema, and wherein the migration comprises recording a state of migrations of the other tenant schemas on the database to resolve a state of the template schema.
2. The system of claim 1 , wherein the processor is further configured to:
upon determining the database lacks the template schema, migrate a new schema to use as the template schema.
3. The system of claim 2 , wherein migration comprises recording a state of migrations of other tenant schemas on the database to resolve a state of the template schema.
4. The system of claim 2 , wherein the processor is further configured to:
update the template schema with migration changes applied to other tenant schemas in the database.
5. The system of claim 1 , wherein the template schema includes tables corresponding to each schema stored within the database.
6. The system of claim 1 , wherein the database is a structured query language (SQL) database.
7. The system of claim 1 , wherein a tenant is a group of users having common access and common privileges to the database.
8. A method, comprising:
receiving, at an application executed on a virtual machine, a request to create a tenant schema within a database, wherein the database includes one or more tenant schemas associated with one or more tenants;
in response to the request, creating the tenant schema associated with a tenant of the one or more tenants, wherein the tenant schema is empty, wherein the one or more tenants have at least one of common access to or privileges to the database;
updating the empty tenant schema according to migration files of other tenant schemas;
determining whether the database includes a template schema, wherein the template schema tracks a previous state and a current state of each tenant schema of the tenant schemas on the database to create new tenant schemas;
upon determining the template schema exists, sending by the application executed on the virtual machine, a copy command to the database to copy the template schema to the tenant schema associated with the tenant; and
upon determining that the database lacks a template tenant, migrating a second tenant schema to a new tenant schema, wherein the migration of the second tenant schema includes copying modifications made to another tenant schema, and wherein the migration comprises recording a state of migrations of the other tenant schemas on the database to resolve a state of the template schema.
9. The method of claim 8 , further comprising: upon determining the database lacks the template schema, migrating a new schema to use as the template schema.
10. The method of claim 9 , wherein migration comprises recording a state of migrations of other tenant schema on the database to resolve a state of the template schema.
11. The method of claim 9 , wherein the processor is further configured to: updating the template schema with migration changes applied to other tenant schemas in the database.
12. The method of claim 8 , wherein the template schema includes tables corresponding to each schema stored within the database.
13. The method of claim 8 , wherein the database is a structured query language (SQL) database.
14. The method of claim 8 , wherein the tenant is a group of users having common access and common privileges to the database.
15. A non-transitory machine readable medium storing code, which when executed by a processor is configured to:
receive, at an application executed on a virtual machine, a request to create a tenant schema within a database, wherein the database includes one or more tenant schemas associated with one or more tenants;
in response to the request, create the tenant schema associated with a tenant of the one or more tenants, wherein the tenant schema is empty, wherein the one or more tenants have at least one of common access to or privileges to the database;
update the empty tenant schema according to migration files of other tenant schemas;
determine whether the database includes a template schema, wherein the template schema tracks a previous state and a current state of each tenant schema of the tenant schemas on the database to create new tenant schemas;
upon determine the template schema exists, send by the application executed on the virtual machine a copy command to the database to copy the template schema to the tenant schema associated with the tenant; and
upon determine that the database lacks a template tenant, migrate a second tenant schema to a new tenant schema, wherein the migration of the second tenant schema includes copying modifications made to another tenant schema, and wherein the migration comprises recording a state of migrations of the other tenant schemas on the database to resolve a state of the template schema.
16. The non-transitory machine readable medium of claim 15 , wherein the code, when executed by a processor, is further configured to: upon determining the database lacks the template schema, migrate a new schema to use as the template schema.
17. The non-transitory machine readable medium of claim 16 , wherein migration comprises recording a state of migrations of other tenant schema on the database to resolve a state of the template schema.
18. The non-transitory machine readable medium of claim 16 , wherein the code, when executed by a processor, is further configured to: update the template schema with migration changes applied to other tenant schemas in the database.
19. The non-transitory machine readable medium of claim 15 , wherein the template schema includes tables corresponding to each schema stored within the database.
20. The non-transitory machine readable medium of claim 15 , wherein the database is a structured query language (SQL) database.