Skip to content
This repository was archived by the owner on Mar 28, 2024. It is now read-only.

Commit 87134f9

Browse files
committed
Add foreign keys
1 parent 05b24e5 commit 87134f9

12 files changed

Lines changed: 75 additions & 1 deletion

app/models/email_address.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
# updated_at :datetime not null
99
# teacher_id :integer
1010
#
11+
# Foreign Keys
12+
#
13+
# fk_rails_... (teacher_id => teachers.id)
14+
#
1115
class EmailAddress < ApplicationRecord
1216
end

app/models/induction_period.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@
1111
# induction_programme_id :integer not null
1212
# mentorship_id :integer not null
1313
#
14+
# Foreign Keys
15+
#
16+
# fk_rails_... (appropriate_body_id => appropriate_bodies.id)
17+
# fk_rails_... (induction_programme_id => induction_programmes.id)
18+
# fk_rails_... (mentorship_id => mentorships.id)
19+
#
1420
class InductionPeriod < ApplicationRecord
1521
end

app/models/mentorship.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@
88
# teacher_id :integer
99
# tenureship_id :integer
1010
#
11+
# Foreign Keys
12+
#
13+
# fk_rails_... (teacher_id => teachers.id)
14+
# fk_rails_... (tenureship_id => tenureships.id)
15+
#
1116
class Mentorship < ApplicationRecord
1217
end

app/models/school.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
# updated_at :datetime not null
99
# parent_id :integer
1010
#
11+
# Foreign Keys
12+
#
13+
# fk_rails_... (parent_id => schools.id)
14+
#
1115
class School < ApplicationRecord
1216
end

app/models/tenureship.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@
1010
# school_id :integer
1111
# teacher_id :integer
1212
#
13+
# Foreign Keys
14+
#
15+
# fk_rails_... (school_id => schools.id)
16+
# fk_rails_... (teacher_id => teachers.id)
17+
#
1318
class Tenureship < ApplicationRecord
1419
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class AddRelationships < ActiveRecord::Migration[7.0]
2+
def change
3+
add_foreign_key :email_addresses, :teachers
4+
5+
add_foreign_key :mentorships, :teachers
6+
add_foreign_key :mentorships, :tenureships
7+
8+
add_foreign_key :schools, :schools, column: :parent_id, primary_key: :id
9+
10+
add_foreign_key :tenureships, :teachers
11+
add_foreign_key :tenureships, :schools
12+
13+
add_foreign_key :induction_periods, :mentorships
14+
add_foreign_key :induction_periods, :appropriate_bodies
15+
add_foreign_key :induction_periods, :induction_programmes
16+
end
17+
end

db/schema.rb

Lines changed: 10 additions & 1 deletion
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[7.0].define(version: 2023_08_11_092928) do
13+
ActiveRecord::Schema[7.0].define(version: 2023_08_11_093018) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -72,4 +72,13 @@
7272
t.datetime "updated_at", null: false
7373
end
7474

75+
add_foreign_key "email_addresses", "teachers"
76+
add_foreign_key "induction_periods", "appropriate_bodies"
77+
add_foreign_key "induction_periods", "induction_programmes"
78+
add_foreign_key "induction_periods", "mentorships"
79+
add_foreign_key "mentorships", "teachers"
80+
add_foreign_key "mentorships", "tenureships"
81+
add_foreign_key "schools", "schools", column: "parent_id"
82+
add_foreign_key "tenureships", "schools"
83+
add_foreign_key "tenureships", "teachers"
7584
end

spec/models/email_address_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
# updated_at :datetime not null
99
# teacher_id :integer
1010
#
11+
# Foreign Keys
12+
#
13+
# fk_rails_... (teacher_id => teachers.id)
14+
#
1115
require 'rails_helper'
1216

1317
RSpec.describe EmailAddress, type: :model do

spec/models/induction_period_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
# induction_programme_id :integer not null
1212
# mentorship_id :integer not null
1313
#
14+
# Foreign Keys
15+
#
16+
# fk_rails_... (appropriate_body_id => appropriate_bodies.id)
17+
# fk_rails_... (induction_programme_id => induction_programmes.id)
18+
# fk_rails_... (mentorship_id => mentorships.id)
19+
#
1420
require 'rails_helper'
1521

1622
RSpec.describe InductionPeriod, type: :model do

spec/models/mentorship_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
# teacher_id :integer
99
# tenureship_id :integer
1010
#
11+
# Foreign Keys
12+
#
13+
# fk_rails_... (teacher_id => teachers.id)
14+
# fk_rails_... (tenureship_id => tenureships.id)
15+
#
1116
require 'rails_helper'
1217

1318
RSpec.describe Mentorship, type: :model do

0 commit comments

Comments
 (0)