Skip to content

Commit

Permalink
Migrate data to local_authority_application_types table
Browse files Browse the repository at this point in the history
  • Loading branch information
EGiataganas committed Feb 24, 2025
1 parent 6f5dfb8 commit b895842
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/application_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class ApplicationType < ApplicationRecord
belongs_to :legislation, optional: true
has_many :planning_applications, -> { kept }, dependent: :restrict_with_exception

has_many :local_authority_application_types, dependent: :destroy
has_many :local_authorities, through: :local_authority_application_types

accepts_nested_attributes_for :legislation, :document_tags

scope :not_retired, -> { where.not(status: "retired") }
Expand Down
3 changes: 3 additions & 0 deletions app/models/local_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class LocalAuthority < ApplicationRecord

has_many :neighbour_responses, through: :consultations

has_many :local_authority_application_types, dependent: :destroy
has_many :application_types, through: :local_authority_application_types

with_options presence: true do
validates :council_code, :subdomain
validates :short_name, :council_name
Expand Down
6 changes: 6 additions & 0 deletions app/models/local_authority_application_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class LocalAuthorityApplicationType < ApplicationRecord
belongs_to :local_authority
belongs_to :application_type
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class MigrateLocalAuthorityApplicationType < ActiveRecord::Migration[7.2]
def change
PlanningApplication.find_each do |planning_application|
LocalAuthorityApplicationType.create!(
local_authority_id: planning_application.local_authority_id,
application_type_id: planning_application.application_type_id
)
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2025_02_24_101659) do
ActiveRecord::Schema[7.2].define(version: 2025_02_24_104514) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gin"
enable_extension "plpgsql"
Expand Down

0 comments on commit b895842

Please sign in to comment.