-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds many to many model tenant save (#154)
- Loading branch information
1 parent
bbb4810
commit 9ac16f3
Showing
9 changed files
with
300 additions
and
3 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
138 changes: 138 additions & 0 deletions
138
django_multitenant/tests/migrations/0024_product_purchase_store_alter_account_id_and_more.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,138 @@ | ||
# Generated by Django 4.0 on 2023-02-20 17:41 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django_multitenant.fields | ||
import django_multitenant.mixins | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("tests", "0023_auto_20200412_0603"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Product", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=255)), | ||
("description", models.TextField()), | ||
], | ||
bases=(django_multitenant.mixins.TenantModelMixin, models.Model), | ||
), | ||
migrations.CreateModel( | ||
name="Purchase", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
], | ||
bases=(django_multitenant.mixins.TenantModelMixin, models.Model), | ||
), | ||
migrations.CreateModel( | ||
name="Store", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=50)), | ||
("address", models.CharField(max_length=255)), | ||
("email", models.CharField(max_length=50)), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=(django_multitenant.mixins.TenantModelMixin, models.Model), | ||
), | ||
migrations.CreateModel( | ||
name="Transaction", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("date", models.DateField()), | ||
( | ||
"product", | ||
django_multitenant.fields.TenantForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="tests.product" | ||
), | ||
), | ||
( | ||
"purchase", | ||
django_multitenant.fields.TenantForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="tests.purchase", | ||
), | ||
), | ||
( | ||
"store", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="tests.store" | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
bases=(django_multitenant.mixins.TenantModelMixin, models.Model), | ||
), | ||
migrations.AddField( | ||
model_name="purchase", | ||
name="product_purchased", | ||
field=models.ManyToManyField( | ||
through="tests.Transaction", to="tests.Product" | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="purchase", | ||
name="store", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="tests.store" | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="product", | ||
name="store", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="tests.store" | ||
), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name="purchase", | ||
unique_together={("id", "store")}, | ||
), | ||
migrations.AlterUniqueTogether( | ||
name="product", | ||
unique_together={("id", "store")}, | ||
), | ||
] |
50 changes: 50 additions & 0 deletions
50
django_multitenant/tests/migrations/0025_many_to_many_distribute.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,50 @@ | ||
# Generated by Django 4.1 on 2023-02-23 17:24 | ||
|
||
from django.db import migrations | ||
from django_multitenant.db import migrations as tenant_migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("tests", "0024_product_purchase_store_alter_account_id_and_more"), | ||
] | ||
operations = [] | ||
|
||
operations += [ | ||
# Drop constraints | ||
migrations.RunSQL( | ||
"ALTER TABLE tests_store DROP CONSTRAINT tests_store_pkey CASCADE;" | ||
), | ||
migrations.RunSQL( | ||
"ALTER TABLE tests_product DROP CONSTRAINT tests_product_pkey CASCADE;" | ||
), | ||
migrations.RunSQL( | ||
"ALTER TABLE tests_purchase DROP CONSTRAINT tests_purchase_pkey CASCADE;" | ||
), | ||
migrations.RunSQL( | ||
"ALTER TABLE tests_transaction DROP CONSTRAINT tests_transaction_pkey CASCADE;" | ||
), | ||
] | ||
|
||
operations += [ | ||
tenant_migrations.Distribute("Store"), | ||
tenant_migrations.Distribute("Product"), | ||
tenant_migrations.Distribute("Purchase"), | ||
tenant_migrations.Distribute("Transaction"), | ||
] | ||
|
||
operations += [ | ||
migrations.RunSQL( | ||
"ALTER TABLE tests_store ADD CONSTRAINT tests_store_pkey PRIMARY KEY (id);" | ||
), | ||
migrations.RunSQL( | ||
"ALTER TABLE tests_product ADD CONSTRAINT tests_product_pkey PRIMARY KEY (store_id, id);" | ||
), | ||
migrations.RunSQL( | ||
"ALTER TABLE tests_purchase ADD CONSTRAINT tests_purchase_pkey PRIMARY KEY (store_id, id);" | ||
), | ||
migrations.RunSQL( | ||
"ALTER TABLE tests_transaction ADD CONSTRAINT tests_transaction_pkey PRIMARY KEY (store_id, id);" | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
[pytest] | ||
addopts = --reuse-db | ||
addopts = --reuse-db | ||
filterwarnings = | ||
ignore::pytest.PytestCacheWarning | ||
|