From e9e5117222c0ab8b68ddf9bb2f8fbd1f0f5356d8 Mon Sep 17 00:00:00 2001 From: Ashutosh singh <55102089+Ashutosh619-sudo@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:21:09 +0530 Subject: [PATCH] Feat: Add created_at, created_at to workspace_schedule and workspaces_user (#418) --- .../migrations/0041_auto_20241223_1102.py | 33 +++++++++++++++++++ apps/workspaces/models.py | 2 ++ .../reset_db_fixtures/reset_db.sql | 32 ++++++++++-------- 3 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 apps/workspaces/migrations/0041_auto_20241223_1102.py diff --git a/apps/workspaces/migrations/0041_auto_20241223_1102.py b/apps/workspaces/migrations/0041_auto_20241223_1102.py new file mode 100644 index 00000000..1e71077f --- /dev/null +++ b/apps/workspaces/migrations/0041_auto_20241223_1102.py @@ -0,0 +1,33 @@ +# Generated by Django 3.2.14 on 2024-12-23 11:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('workspaces', '0040_workspacegeneralsettings_memo_structure'), + ] + + 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 f018c98c..f0bb2f16 100644 --- a/apps/workspaces/models.py +++ b/apps/workspaces/models.py @@ -249,6 +249,8 @@ class WorkspaceSchedule(models.Model): null=True, help_text="Emails that has to be send mail", ) + 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 7a4c0a28..9199736d 100644 --- a/tests/sql_fixtures/reset_db_fixtures/reset_db.sql +++ b/tests/sql_fixtures/reset_db_fixtures/reset_db.sql @@ -1555,7 +1555,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 ); @@ -1615,7 +1617,8 @@ ALTER SEQUENCE public.workspaces_id_seq OWNED BY public.workspaces.id; 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 ); @@ -2645,6 +2648,8 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 158 workspaces 0039_alter_workspacegeneralsettings_change_accounting_period 2024-11-18 04:43:45.472917+00 159 fyle 0022_support_split_expense_grouping 2024-11-18 10:49:49.550689+00 160 workspaces 0040_workspacegeneralsettings_memo_structure 2024-12-03 21:13:46.617079+00 +161 fyle_accounting_mappings 0027_alter_employeemapping_source_employee 2024-12-23 11:03:59.013177+00 +162 workspaces 0041_auto_20241223_1102 2024-12-23 11:03:59.043589+00 \. @@ -5077,7 +5082,7 @@ 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; +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; \. @@ -5094,8 +5099,8 @@ COPY public.workspaces (id, name, fyle_org_id, last_synced_at, created_at, updat -- 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 +COPY public.workspaces_user (id, workspace_id, user_id, created_at) FROM stdin; +1 1 1 2024-12-23 11:03:59.028742+00 \. @@ -5182,7 +5187,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 40, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 160, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 162, true); -- @@ -5596,6 +5601,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 -- @@ -6145,13 +6158,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 --