Browse Source

feat: add absorbing_organisation relationship to orgs

pull/1789/head
natdeanlewissoftwire 3 years ago
parent
commit
a9ce896d81
  1. 3
      app/models/organisation.rb
  2. 5
      db/migrate/20230719150610_add_absorbing_organisation_id_to_organisations.rb
  3. 31
      db/schema.rb

3
app/models/organisation.rb

@ -18,6 +18,9 @@ class Organisation < ApplicationRecord
has_many :managing_agent_relationships, foreign_key: :parent_organisation_id, class_name: "OrganisationRelationship"
has_many :managing_agents, through: :managing_agent_relationships, source: :child_organisation
belongs_to :absorbing_organisation, class_name: "Organisation", optional: true
has_many :absorbed_organisations, class_name: "Organisation", foreign_key: "absorbing_organisation_id"
def affiliated_stock_owners
ids = []

5
db/migrate/20230719150610_add_absorbing_organisation_id_to_organisations.rb

@ -0,0 +1,5 @@
class AddAbsorbingOrganisationIdToOrganisations < ActiveRecord::Migration[7.0]
def change
add_reference :organisations, :absorbing_organisation, null: true, foreign_key: { to_table: :organisations }
end
end

31
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
ActiveRecord::Schema[7.0].define(version: 2023_07_19_150610) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -191,14 +191,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.integer "hb"
t.integer "hbrentshortfall"
t.integer "property_relet"
t.datetime "mrcdate", precision: nil
t.datetime "mrcdate"
t.integer "incref"
t.datetime "startdate", precision: nil
t.datetime "startdate"
t.integer "armedforces"
t.integer "first_time_property_let_as_social_housing"
t.integer "unitletas"
t.integer "builtype"
t.datetime "voiddate", precision: nil
t.datetime "voiddate"
t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id"
t.integer "renttype"
@ -346,7 +346,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.string "old_id"
t.string "old_visible_id"
t.string "mobility_type"
t.datetime "startdate", precision: nil
t.datetime "startdate"
t.string "location_admin_district"
t.boolean "confirmed"
t.index ["old_id"], name: "index_locations_on_old_id", unique: true
@ -432,6 +432,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.integer "unspecified_units"
t.string "old_org_id"
t.string "old_visible_id"
t.bigint "absorbing_organisation_id"
t.index ["absorbing_organisation_id"], name: "index_organisations_on_absorbing_organisation_id"
t.index ["old_visible_id"], name: "index_organisations_on_old_visible_id", unique: true
end
@ -517,7 +519,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.integer "stairbought"
t.integer "stairowned"
t.decimal "mrent", precision: 10, scale: 2
t.datetime "exdate", precision: nil
t.datetime "exdate"
t.integer "exday"
t.integer "exmonth"
t.integer "exyear"
@ -553,7 +555,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.integer "wchair"
t.integer "income2_value_check"
t.integer "armedforcesspouse"
t.datetime "hodate", precision: nil
t.datetime "hodate"
t.integer "hoday"
t.integer "homonth"
t.integer "hoyear"
@ -606,9 +608,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.integer "discounted_sale_value_check"
t.integer "student_not_child_value_check"
t.integer "percentage_discount_value_check"
t.integer "combined_income_value_check"
t.integer "buyer_livein_value_check"
t.integer "status_cache", default: 0, null: false
t.integer "combined_income_value_check"
t.datetime "discarded_at"
t.integer "stairowned_value_check"
t.integer "creation_method", default: 1
@ -661,8 +663,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.string "name"
t.bigint "organisation_id"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at", precision: nil
t.datetime "last_sign_in_at", precision: nil
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "role"
@ -670,7 +672,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.string "phone"
t.integer "failed_attempts", default: 0
t.string "unlock_token"
t.datetime "locked_at", precision: nil
t.datetime "locked_at"
t.boolean "is_dpo", default: false
t.boolean "is_key_contact", default: false
t.integer "second_factor_attempts_count", default: 0
@ -678,12 +680,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.string "encrypted_otp_secret_key_iv"
t.string "encrypted_otp_secret_key_salt"
t.string "direct_otp"
t.datetime "direct_otp_sent_at", precision: nil
t.datetime "direct_otp_sent_at"
t.datetime "totp_timestamp", precision: nil
t.boolean "active", default: true
t.string "confirmation_token"
t.datetime "confirmed_at", precision: nil
t.datetime "confirmation_sent_at", precision: nil
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "unconfirmed_email"
t.boolean "initial_confirmation_sent"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
@ -713,6 +715,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
add_foreign_key "locations", "schemes"
add_foreign_key "organisation_relationships", "organisations", column: "child_organisation_id"
add_foreign_key "organisation_relationships", "organisations", column: "parent_organisation_id"
add_foreign_key "organisations", "organisations", column: "absorbing_organisation_id"
add_foreign_key "sales_logs", "organisations", column: "owning_organisation_id", on_delete: :cascade
add_foreign_key "schemes", "organisations", column: "owning_organisation_id", on_delete: :cascade
add_foreign_key "users", "organisations", on_delete: :cascade

Loading…
Cancel
Save