How to create a hibernate view of other databases? - postgresql

Good Morning, I'm in a problem!
My project is multitenant, I use SPRING JPA + SPRINGBOOT + POSTGRES.
Where it contains a database manager and Each tenant has its own database.
The problem starts when inside the database of the tenant I have views of the data manager database.
For example, inside the database manager I have information to make the login of the users of a tenant. But in the database of each tenant should be able to have the information of their users. Where users within the tenant database could have more data!
What is the best way to do this? Should I create the view?
In addition, this application is very popular, so the idea is that the use of the database is quite dynamic.
Thank you in advance! any contribution will be helpful.

Yes the best solution will be to create views where you get all the data that you need and the data is already filtered for the tenant.
Edit:
You have to create the views on the database and then map it to read only Entities or just use it with SQL.
To have read only entities you can use Hibernates #Immutable annotation.
Please find more information in the Hibernate documentation: https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#entity-immutability

Related

Database design for custom objects for SaaS application

I’m looking forward to creating a multitenant-based SASS application. I have defined database design like each tenant using different databases (Postgres) with standard objects(tables) like contact, and accounts. So far clean, I can see many SaaS application supports Custom Object(tables), where customer can create their own objects in real-time and required columns. I would want to support the same. Could someone please explain the backend logic behind that? How can we add new tables for custom objects in the database and refresh the DbContext entity at runtime?
Note: I’m aware for custom fields, many choice JSON-type columns in Postgres, it opens ways to add as many custom columns as JSON type in existing tables. But don’t find any recommended way to do custom object support.
EF doesn't really support adding tables at runtime. You can use ADO.NET queries to work with tables whose schemas aren't known at design-time.

Suitecrm Database schema for multiple companies

How can I separate database using suitecrm.
In My application there is one source code and i want to company wise separate database.
Please help me.
You might need to use seperate installations for keeping them seperate.
Additionally, you can use $sugar_config['db'] variable to dynamically connect with a database of your choice.

Migrations and Update Database in Entity Framework for Dynamic connection string

I'm having 2 databases one for managing clients and other for managing application data. I'm trying to implement multi-tenancy application using EF code first approach where the database will be created on the fly it doesn't exist. Now tenant databases are creating fine but, database migrations are not performing since the connection string is passing programmatically. Please tell me how to do Database migrations for tenant databases where the connection string are set programmatically at runtime.
Thanks,
Naveen
Check out IDesignTimeDbContextFactor<T>
Microsoft doc: https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.design.idesigntimedbcontextfactory-1?view=efcore-2.1
Example: https://www.benday.com/2017/12/19/ef-core-2-0-migrations-without-hard-coded-connection-strings/

How to use Entity Framework with adding a new database for every new client?

I am creating a project which requires a separate database for each client. We are using EF to create interaction between database and our API.
I am not sure how to use Entity Framework every time I create a new database. What shall be the correct way of doing this?
I am getting this idea to have a config file where I can enter the entry of this new database which will then allow the users to use the system but don't know how to implement this. Can someone please suggest? Thanks in advance!

ASP.NET MVC 2: Authentication with custom SQL Database?

I'm looking into how to integrate [Authorize] within my MVC 2 application... I'm reading articles about it and I've run the aspnet_regsql tool. I see that my database now containes a bunch of new tables and a whole hell of a lot of SPROCs.
Why is all of this necessary? I thought that I would be able to check login credentials in a table that I've already created for Party ... can't I just call a SPROC that checks the login credentials and then logs the user in? Why all of these new tables and SPROCs?
Because it is the way how it is works. If you using ASP.NET Membership by default you need to have database aspnetdb with lots of tables and stored procs. If you want you may customize that. In order to do that you need to implement custom membership provider.
The simple example how to do that you may find here http://msdn.microsoft.com/en-us/library/aa479048.aspx and here http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider also source code available.
It sounds like you want to create a custom membership provider. For logging in I think you really only need to override the ValidateUser method:
http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx
For roles you may be able to get by with overriding only the IsUserInRole method:
http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx