diff --git a/apps/workspaces/migrations/0001_initial.py b/apps/workspaces/migrations/0001_initial.py index c10f8b2..2de501b 100644 --- a/apps/workspaces/migrations/0001_initial.py +++ b/apps/workspaces/migrations/0001_initial.py @@ -4,6 +4,7 @@ from django.conf import settings from django.db import migrations, models import ms_business_central_api.models.fields +import django.db.models.deletion class Migration(migrations.Migration): @@ -31,10 +32,26 @@ class Migration(migrations.Migration): ('business_central_company_id', ms_business_central_api.models.fields.StringNullField(help_text='Business Central Company Id', max_length=255, null=True)), ('created_at', models.DateTimeField(auto_now_add=True, help_text='Created at datetime')), ('updated_at', models.DateTimeField(auto_now=True, help_text='Updated at datetime')), - ('user', models.ManyToManyField(help_text='Reference to users table', to=settings.AUTH_USER_MODEL)), ], options={ 'db_table': 'workspaces', }, ), + migrations.CreateModel( + name='WorkspacesUser', + fields=[ + ('id', models.BigAutoField(primary_key=True, serialize=False)), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)), + ('workspace', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='workspaces.workspace')), + ], + options={ + 'db_table': 'workspaces_user', + 'unique_together': {('workspace', 'user')}, + }, + ), + migrations.AlterField( + model_name='workspace', + name='user', + field=models.ManyToManyField(help_text='Reference to users table', through='workspaces.WorkspacesUser', to=settings.AUTH_USER_MODEL), + ), ] diff --git a/apps/workspaces/migrations/0007_workspacesuser_created_at_workspacesuser_updated_at.py b/apps/workspaces/migrations/0007_workspacesuser_created_at_workspacesuser_updated_at.py new file mode 100644 index 0000000..9a89654 --- /dev/null +++ b/apps/workspaces/migrations/0007_workspacesuser_created_at_workspacesuser_updated_at.py @@ -0,0 +1,23 @@ +# Generated by Django 4.1.2 on 2024-12-19 18:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0006_rename_default_ccc_bank_account_id_exportsetting_default_ccc_bank_account_id_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='workspacesuser', + name='created_at', + field=models.DateTimeField(auto_now_add=True, help_text='Created at datetime', null=True), + ), + migrations.AddField( + model_name='workspacesuser', + name='updated_at', + field=models.DateTimeField(auto_now=True, help_text='Updated at datetime', null=True), + ), + ] diff --git a/apps/workspaces/migrations/0008_remove_workspacesuser_created_at_and_more.py b/apps/workspaces/migrations/0008_remove_workspacesuser_created_at_and_more.py new file mode 100644 index 0000000..fdb88e5 --- /dev/null +++ b/apps/workspaces/migrations/0008_remove_workspacesuser_created_at_and_more.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.2 on 2024-12-23 11:42 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0007_workspacesuser_created_at_workspacesuser_updated_at'), + ] + + operations = [ + migrations.RemoveField( + model_name='workspacesuser', + name='created_at', + ), + migrations.RemoveField( + model_name='workspacesuser', + name='updated_at', + ), + ] diff --git a/apps/workspaces/migrations/0009_add_create_at_to_workspaces_user_sql.py b/apps/workspaces/migrations/0009_add_create_at_to_workspaces_user_sql.py new file mode 100644 index 0000000..b0765af --- /dev/null +++ b/apps/workspaces/migrations/0009_add_create_at_to_workspaces_user_sql.py @@ -0,0 +1,23 @@ +# Generated by Django 4.1.2 on 2024-12-23 11:52 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0008_remove_workspacesuser_created_at_and_more'), + ] + + operations = [ + migrations.RunSQL( + sql=""" + ALTER TABLE workspaces_user + ADD COLUMN created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(); + """, + reverse_sql=""" + ALTER TABLE workspaces_user + DROP COLUMN created_at; + """, + ), + ] diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index 6e4720a..a5903d1 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -30,6 +30,16 @@ def get_default_onboarding_state(): return 'CONNECTION' +class WorkspacesUser(models.Model): + id = models.BigAutoField(primary_key=True) + workspace = models.ForeignKey('Workspace', models.DO_NOTHING) + user = models.ForeignKey('users.User', models.DO_NOTHING) + + class Meta: + db_table = 'workspaces_user' + unique_together = (('workspace', 'user'),) + + class Workspace(models.Model): """ Workspace model