influitive / apartment

Database multi-tenancy for Rack (and Rails) applications
2.67k stars 463 forks source link

Grant failing during tenant creation when database user is not root or DBA (MySQL) #556

Open GuiDoSignal opened 6 years ago

GuiDoSignal commented 6 years ago

Steps to reproduce

  1. Use a database user that is not root or DBA on MySQL
  2. Try to create a new tenant.

Expected behavior

  1. Tenant is created and user has the same permissions on the new database as he/she had on the public database.

Actual behavior

  1. Tenant is created, but user has only the select grant given to him on the new database.

System configuration

** Additional info

I provided a work-around for this creating a CustomElevator that prepends the tenant name with a string. Then, I give the grants needed to my user on MySQL based on a wildcard (string_%) which works fine as a work-around.

I would like to bring to discussion the following ideas:

  1. Which are the minimum grants needed for the database user to use apartment?
  2. Can the code that creates the tenants include the SQL statements for providing the permissions needed on the newly created database?
  3. Is there a better approach for solving this issue than the one I came up with?

Thanks for the amazing gem and sorry if my English is not clear enough.

Bests,