Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create TeamProgramme #1857

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/models/team_programme.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: team_programmes
#
# id :bigint not null, primary key
# programme_id :bigint not null
# team_id :bigint not null
#
# Indexes
#
# index_team_programmes_on_programme_id (programme_id)
# index_team_programmes_on_team_id (team_id)
# index_team_programmes_on_team_id_and_programme_id (team_id,programme_id) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (programme_id => programmes.id)
# fk_rails_... (team_id => teams.id)
#
class TeamProgramme < ApplicationRecord
audited

belongs_to :programme
belongs_to :team
end
13 changes: 13 additions & 0 deletions db/migrate/20240927083819_create_team_programmes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class CreateTeamProgrammes < ActiveRecord::Migration[7.2]
def change
# rubocop:disable Rails/CreateTableWithTimestamps
create_table :team_programmes do |t|
t.references :team, foreign_key: true, null: false
t.references :programme, foreign_key: true, null: false
t.index %i[team_id programme_id], unique: true
end
# rubocop:enable Rails/CreateTableWithTimestamps
end
end
10 changes: 10 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@
t.index ["team_id"], name: "index_sessions_on_team_id"
end

create_table "team_programmes", force: :cascade do |t|
t.bigint "team_id", null: false
t.bigint "programme_id", null: false
t.index ["programme_id"], name: "index_team_programmes_on_programme_id"
t.index ["team_id", "programme_id"], name: "index_team_programmes_on_team_id_and_programme_id", unique: true
t.index ["team_id"], name: "index_team_programmes_on_team_id"
end

create_table "teams", force: :cascade do |t|
t.text "name", null: false
t.datetime "created_at", null: false
Expand Down Expand Up @@ -649,6 +657,8 @@
add_foreign_key "programmes_sessions", "sessions"
add_foreign_key "session_dates", "sessions"
add_foreign_key "sessions", "teams"
add_foreign_key "team_programmes", "programmes"
add_foreign_key "team_programmes", "teams"
add_foreign_key "triage", "patient_sessions"
add_foreign_key "triage", "programmes"
add_foreign_key "triage", "users", column: "performed_by_user_id"
Expand Down
Binary file modified erd.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions lib/tasks/programmes.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace :programmes do

programme = Programme.create!(team:, type:, vaccines:)

TeamProgramme.create!(team:, programme:)

puts "New #{programme.name} programme with ID #{programme.id} created."
puts "Vaccines: #{vaccines.map(&:brand).join(", ")}"
end
Expand Down
27 changes: 27 additions & 0 deletions spec/factories/team_programmes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: team_programmes
#
# id :bigint not null, primary key
# programme_id :bigint not null
# team_id :bigint not null
#
# Indexes
#
# index_team_programmes_on_programme_id (programme_id)
# index_team_programmes_on_team_id (team_id)
# index_team_programmes_on_team_id_and_programme_id (team_id,programme_id) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (programme_id => programmes.id)
# fk_rails_... (team_id => teams.id)
#
FactoryBot.define do
factory :team_programme do
team
programme
end
end
26 changes: 26 additions & 0 deletions spec/models/team_programme_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: team_programmes
#
# id :bigint not null, primary key
# programme_id :bigint not null
# team_id :bigint not null
#
# Indexes
#
# index_team_programmes_on_programme_id (programme_id)
# index_team_programmes_on_team_id (team_id)
# index_team_programmes_on_team_id_and_programme_id (team_id,programme_id) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (programme_id => programmes.id)
# fk_rails_... (team_id => teams.id)
#
describe TeamProgramme do
subject(:team_programme) { build(:team_programme) }

it { should be_valid }
end
Loading