Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add created_at, created_at to workspace_schedule and workspaces… #585

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions apps/workspaces/migrations/0040_auto_20241223_1050.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.14 on 2024-12-23 10:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0039_alter_configuration_change_accounting_period'),
]

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),
),
Comment on lines +18 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ensure consistent usage of auto_now.&auto_now_add
auto_now and auto_now_add are both appropriate here, but confirm consistency across models so that timestamps are always handled in an expected manner.

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;
""",
),
]
2 changes: 2 additions & 0 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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'
Expand Down
36 changes: 21 additions & 15 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 15.9 (Debian 15.9-1.pgdg120+1)
-- Dumped by pg_dump version 15.8 (Debian 15.8-1.pgdg120+1)
-- Dumped from database version 15.10 (Debian 15.10-1.pgdg120+1)
-- Dumped by pg_dump version 15.10 (Debian 15.10-1.pgdg120+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down Expand Up @@ -2059,7 +2059,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
Comment on lines +2062 to +2064
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding NOT NULL constraints and default values

The new timestamp columns lack NOT NULL constraints and default values. This could lead to inconsistent data tracking.

Consider modifying the columns as follows:

-    created_at timestamp with time zone,
-    updated_at timestamp with time zone
+    created_at timestamp with time zone DEFAULT now() NOT NULL,
+    updated_at timestamp with time zone DEFAULT now() NOT NULL
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
error_count integer,
created_at timestamp with time zone,
updated_at timestamp with time zone
error_count integer,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL

);


Expand Down Expand Up @@ -2160,7 +2162,8 @@ ALTER SEQUENCE public.workspaces_sageintacctcredential_id_seq OWNED BY public.sa
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
);


Expand Down Expand Up @@ -4137,6 +4140,8 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin;
198 tasks 0010_alter_tasklog_expense_group 2024-11-18 04:59:52.206781+00
199 workspaces 0039_alter_configuration_change_accounting_period 2024-11-18 05:05:10.975057+00
200 fyle 0035_expense_masked_corporate_card_number 2024-11-20 02:49:32.481921+00
201 fyle_accounting_mappings 0027_alter_employeemapping_source_employee 2024-12-23 10:52:45.346752+00
202 workspaces 0040_auto_20241223_1050 2024-12-23 10:52:45.388875+00
\.


Expand Down Expand Up @@ -8048,7 +8053,7 @@ COPY public.users (password, last_login, id, email, user_id, full_name, active,
-- 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;
\.


Expand All @@ -8065,8 +8070,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 10:52:45.370215+00
\.


Expand Down Expand Up @@ -8144,7 +8149,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 50, true);
-- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.django_migrations_id_seq', 200, true);
SELECT pg_catalog.setval('public.django_migrations_id_seq', 202, true);


--
Expand Down Expand Up @@ -8620,6 +8625,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
--
Expand Down Expand Up @@ -9340,13 +9353,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
--
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workspaces/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@
'masked_corporate_card_number': '**** 4567'
}
],
'workspace_schedule': {'id': 1, 'enabled': True, 'start_datetime': '2022-09-26T13:08:16.281604Z', 'interval_hours': 1, 'error_count': None, 'additional_email_options': [], 'emails_selected': ['[email protected]'], 'workspace': 1, 'schedule': 9}
'workspace_schedule': {'id': 1, 'enabled': True, 'start_datetime': '2022-09-26T13:08:16.281604Z', 'interval_hours': 1, 'error_count': None, 'additional_email_options': [], 'emails_selected': ['[email protected]'], 'workspace': 1, 'schedule': 9, 'updated_at': '2022-05-13', 'created_at': '2022-05-13'}
}
Loading