RamyHakam / multi-tenancy-project-example

This is a simple example of using the https://github.com/RamyHakam/multi_tenancy_bundle
4 stars 3 forks source link

Error when connecting to postgreSql #7

Closed davidperezsantos closed 4 months ago

davidperezsantos commented 7 months ago

Good morning, I have the following error when working with the library, please could you help me

Warning: Undefined property: Hakam\MultiTenancyBundle\Doctrine\DBAL\TenantConnection::$_driver

My configuration is as follows, if you need more information, write to me, thank you

hakam_multi_tenancy: tenant_database_className: App\Entity\Main\TenantDbConfig tenant_database_identifier: id tenant_connection: host: 127.0.0.1 port: 5432 password: postgres user: postgres driver: pdo_pgsql charset: utf8

tenant_migration: tenant_migration_namespace: DoctrineMigrations\Tenant tenant_migration_path: migrations/Tenant tenant_entity_manager: dql: string_functions: test_string: App\DQL\StringFunction second_string: App\DQL\SecondStringFunction numerical_functions: test_numeric: App\DQL\NumericFunction datetime_functions: test_datetime: App\DQL\DatetimeFunction mapping: type: attribute dir: '%kernel.project_dir%/src/Entity/Tenant' prefix: App\Entity\Tenant alias: Tenant

RamyHakam commented 4 months ago

Hey, I think you can use the least version 2.7.2 will the fix of this issue

davidperezsantos commented 4 months ago

I don't understand how I do this, can you explain to me how I put version 2.7.2

RamyHakam commented 4 months ago

Sorry, You can use the latest version 2.7.1 from the main bundle update your composer.json file and use 2.7.1 for the bundle

davidperezsantos commented 4 months ago

Now I have several doubts, when I run the command php bin/console tenant:database:create $tenantDbConfig->getDbName() it shows me the following error: [critical] Error thrown while running command "tenant:database:create tenantstore1". Message: "No arguments expected for "tenant:database:create" command, got "tenantstore1"." image

and the other where I define the entities that will be created in the new database

And last question, how can I know from an external application which database I access?

Thanks for the help.

RamyHakam commented 4 months ago

For your current issue, the command to create db does not accept any argument , it starts to load the new tenant DB list from the main DB and make them one by one, Please check the main bundle Readme file to see where you can add the new entities for tenant

davidperezsantos commented 4 months ago

Sorry for the inconvenience, but I still don't understand if I have several tenants, how does the system know which database it is going to access, assuming that the tenant is a company and it is the one for which I create the tenant configuration, and the users are different for each company, so since I know which one it belongs to, can you help me with this question, thank you

RamyHakam commented 4 months ago

For my understading , Your Tenant Uses should have a db id in there data config in your system , once the user is logged in you can use this db I dentifer to connect to the tenant db another way is to based on request type , Domain , subdomain , etc , you can fire the event in the request kernal event based on the db id for that company or user request

davidperezsantos commented 4 months ago

Where can I see these two examples in practice?

RamyHakam commented 4 months ago

Pleae check the main bundle to understand how you can store the db id for your users, also in the example you can see in the readme file an example to add a user with a db id and switching EM to that db , you can add users as you can and switch between them in runtime