diff --git a/src/backend/app/db/db_models.py b/src/backend/app/db/db_models.py index ceabf66ad..1737b12e1 100644 --- a/src/backend/app/db/db_models.py +++ b/src/backend/app/db/db_models.py @@ -536,8 +536,7 @@ class DbSubmissionPhotos(Base): project_id = cast( int, Column(Integer, ForeignKey("projects.id"), name="project_id", index=True) ) - task_id = cast( - int, Column(Integer, ForeignKey("tasks.id"), name="task_id", index=True) - ) + # Note this is not a DbTask, but an ODK task_id + task_id = cast(int, Column(Integer)) submission_id = cast(str, Column(String)) s3_path = cast(str, Column(String)) diff --git a/src/backend/migrations/007-remove-xform-table.sql b/src/backend/migrations/007-remove-xform-table.sql index 5cd75299b..e3b8f95c2 100644 --- a/src/backend/migrations/007-remove-xform-table.sql +++ b/src/backend/migrations/007-remove-xform-table.sql @@ -21,17 +21,6 @@ BEGIN ADD CONSTRAINT fk_project_id FOREIGN KEY (project_id) REFERENCES public.projects (id); END IF; - - IF NOT EXISTS ( - SELECT 1 FROM information_schema.table_constraints - WHERE constraint_name = 'fk_tasks' - AND table_name = 'submission_photos' - ) THEN - ALTER TABLE ONLY public.submission_photos - ADD CONSTRAINT fk_tasks FOREIGN KEY ( - task_id, project_id - ) REFERENCES public.tasks (id, project_id); - END IF; END $$; -- Update public.projects table diff --git a/src/backend/migrations/init/fmtm_base_schema.sql b/src/backend/migrations/init/fmtm_base_schema.sql index 17f20b4d3..839b7cd5f 100644 --- a/src/backend/migrations/init/fmtm_base_schema.sql +++ b/src/backend/migrations/init/fmtm_base_schema.sql @@ -393,6 +393,7 @@ ALTER SEQUENCE public.xlsforms_id_seq OWNED BY public.xlsforms.id; CREATE TABLE public.submission_photos ( id integer NOT NULL, project_id integer NOT NULL, + -- Note this is not public.tasks, but an ODK task_id task_id integer NOT NULL, submission_id character varying NOT NULL, s3_path character varying NOT NULL @@ -600,11 +601,6 @@ ADD CONSTRAINT fk_project_id FOREIGN KEY ( project_id ) REFERENCES public.projects (id); -ALTER TABLE ONLY public.submission_photos -ADD CONSTRAINT fk_tasks FOREIGN KEY ( - task_id, project_id -) REFERENCES public.tasks (id, project_id); - -- Finalise REVOKE USAGE ON SCHEMA public FROM public;