Move all to SOA and tag time entries to join table as this should be how it works and also UNNEST doesn't support nested arrays

This commit is contained in:
2024-07-27 20:51:14 +01:00
parent 6f7db97ab6
commit 71f9ed3312
3 changed files with 58 additions and 42 deletions
@@ -0,0 +1,16 @@
-- Create a new join table to associate time_entries with tags
CREATE TABLE public.time_entry_tags (
time_entry_id bigint not null references public.time_entries(id) on delete cascade,
tag_id bigint not null references public.tags(id) on delete cascade,
primary key (time_entry_id, tag_id)
);
-- Insert data into the new join table based on the existing time_entries and tags data
INSERT INTO public.time_entry_tags (time_entry_id, tag_id)
SELECT time_entries.id, UNNEST(time_entries.tag_ids) AS tag_id
FROM public.time_entries
WHERE time_entries.tag_ids IS NOT NULL;
-- Remove the tag_ids array column from the time_entries table
ALTER TABLE public.time_entries
DROP COLUMN tag_ids;