forked from apptension/saas-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: apptension#382 Multi-tenancy / Add support for multiple tenants (
apptension#561) BREAKING CHANGE: Important migration instructions Before running the multi-tenancy migrations on your existing codebase or database, it is crucial to follow these steps to avoid any issues: 1. Remove or comment `DJSTRIPE_SUBSCRIBER_MODEL` setting 2. Run the migrations 3. Revert the change: After the migrations have successfully completed, revert the change by uncommenting or re-adding the `DJSTRIPE_SUBSCRIBER_MODEL` setting.
- Loading branch information
Showing
338 changed files
with
11,716 additions
and
737 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/backend/apps/demo/migrations/0003_cruddemoitem_tenant.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 4.2 on 2024-03-26 12:10 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
from apps.multitenancy.constants import TenantType | ||
|
||
|
||
def populate_tenant(apps, schema_editor): | ||
CrudDemoItem = apps.get_model('demo', 'CrudDemoItem') | ||
Tenant = apps.get_model('multitenancy', 'Tenant') | ||
|
||
for item in CrudDemoItem.objects.all(): | ||
if not item.tenant: | ||
default_tenant = Tenant.objects.filter(type=TenantType.DEFAULT, creator=item.created_by).first() | ||
item.tenant = default_tenant | ||
item.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('multitenancy', '0005_tenant_billing_email'), | ||
('demo', '0002_initial') | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='cruddemoitem', | ||
name='tenant', | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name='%(class)s_set', | ||
to='multitenancy.tenant', | ||
verbose_name='Tenant', | ||
), | ||
), | ||
migrations.RunPython(populate_tenant, reverse_code=migrations.RunPython.noop), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.