Skip to content

Commit 61bfbb3

Browse files
murugaplthomasleese
authored andcommitted
Migration to create ImportantNotice table
To support the dismissal feature of ImportantNotices, we need to store notices in the db ratehr than calcualte them on the fly.
1 parent 2ad41c4 commit 61bfbb3

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
class CreateImportantNotices < ActiveRecord::Migration[8.0]
4+
def change
5+
create_table :important_notices do |t|
6+
t.references :patient, foreign_key: true, null: false
7+
t.references :team, foreign_key: true, null: false
8+
t.references :vaccination_record, foreign_key: true, null: true
9+
t.references :dismissed_by_user,
10+
foreign_key: {
11+
to_table: :users
12+
},
13+
null: true
14+
t.integer :type, null: false
15+
t.datetime :recorded_at, null: false
16+
t.datetime :dismissed_at
17+
18+
t.timestamps
19+
end
20+
21+
add_index :important_notices,
22+
%i[patient_id type recorded_at team_id],
23+
unique: true,
24+
name: "index_notices_on_patient_and_type_and_recorded_at_and_team"
25+
end
26+
end

db/schema.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,23 @@
387387
t.index ["immunisation_import_id", "vaccination_record_id"], name: "idx_on_immunisation_import_id_vaccination_record_id_588e859772", unique: true
388388
end
389389

390+
create_table "important_notices", force: :cascade do |t|
391+
t.datetime "created_at", null: false
392+
t.datetime "dismissed_at"
393+
t.bigint "dismissed_by_user_id"
394+
t.bigint "patient_id", null: false
395+
t.datetime "recorded_at", null: false
396+
t.bigint "team_id", null: false
397+
t.integer "type", null: false
398+
t.datetime "updated_at", null: false
399+
t.bigint "vaccination_record_id"
400+
t.index ["dismissed_by_user_id"], name: "index_important_notices_on_dismissed_by_user_id"
401+
t.index ["patient_id", "type", "recorded_at", "team_id"], name: "index_notices_on_patient_and_type_and_recorded_at_and_team", unique: true
402+
t.index ["patient_id"], name: "index_important_notices_on_patient_id"
403+
t.index ["team_id"], name: "index_important_notices_on_team_id"
404+
t.index ["vaccination_record_id"], name: "index_important_notices_on_vaccination_record_id"
405+
end
406+
390407
create_table "local_authorities", id: false, force: :cascade do |t|
391408
t.datetime "created_at", null: false
392409
t.date "end_date"
@@ -1013,6 +1030,10 @@
10131030
add_foreign_key "immunisation_imports_sessions", "sessions", on_delete: :cascade
10141031
add_foreign_key "immunisation_imports_vaccination_records", "immunisation_imports", on_delete: :cascade
10151032
add_foreign_key "immunisation_imports_vaccination_records", "vaccination_records", on_delete: :cascade
1033+
add_foreign_key "important_notices", "patients"
1034+
add_foreign_key "important_notices", "teams"
1035+
add_foreign_key "important_notices", "users", column: "dismissed_by_user_id"
1036+
add_foreign_key "important_notices", "vaccination_records"
10161037
add_foreign_key "location_programme_year_groups", "location_year_groups", on_delete: :cascade
10171038
add_foreign_key "location_programme_year_groups", "programmes", on_delete: :cascade
10181039
add_foreign_key "location_year_groups", "locations", on_delete: :cascade

0 commit comments

Comments
 (0)