diff --git a/app/models/municipality.rb b/app/models/municipality.rb new file mode 100644 index 0000000..0fc63dc --- /dev/null +++ b/app/models/municipality.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Municipality < ApplicationRecord + has_many :municipality_areas, dependent: :destroy +end diff --git a/app/models/municipality_area.rb b/app/models/municipality_area.rb new file mode 100644 index 0000000..c2c5b3b --- /dev/null +++ b/app/models/municipality_area.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class MunicipalityArea < ApplicationRecord + belongs_to :municipality +end diff --git a/db/migrate/20230214152809_create_municipalities.rb b/db/migrate/20230214152809_create_municipalities.rb new file mode 100644 index 0000000..55c5cb7 --- /dev/null +++ b/db/migrate/20230214152809_create_municipalities.rb @@ -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 diff --git a/db/migrate/20230214160225_create_municipality_areas.rb b/db/migrate/20230214160225_create_municipality_areas.rb new file mode 100644 index 0000000..b0f367d --- /dev/null +++ b/db/migrate/20230214160225_create_municipality_areas.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index f2677b8..7d5b38b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,21 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_02_14_134011) do +ActiveRecord::Schema[7.0].define(version: 2023_02_14_160225) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "postgis" + create_table "municipalities", force: :cascade do |t| + t.string "name", null: false + end + + create_table "municipality_areas", force: :cascade do |t| + t.bigint "municipality_id", null: false + t.geometry "area", limit: {:srid=>3857, :type=>"st_polygon"}, null: false + t.index ["area"], name: "index_municipality_areas_on_area", using: :gist + t.index ["municipality_id"], name: "index_municipality_areas_on_municipality_id" + end + + add_foreign_key "municipality_areas", "municipalities" end