Browse Source

add indexes and fk constraints to org relations

pull/1019/head
Phil Lee 4 years ago
parent
commit
c320d67e06
  1. 10
      db/migrate/20221122130928_add_org_relation_indexes.rb
  2. 7
      db/schema.rb

10
db/migrate/20221122130928_add_org_relation_indexes.rb

@ -0,0 +1,10 @@
class AddOrgRelationIndexes < ActiveRecord::Migration[7.0]
def change
add_index :organisation_relationships, :child_organisation_id
add_index :organisation_relationships, :parent_organisation_id
add_index :organisation_relationships, %i[parent_organisation_id child_organisation_id], unique: true, name: "index_org_rel_parent_child_uniq"
add_foreign_key :organisation_relationships, :organisations, column: :parent_organisation_id
add_foreign_key :organisation_relationships, :organisations, column: :child_organisation_id
end
end

7
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: 2022_11_22_122311) do
ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -286,6 +286,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_122311) do
t.integer "parent_organisation_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["child_organisation_id"], name: "index_organisation_relationships_on_child_organisation_id"
t.index ["parent_organisation_id", "child_organisation_id"], name: "index_org_rel_parent_child_uniq", unique: true
t.index ["parent_organisation_id"], name: "index_organisation_relationships_on_parent_organisation_id"
end
create_table "organisation_rent_periods", force: :cascade do |t|
@ -476,6 +479,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_122311) do
add_foreign_key "lettings_logs", "organisations", column: "owning_organisation_id", on_delete: :cascade
add_foreign_key "lettings_logs", "schemes"
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 "sales_logs", "organisations", column: "owning_organisation_id", on_delete: :cascade
add_foreign_key "schemes", "organisations", column: "managing_organisation_id"
add_foreign_key "schemes", "organisations", column: "owning_organisation_id", on_delete: :cascade

Loading…
Cancel
Save