Open stancl opened 3 years ago
Samuel - thanks a lot for all the great work you put into this. I completely agree with your priorities. Security, stability and compatibility are for many the most important factors. New features are less important and historically a source to problems with the three mentioned areas.
Great news, Thank you for providing such a good package. looking forward to the new version of the SaaS template. I hope the template can fit the following situations out of the box:
It would be useful if the connection name used in trait TenantConnection is taken from the config
@medvinator What benefit would that bring?
@medvinator What benefit would that bring?
Convenience when working with code.
I creating service with 3 app level: director
, partner
and client
Partners are tenants of the director (implemented by package spatie/laravel-multitenancy). Clients are tenants of a partner (implemented by package stancl/tenancy).
Each partner and client has its own database. There are several models that are common for both the partner and the client (for example, webhooks). Therefore, there must be a different connection, it is implemented like this
public function getConnectionName(): ?string
{
return match (level()->current) {
'director' => 'director',
'partner' => 'partner',
'client' => 'tenant'
};
}
As you can see, it would be convenient to name the connection not tenant
, but a client
and do so
public function getConnectionName(): ?string
{
return level()->current;
}
It would be possible to call the client's level a tenant
, but this would potentially add confusion.
Thank you for your attention and a wonderful package, I hope I explained clearly.
I was wondering a little about about the structure of App\Providers\TenancyServiceProvider
Would it make sense to extract Pipelines into into own namespace? Something along the lines of:
....
Events\TenantCreated::class => TenantCreatedPipeline::class,
....
So that ServiceProvider gets less crowded?
I would love to see an implementation of Postgres Row Level Security.
Right now, there is a trade-off with the current options of multi-database vs. single-database tenancy.
Postgres RLS: Best of both worlds without the drawbacks?
Since you can already separate the tenants by schema rather than full DB for Postgres, perhaps implementing an RLS version is feasible? It seems like the holy grail of lower ops complexity but not having to worry about so many WHERE
clauses.
AWS blog has a great article about RLS and multi-tenancy specifically: https://aws.amazon.com/blogs/database/multi-tenant-data-isolation-with-postgresql-row-level-security/
@jcs224 That's a great suggestion. I'll definitely try to do that in v4!
Is this getting solved in v4? https://github.com/archtechx/tenancy/issues/645
Yes
@stancl Thanks for the great package. I was hoping V4 would improve performance with testing.
expecting a dramatic performance boost with Octane supported in V4
You shouldn't really. Octane is nice, but I don't think it'd provide a dramatic boost in performance for almost any applications. Proper database performance practices will go a lot longer way.
One thing I'd be interested in is a way to manage a Tenant's resources within the central application's Nova, especially if they could be included in a similar way to how Nova's relationship fields worked.
It would be very nice to be able to see a list of all users configured in the tenant portion, it could be very handy in combination with the User Impersonation feature, as you'd pretty easily be able to create an action to impersonate a user and redirect to the tenant's application.
Tiny little thing - but it would be nice (for me) to be able to run something like php artisan tenants:migrate --with-main
or something that also ran your 'normal' migrations.
@ohnotnow you can always extend the command, no?
I think putting php artisan migrate && php artisan tenants:migrate
in your deployment script is the best way to go about this
It's more for places you're doing docker/k8s things. You can have a pod that runs your migrations like
...
command: ["php"]
args: ["/var/www/html/artisan", "migrate", "--force"]
so you can only have one 'command' and it doesn't understand shell things like &&
. It can be worked around fairly easily, and as I say - it's a tiny little thing. Just be handy. Possibly only for me I admit :-)
@ohnotnow just wrap two commands in one
Yeah - I know - it was just a tiny little suggestion to save a tiny bit of work (for me) :-)
.. and file storage is now something that can be build at runtime:
Cool, we're already doing that using lower level calls but this provides a nice API for that
Improvement:
Tenants table migration have onDelete cascade reference to delete its domains. This is good but you can't use Listeners on DeletingDomain/DomainDeleted events to perform your own actions.
The proposal is remove onDelete cascade reference and use TenantDeleted pipeline to perform domains deletion.
Apparently it is not necessary to do the same with onUpdate reference, but it might be good to remove all database cascade references and get full control through Events.
I'm still a novice at Tenancy, but this is what I would like, or what I did not find yet ;)
I know this is probably easily implemented in custom code, but if you're going for a great out-of-the-box experience, these might be nice additions.
I'm still a novice at Tenancy, but this is what I would like, or what I did not find yet ;)
- Table prefix Tenancy.
- Tenant identification by bearer token (Laravel Sanctum / API).
- Automatic removal of created databases in tests.
I know this is probably easily implemented in custom code, but if you're going for a great out-of-the-box experience, these might be nice additions.
1st one already exists in tenancy config files :), API identification is quite easy, just implement your own token system using the UUID system already built-in setup a middleware that checks the API token exists against the user and against user agents or a fingerprint of the users setup problem solved
Will v4 support Octane? And if so, will both Swoole and Roadrunner be supported?
We're building a new app using Octane at the moment and would love an easy way to add multi tenancy.
Tenancy and Octane could be a bit complex, but looking at how Octane separates things, it should probably work fine. I'll try to specifically test that, though it probably won't be a guaranteed feature
If suggestions are still open, perhaps some kind of Laravel Scout integration?
Tenancy and Octane could be a bit complex, but looking at how Octane separates things, it should probably work fine. I'll try to specifically test that, though it probably won't be a guaranteed feature
have been using Octane and Tenancy V3, since Octane releases a couple of months ago, yeah, it works fine. haven't caught into anything buggy or weird stuff until now. back then, I had used laravel-swoole-tw with Tenancy V3, there were some clear gotchas though hope you can go through all those specific tests and make this happen, or maybe list out things that should pay attention to when integrating octane. great thanks
FWIW I don't find Octane to be that useful for 99% of apps, and tenancy seems like the single most dangerous thing to use with Octane. Sure, Octane does separate Container state well, but some code may use other forms of global state and with Tenancy it's best to separate tenants as much as possible to avoid any risks. For the same reason I'd also generally use Vapor and cloud based services like S3 rather than hosting multiple tenants on the same stateful server.
That said, I'll try to make sure it's supported, but it'll always come with a disclaimer.
@stancl, any approximate release date? at least for the beta
After Lean Admin is launched in a few weeks, I'll be working on the new SaaS boilerplate and v4 will be released alongside the boilerplate 👍🏻
You already said you would look at it for v4 on issue #250 itself, but for overview purposes: having a solution for slow tests documented and in the boilerplate.
You already said you would look at it for v4 on issue #250 itself, but for overview purposes: having a solution for slow tests documented and in the boilerplate.
Check https://github.com/archtechx/tenancy/issues/250#issuecomment-927124384
Packages in vendor for the tenant application are not migrated since the configurable path by default uses "database/migrations/tenant"
Having to manually define the multiple packages on the path configurable is not good (hardcoded code)
And this one is just an idea:
Would be great to have an API with it's own routes etc on the library. This will lead to the posiblity of creating a product like "Saas Boilerplate" but a SPA one. No need to install on your application but as a separate application (which connects through a new API to the central database). With this it would be easy to create a SPA SaaS boilerplate installable with a simple docker image and fully independant of the tenant application)
@stancl Will Lighthouse-php be supported?
Also +1 for API endpoints. That'd be really useful for deploying tenants across multiple servers.
If you need any help with getting Version 4 released, please let me know. I can help with testing, bug fixes, etc....
After Lean Admin is launched in a few weeks, I'll be working on the new SaaS boilerplate and v4 will be released alongside the boilerplate 👍🏻
It's almost 6 months since you announced that 'v4' is coming. The announcement of 'Lean Admin' is also 10 weeks past. Nothing is released yet. Can we get an estimated release date, month, or year for any of these?
The projects (mainly Lean, with the rest depending on me finishing Lean) got delayed due to a couple of reasons, yes.
Can we get an estimated release date, month, or year for any of these?
Not with this tone. I mean, I could provide some (more accurate) estimates for those projects, but I don't want to incentivize requests written in an entitled tone.
Created a project here which will include all of the open issues and PRs that I'll deal with in v4.
Some of them are bugs that can be addressed in v3 as well, since the fix will be the same. But in general, all feature additions will be in v4.
Would appreciate some feedback on this issue, if you'd like to see the feature in v4: https://github.com/archtechx/tenancy/issues/752
For context: when I'll be working on v4, it'll probably be in this order:
SerializesModels
even with tenant models, but we'd need to make some small changes, possibly to Laravel itself. I'd like to do this before L9 RC1 is taggedPoints 1) 2) 3) aren't separate from the open issues, they'll actually close like ~5 issues that are open right now.
For the 3.x branch, I'll resolve these tasks, and everything else will be done in v4.
v4 will required Laravel 9 and therefore PHP 8.0. Depending on how good the ecosystem support is for 8.1 when I'll be working on v4, I might even go for 8.1. It'll only be used on new projects or projects that stay up to date (Laravel 9), so the PHP version change shouldn't be an issue.
That said, I wouldn't go for 8.1 in a project right now because it's still a bit rough to use. Composer shows a lot of deprecation warnings, some IDEs don't fully support the new syntax, and other minor ecosystem-related things like that.
Will there be allow turning off default personal team and make teams with hierarchy?
hey @stancl
First of all thank you for the great package. Do you know when you will be ready for Laravel 9? Will that be on v3 or v4?
Thanks again
For now I recommend following the guide in the docs.
v4 will come out a few weeks after Laravel 9. With v3 only supporting Laravel 8 for now.
I might end up adding L9 support to both v3 and v4, but I'm not 100% decided yet. There are some larger changes I'd need to make to support both L8 and L9 in the same version of Tenancy, so I'll take a look at those when L9 has a stable release.
@stancl Ok thanks for the prompt reply. I believe I can fix the binding issue tbh. I am more concern into L9 support which I would like to update my app as soon it gets released (stable).
Right now that's not possible with v3 and with v4 being available weeks after L9 release I think you will have to update v3 to support L9. Otherwise we will have to fork the package for some time :/
What's not possible with v3? Laravel 9 compatibility?
Is there a reason why you'd need to use L9 immediately after release? I think L8 will still have decent support for many months
L9 will be the LTS version plus I would like to get to the most up to date version with all the goodies
I see. In that case I'd just stick to L8 and upgrade later on — Laravel upgrades are generally very easy.
As for maintaining a fork, the reason why we can't have L9 support straight away is that concrete (and potentially complex) code changes are needed, so it's not as simple as changing the composer.json
file. You'd have to handle all of this yourself if you wanted to have a fork.
I'm also looking forward to upgrade to L9 ASAP. However, I'd rather upgrade tenancy package to v4 first so Laravel upgrade goes smoothly. This package is the only one that keeps us from upgrading. What can we do to speed up v4 release?
Update: Version 4 is now in early access, see the
#announcements
channel on our DiscordHey everyone,
Soon (in a few weeks) I'll start working on the next major version of Tenancy for Laravel.
v3 has worked extremely well, with me writing most of the code in spring 2020 and very few changes being needed for a year. The core is really solid.
That said, there's always room for improvement, which is what version 4 be focused on.
Currently, I have these changes planned:
In short, the major version won't have too many changes, and most will be quality of life improvements.
But those are my plans. If you would like to see any new features or changes, please share them below. I'd love to hear any feature suggestions or other feedback, because I'll be working a lot on the package now, and I'll have a chance to work on features that would normally not be possible to add due to breaking changes.
Thank you!