From 418fea2b9a45c26a122969acc595a8330d233d65 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Fri, 20 Dec 2024 00:46:23 +0530 Subject: [PATCH] Fix: Add created_at, created_at to workspace_schedule and workspaces_user table --- apps/workspaces/migrations/0001_initial.py | 19 ++++++++++++++- ...er_created_at_workspacesuser_updated_at.py | 23 +++++++++++++++++++ apps/workspaces/models.py | 12 +++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 apps/workspaces/migrations/0007_workspacesuser_created_at_workspacesuser_updated_at.py 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/models.py b/apps/workspaces/models.py index 6e4720a..e533738 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -29,6 +29,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) + created_at = models.DateTimeField(auto_now_add=True, null=True, help_text='Created at datetime') + updated_at = models.DateTimeField(auto_now=True, null=True, help_text='Updated at datetime') + + class Meta: + db_table = 'workspaces_user' + unique_together = (('workspace', 'user'),) class Workspace(models.Model): """ @@ -36,7 +46,7 @@ class Workspace(models.Model): """ id = models.AutoField(primary_key=True) name = StringNotNullField(help_text='Name of the workspace') - user = models.ManyToManyField(User, help_text='Reference to users table') + user = models.ManyToManyField(User, help_text='Reference to users table', through='WorkspacesUser') org_id = models.CharField(max_length=255, help_text='org id', unique=True) reimbursable_last_synced_at = CustomDateTimeField(help_text='Datetime when expenses were pulled last') credit_card_last_synced_at = CustomDateTimeField(help_text='Datetime when ccc expenses were pulled last')