timgremore commited on
Commit
a0c85a9
1 Parent(s): e415915

fix: Reference chunks table not users in constraint

Browse files
priv/repo/migrations/20240311203957_fix_code_feedbacks_transcription_chunk_id_foreign_key_reference.exs ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ defmodule Medicode.Repo.Migrations.FixCodeFeedbacksTranscriptionChunkIdForeignKeyReference do
2
+ use Ecto.Migration
3
+
4
+ def up do
5
+ drop constraint("code_feedbacks", "code_feedbacks_transcription_chunk_id_fkey")
6
+
7
+ alter table("code_feedbacks") do
8
+ remove :transcription_chunk_id
9
+ end
10
+
11
+ flush()
12
+
13
+ alter table(:code_feedbacks) do
14
+ # TODO: This shouldn't be nullable
15
+ add(
16
+ :transcription_chunk_id,
17
+ references(:transcription_chunks, type: :binary_id, on_delete: :delete_all),
18
+ null: true
19
+ )
20
+ end
21
+ end
22
+
23
+ def down do
24
+ drop constraint("code_feedbacks", "code_feedbacks_transcription_chunk_id_fkey")
25
+
26
+ alter table("code_feedbacks") do
27
+ remove :transcription_chunk_id
28
+ end
29
+
30
+ flush()
31
+
32
+ alter table(:code_feedbacks) do
33
+ add(
34
+ :transcription_chunk_id,
35
+ references(:users, type: :binary_id, on_delete: :delete_all),
36
+ null: true
37
+ )
38
+ end
39
+ end
40
+ end