From 418fea2b9a45c26a122969acc595a8330d233d65 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Fri, 20 Dec 2024 00:46:23 +0530 Subject: [PATCH 1/7] 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') From 3820aaa931011f0d4cb49dbc413f13b8ff448e18 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Fri, 20 Dec 2024 00:54:27 +0530 Subject: [PATCH 2/7] flake resolved --- apps/workspaces/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index e533738..b2b0b52 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -29,6 +29,7 @@ def get_default_onboarding_state(): return 'CONNECTION' + class WorkspacesUser(models.Model): id = models.BigAutoField(primary_key=True) workspace = models.ForeignKey('Workspace', models.DO_NOTHING) @@ -37,9 +38,10 @@ class WorkspacesUser(models.Model): updated_at = models.DateTimeField(auto_now=True, null=True, help_text='Updated at datetime') class Meta: - db_table = 'workspaces_user' + db_table = 'workspaces_user' unique_together = (('workspace', 'user'),) + class Workspace(models.Model): """ Workspace model From 1198b2390449b1c98063be7d856237b720f7ff7b Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 23 Dec 2024 17:25:00 +0530 Subject: [PATCH 3/7] removing updated_at from workspaces_user --- ...move_workspacesuser_created_at_and_more.py | 21 +++++++++++++++++ ...09_add_create_at_to_workspaces_user_sql.py | 23 +++++++++++++++++++ apps/workspaces/models.py | 15 +----------- 3 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 apps/workspaces/migrations/0008_remove_workspacesuser_created_at_and_more.py create mode 100644 apps/workspaces/migrations/0009_add_create_at_to_workspaces_user_sql.py 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 b2b0b52..552e4da 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -29,26 +29,13 @@ 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): """ Workspace 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', through='WorkspacesUser') + user = models.ManyToManyField(User, help_text='Reference to users table') 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') From 3e99259cdeee5f3ca0b5766db27457e08d4d8805 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 23 Dec 2024 17:29:55 +0530 Subject: [PATCH 4/7] flake resolved --- apps/workspaces/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index 552e4da..6e4720a 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -29,6 +29,7 @@ def get_default_onboarding_state(): return 'CONNECTION' + class Workspace(models.Model): """ Workspace model From c43efc17a55f2b90e9d075c411d0ff2497be6ac8 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 23 Dec 2024 17:37:52 +0530 Subject: [PATCH 5/7] adding model --- apps/workspaces/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index 6e4720a..0fef6e8 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -30,6 +30,15 @@ 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 From f76605e3651e28dc5409f369317bbef127dd68a4 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 23 Dec 2024 17:41:39 +0530 Subject: [PATCH 6/7] flake resolved --- apps/workspaces/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index 0fef6e8..4666b0f 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -34,6 +34,7 @@ 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'),) From f6d281b5b7a911917d8a744501155d48fb11b4b0 Mon Sep 17 00:00:00 2001 From: Ashutosh619-sudo Date: Mon, 23 Dec 2024 17:44:29 +0530 Subject: [PATCH 7/7] flake resolved --- apps/workspaces/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/workspaces/models.py b/apps/workspaces/models.py index 4666b0f..a5903d1 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -34,7 +34,7 @@ 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'),)