Skip to content

Commit 632167a

Browse files
committed
Migration to change the source check constraint
We need to allow `source` `manual_report` to be used in the same way as `service`. Jira-Issue: MAV-3404
1 parent 7ffd629 commit 632167a

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class ChangeVaccinationRecordsSourceCheckConstraint < ActiveRecord::Migration[8.1]
2+
def up
3+
remove_check_constraint :vaccination_records, name: "source_check"
4+
5+
add_check_constraint :vaccination_records,
6+
"(session_id IS NULL AND source != 0 AND source != 5) OR " \
7+
"(session_id IS NOT NULL AND (source = 0 OR source = 5))",
8+
name: "source_check",
9+
validate: false
10+
end
11+
12+
def down
13+
remove_check_constraint :vaccination_records, name: "source_check"
14+
15+
add_check_constraint :vaccination_records,
16+
"(session_id IS NULL AND source != 0) OR " \
17+
"(session_id IS NOT NULL AND source = 0)",
18+
name: "source_check",
19+
validate: false
20+
end
21+
end

db/schema.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.1].define(version: 2026_02_09_161431) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_02_17_111256) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616
enable_extension "pg_trgm"
@@ -994,9 +994,10 @@
994994
t.index ["supplied_by_user_id"], name: "index_vaccination_records_on_supplied_by_user_id"
995995
t.index ["uuid"], name: "index_vaccination_records_on_uuid", unique: true
996996
t.index ["vaccine_id"], name: "index_vaccination_records_on_vaccine_id"
997-
t.check_constraint "session_id IS NULL AND source <> 0 OR session_id IS NOT NULL AND source = 0", name: "source_check"
998997
end
999998

999+
add_check_constraint "vaccination_records", "session_id IS NULL AND source <> 0 AND source <> 5 OR session_id IS NOT NULL AND (source = 0 OR source = 5)", name: "source_check", validate: false
1000+
10001001
create_table "vaccines", force: :cascade do |t|
10011002
t.text "brand", null: false
10021003
t.boolean "contains_gelatine", null: false

0 commit comments

Comments
 (0)