From a2840913c919ee5698b001b03b1c5dc2e7bfe8e5 Mon Sep 17 00:00:00 2001 From: Ashutosh singh <55102089+Ashutosh619-sudo@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:21:17 +0530 Subject: [PATCH] Feat: Add created_at, created_at to workspace_schedule and workspaces_user (#709) --- .../migrations/0049_auto_20241223_1039.py | 33 +++++++++++++ apps/workspaces/models.py | 2 + .../reset_db_fixtures/reset_db.sql | 49 +++++++++++-------- 3 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 apps/workspaces/migrations/0049_auto_20241223_1039.py diff --git a/apps/workspaces/migrations/0049_auto_20241223_1039.py b/apps/workspaces/migrations/0049_auto_20241223_1039.py new file mode 100644 index 00000000..6bcdb01e --- /dev/null +++ b/apps/workspaces/migrations/0049_auto_20241223_1039.py @@ -0,0 +1,33 @@ +# Generated by Django 3.2.14 on 2024-12-23 10:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0048_alter_workspace_onboarding_state'), + ] + + operations = [ + migrations.AddField( + model_name='workspaceschedule', + name='created_at', + field=models.DateTimeField(auto_now_add=True, help_text='Created at datetime', null=True), + ), + migrations.AddField( + model_name='workspaceschedule', + name='updated_at', + field=models.DateTimeField(auto_now=True, help_text='Updated at datetime', null=True), + ), + 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 84a64415..ba11051b 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -75,6 +75,8 @@ class WorkspaceSchedule(models.Model): additional_email_options = JSONField(default=list, help_text='Email and Name of person to send email', null=True) emails_selected = ArrayField(base_field=models.CharField(max_length=255), null=True, help_text='Emails that has to be send mail') schedule = models.OneToOneField(Schedule, on_delete=models.PROTECT, null=True) + 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 = 'workspace_schedules' diff --git a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql index 9ed3be11..02ec4662 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -1906,7 +1906,9 @@ CREATE TABLE public.workspace_schedules ( workspace_id integer NOT NULL, additional_email_options jsonb, emails_selected character varying(255)[], - error_count integer + error_count integer, + created_at timestamp with time zone, + updated_at timestamp with time zone ); @@ -1987,7 +1989,8 @@ ALTER SEQUENCE public.workspaces_qbocredential_id_seq OWNED BY public.qbo_creden CREATE TABLE public.workspaces_user ( id integer NOT NULL, workspace_id integer NOT NULL, - user_id integer NOT NULL + user_id integer NOT NULL, + created_at timestamp with time zone DEFAULT now() NOT NULL ); @@ -4082,6 +4085,9 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 196 tasks 0012_auto_20241127_0730 2024-11-27 07:49:43.762663+00 197 workspaces 0047_alter_workspacegeneralsettings_change_accounting_period 2024-11-27 07:49:43.779315+00 198 quickbooks_online 0018_creditcardpurchase_exchange_rate 2024-12-10 06:00:05.224041+00 +199 fyle_accounting_mappings 0027_alter_employeemapping_source_employee 2024-12-23 10:37:03.397276+00 +200 workspaces 0048_alter_workspace_onboarding_state 2024-12-23 10:37:03.418502+00 +201 workspaces 0049_auto_20241223_1039 2024-12-23 10:41:16.03056+00 \. @@ -33916,11 +33922,11 @@ COPY public.workspace_general_settings (id, reimbursable_expenses_object, corpor -- Data for Name: workspace_schedules; Type: TABLE DATA; Schema: public; Owner: postgres -- -COPY public.workspace_schedules (id, enabled, start_datetime, interval_hours, schedule_id, workspace_id, additional_email_options, emails_selected, error_count) FROM stdin; -1 f \N \N \N 2 [] \N \N -2 f \N \N \N 3 [] \N \N -3 f \N \N \N 4 [] \N \N -4 f \N \N \N 5 [] \N \N +COPY public.workspace_schedules (id, enabled, start_datetime, interval_hours, schedule_id, workspace_id, additional_email_options, emails_selected, error_count, created_at, updated_at) FROM stdin; +1 f \N \N \N 2 [] \N \N 2024-12-23 10:41:16.017908+00 2024-12-23 10:41:16.028838+00 +2 f \N \N \N 3 [] \N \N 2024-12-23 10:41:16.017908+00 2024-12-23 10:41:16.028838+00 +3 f \N \N \N 4 [] \N \N 2024-12-23 10:41:16.017908+00 2024-12-23 10:41:16.028838+00 +4 f \N \N \N 5 [] \N \N 2024-12-23 10:41:16.017908+00 2024-12-23 10:41:16.028838+00 \. @@ -33941,12 +33947,12 @@ COPY public.workspaces (id, name, fyle_org_id, qbo_realm_id, last_synced_at, cre -- Data for Name: workspaces_user; Type: TABLE DATA; Schema: public; Owner: postgres -- -COPY public.workspaces_user (id, workspace_id, user_id) FROM stdin; -1 1 1 -2 2 1 -3 3 1 -4 4 1 -5 5 1 +COPY public.workspaces_user (id, workspace_id, user_id, created_at) FROM stdin; +1 1 1 2024-12-23 10:41:16.018067+00 +2 2 1 2024-12-23 10:41:16.018067+00 +3 3 1 2024-12-23 10:41:16.018067+00 +4 4 1 2024-12-23 10:41:16.018067+00 +5 5 1 2024-12-23 10:41:16.018067+00 \. @@ -34010,7 +34016,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 47, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 198, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 201, true); -- @@ -34447,6 +34453,14 @@ ALTER TABLE ONLY public.employee_mappings ADD CONSTRAINT employee_mappings_pkey PRIMARY KEY (id); +-- +-- Name: employee_mappings employee_mappings_source_employee_id_dd9948ba_uniq; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.employee_mappings + ADD CONSTRAINT employee_mappings_source_employee_id_dd9948ba_uniq UNIQUE (source_employee_id); + + -- -- Name: errors errors_expense_attribute_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres -- @@ -35101,13 +35115,6 @@ CREATE INDEX employee_mappings_destination_employee_id_b6764819 ON public.employ CREATE INDEX employee_mappings_destination_vendor_id_c4bd73df ON public.employee_mappings USING btree (destination_vendor_id); --- --- Name: employee_mappings_source_employee_id_dd9948ba; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX employee_mappings_source_employee_id_dd9948ba ON public.employee_mappings USING btree (source_employee_id); - - -- -- Name: employee_mappings_workspace_id_4a25f8c9; Type: INDEX; Schema: public; Owner: postgres --