tenancy / multi-tenant

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
https://tenancy.dev
MIT License
2.56k stars 392 forks source link

Error creating tenant user #926

Open iwaheedshahzad opened 4 years ago

iwaheedshahzad commented 4 years ago

Description SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF NOT EXISTS fsdfsd.tenant@'127.0.0.1' IDENTIFIED BY '9aa7cb964ca9d081fc65d47' at line 1 (SQL: CREATE USER IF NOT EXISTS fsdfsd.tenant@'127.0.0.1' IDENTIFIED BY '9aa7cb964ca9d081fc65d476b0340995') Screenshot (143)

iwaheedshahzad commented 4 years ago

Also I have granted all prevelages to user .

bkintanar commented 4 years ago

What's the mariadb version you're using? Requirements are

MySQL 5.7+, MariaDB 10.2.0+ or PostgreSQL 9+.

iwaheedshahzad commented 4 years ago

What's the mariadb version you're using? Requirements are

MySQL 5.7+, MariaDB 10.2.0+ or PostgreSQL 9+.

Yes i have checked . Version is greater than required.

Bibendus83 commented 4 years ago

It seems your version of MariaDB is not supporting the "IF NOT EXISTS" clause but I'm not able to find the first version it was implemented in. Check again your MariaDB version, maybe you have a configuration with multiple DB servers goin on and you are connecting to the wrong DB.

BTW reading this other ticket (#928) I would like to ask, why exactly "IF NOT EXISTS" is used? If the user already exists and hyn is trying to create a new user with a different password no error will be thrown resulting in an inconsistent user configuration. Shouldn't that be removed?

fletch3555 commented 4 years ago

IF NOT EXISTS is there so the package doesn't error (causes more confusion for users). Everyone just has to make sure to use the repository classes when creating/deleting things, or at least fire the events.

Bibendus83 commented 4 years ago

@fletch3555 Without an error, developers think that all is fine while it sure isn't. I think it's better to throw an error at the right point (I can't create a user because it already exists) than having to debug the reason I can't login with that user because it was created earlier with a different password (many possibilities, wrong user? wrong password? user doesn't exist? user has no rights? etc.)

fletch3555 commented 4 years ago

What if a user doesn't want to use a unique user for each? They can override things to make the parameters be the same, so when it tries to create the user, it'll just silently pass. If we change that, that won't be possible anymore.

Bibendus83 commented 4 years ago

Isn't the new user creation related to the auto-create-tenant-database-user setting? If it's set to true you clearly want a user for each database and in this case the query should not include a IF NOT EXISTS statement for the reason I stated before.