Skip to content

Commit

Permalink
Municipalities with many areas
Browse files Browse the repository at this point in the history
Data structure to save Japanese municipalities and the associated areas.
  • Loading branch information
arkirchner committed Feb 17, 2023
1 parent 4022434 commit 3e40b1c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/municipality.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Municipality < ApplicationRecord
has_many :municipality_areas, dependent: :destroy
end
5 changes: 5 additions & 0 deletions app/models/municipality_area.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class MunicipalityArea < ApplicationRecord
belongs_to :municipality
end
9 changes: 9 additions & 0 deletions db/migrate/20230214152809_create_municipalities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class CreateMunicipalities < ActiveRecord::Migration[7.0]
def change
create_table :municipalities do |t|
t.string :name, null: false
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20230214160225_create_municipality_areas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class CreateMunicipalityAreas < ActiveRecord::Migration[7.0]
def change
create_table :municipality_areas do |t|
t.references :municipality, null: false, foreign_key: true
t.st_polygon :area, null: false, srid: 3857, index: { using: :gist }
end
end
end
14 changes: 13 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e40b1c

Please sign in to comment.