Mysql compatibility#53
Mysql compatibility#53mgiacomini merged 14 commits intoateliware:masterfrom maxmarcon:mysql-compatibility-upstream
Conversation
mix.exs
Outdated
| {:ecto, "~> 2.1"}, | ||
| {:postgrex, ">= 0.11.0"}, | ||
|
|
||
| {:mariaex, "~> 0.8.2"}, |
There was a problem hiding this comment.
So, let's make this one and :postgrex dependencies optional, since the user will probably choose between one and another.
There was a problem hiding this comment.
I kept only mariaex optional, because otherwise your test suite fails. It's weird, I would have expected the "optional" requirement to have an effect only if the project is included by another one: https://hexdocs.pm/mix/Mix.Tasks.Deps.html but I must be missing something.
lib/triplex.ex
Outdated
| case SQL.query(repo, "DELETE FROM #{Triplex.config().tenant_table} WHERE NAME = ?", [tenant]) do | ||
| {:error, msg} -> {:error, msg} | ||
| _ -> {:ok, tenant} | ||
| end |
There was a problem hiding this comment.
We could refactor this nested cases to use a with
lib/triplex.ex
Outdated
| {:error, reserved_message(new_tenant)} | ||
| else | ||
| repo.__adapter__ == Ecto.Adapters.MySQL -> | ||
| {:error, "you cannot rename tenants in a MySQL database. You will have to drop the tenant and recreate it with a different name"} |
There was a problem hiding this comment.
Well, to drop the tenant and create another is not a good option, since the user will lose all his tenant data. Let's remove this part and stay only with: "you cannot rename tenants in a MySQL database"
There was a problem hiding this comment.
Good point, changed.
lib/triplex.ex
Outdated
| sql = case repo.__adapter__ do | ||
| Ecto.Adapters.MySQL -> | ||
| "SELECT name FROM #{config().tenant_table}" | ||
| _ -> |
There was a problem hiding this comment.
Let's "let it fail" and put Ecto.Adapters.Postgres on this case clause ;)
lib/triplex.ex
Outdated
| sql = case repo.__adapter__ do | ||
| Ecto.Adapters.MySQL -> | ||
| "SELECT COUNT(*) FROM #{config().tenant_table} WHERE name = ?" | ||
| _ -> |
There was a problem hiding this comment.
Let's "let it fail" and put Ecto.Adapters.Postgres on this case clause ;)
|
@kelvinst thanks for your comments. I addressed them the best I could. I also did 2 additional things:
|
|
Hey @maxmarcon cool! Sorry for the delay, new job. 😬 I'll review it soon, I promise. 😄 |
lib/mix/tasks/triplex.init.tenant.ex
Outdated
| @@ -0,0 +1,58 @@ | |||
| defmodule Mix.Tasks.Triplex.Init.Tenant do | |||
There was a problem hiding this comment.
What about renaming this task to triplex.mysql.install?
…figuration in README
Here's the PR for issue #52
Looking forward to your comments.