us_geo 1.0.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +82 -0
  3. data/MIT_LICENSE.txt +21 -0
  4. data/README.md +77 -60
  5. data/UPDATING_TO_VERSION_2.md +172 -0
  6. data/VERSION +1 -0
  7. data/db/migrate/20190221054200_create_regions.rb +4 -2
  8. data/db/migrate/20190221054300_create_divisions.rb +4 -2
  9. data/db/migrate/20190221054400_create_states.rb +4 -2
  10. data/db/migrate/20190221054500_create_combined_statistical_areas.rb +4 -2
  11. data/db/migrate/20190221054600_create_core_based_statistical_areas.rb +4 -2
  12. data/db/migrate/20190221054650_create_metropolitan_divisions.rb +4 -2
  13. data/db/migrate/20190221054700_create_counties.rb +4 -3
  14. data/db/migrate/20190221054800_create_zctas.rb +4 -2
  15. data/db/migrate/20190221054900_create_zcta_counties.rb +4 -2
  16. data/db/migrate/20190221055000_create_urban_areas.rb +4 -2
  17. data/db/migrate/20190221055100_create_urban_area_counties.rb +4 -4
  18. data/db/migrate/20190221055200_create_zcta_urban_areas.rb +4 -4
  19. data/db/migrate/20190221060000_create_places.rb +4 -2
  20. data/db/migrate/20190221061000_create_place_counties.rb +4 -2
  21. data/db/migrate/20190221062000_create_zcta_places.rb +4 -4
  22. data/db/migrate/20190221063000_create_county_subdivisions.rb +4 -2
  23. data/db/migrate/20220722000000_allow_null_zcta_counties_demographics.rb +23 -0
  24. data/db/migrate/20220722000200_allow_null_zcta_places_demographics.rb +23 -0
  25. data/db/migrate/20230414000000_add_zcta_primary_place.rb +13 -0
  26. data/db/migrate/20230414000200_add_demographics_to_regions.rb +28 -0
  27. data/db/migrate/20230414000300_add_demographics_to_divisions.rb +28 -0
  28. data/db/migrate/20230414000400_add_demographics_to_states.rb +28 -0
  29. data/db/migrate/20230414000700_add_short_name_to_core_based_statistical_areas.rb +22 -0
  30. data/db/migrate/20230414000750_add_short_name_to_combined_statistical_areas.rb +22 -0
  31. data/db/migrate/20230414000800_create_zcta_mappings.rb +18 -0
  32. data/db/migrate/20230417000100_create_zcta_county_subdivisions.rb +22 -0
  33. data/db/migrate/20230417000200_add_unique_name_index_to_county_subdivisions.rb +26 -0
  34. data/db/migrate/20230417000250_add_zcta_primary_county_subdivision.rb +13 -0
  35. data/db/migrate/20230417000300_create_urban_area_county_subdivisions.rb +23 -0
  36. data/db/migrate/20230417000400_allow_null_urban_area_counties_demographics.rb +23 -0
  37. data/db/migrate/20230417000500_allow_null_zcta_urban_areas_demographics.rb +23 -0
  38. data/db/migrate/20230417000600_add_additional_time_zone_name_to_counties.rb +13 -0
  39. data/db/schema.rb +303 -0
  40. data/explorer_app/.gitattributes +7 -0
  41. data/explorer_app/.gitignore +34 -0
  42. data/explorer_app/Gemfile +38 -0
  43. data/explorer_app/Rakefile +6 -0
  44. data/explorer_app/app/assets/images/.keep +0 -0
  45. data/explorer_app/app/assets/stylesheets/application.css +1 -0
  46. data/explorer_app/app/controllers/application_controller.rb +64 -0
  47. data/explorer_app/app/controllers/combined_statistical_areas_controller.rb +12 -0
  48. data/explorer_app/app/controllers/concerns/.keep +0 -0
  49. data/explorer_app/app/controllers/core_based_statistical_areas_controller.rb +36 -0
  50. data/explorer_app/app/controllers/counties_controller.rb +22 -0
  51. data/explorer_app/app/controllers/county_subdivisions_controller.rb +23 -0
  52. data/explorer_app/app/controllers/divisions_controller.rb +27 -0
  53. data/explorer_app/app/controllers/home_controller.rb +6 -0
  54. data/explorer_app/app/controllers/metropolitan_divisions_controller.rb +27 -0
  55. data/explorer_app/app/controllers/places_controller.rb +23 -0
  56. data/explorer_app/app/controllers/regions_controller.rb +13 -0
  57. data/explorer_app/app/controllers/states_controller.rb +25 -0
  58. data/explorer_app/app/controllers/urban_areas_controller.rb +24 -0
  59. data/explorer_app/app/controllers/zctas_controller.rb +23 -0
  60. data/explorer_app/app/helpers/application_helper.rb +137 -0
  61. data/explorer_app/app/models/application_record.rb +3 -0
  62. data/explorer_app/app/models/concerns/.keep +0 -0
  63. data/explorer_app/app/views/combined_statistical_areas/_table.html.erb +18 -0
  64. data/explorer_app/app/views/combined_statistical_areas/index.html.erb +7 -0
  65. data/explorer_app/app/views/combined_statistical_areas/show.html.erb +52 -0
  66. data/explorer_app/app/views/core_based_statistical_areas/_table.html.erb +32 -0
  67. data/explorer_app/app/views/core_based_statistical_areas/index.html.erb +19 -0
  68. data/explorer_app/app/views/core_based_statistical_areas/show.html.erb +60 -0
  69. data/explorer_app/app/views/counties/_table.html.erb +64 -0
  70. data/explorer_app/app/views/counties/show.html.erb +96 -0
  71. data/explorer_app/app/views/county_subdivisions/_table.html.erb +48 -0
  72. data/explorer_app/app/views/county_subdivisions/show.html.erb +84 -0
  73. data/explorer_app/app/views/divisions/_table.html.erb +24 -0
  74. data/explorer_app/app/views/divisions/index.html.erb +3 -0
  75. data/explorer_app/app/views/divisions/show.html.erb +3 -0
  76. data/explorer_app/app/views/home/index.html.erb +23 -0
  77. data/explorer_app/app/views/layouts/application.html.erb +34 -0
  78. data/explorer_app/app/views/metropolitan_divisions/_table.html.erb +42 -0
  79. data/explorer_app/app/views/metropolitan_divisions/index.html.erb +8 -0
  80. data/explorer_app/app/views/metropolitan_divisions/show.html.erb +46 -0
  81. data/explorer_app/app/views/places/_table.html.erb +47 -0
  82. data/explorer_app/app/views/places/show.html.erb +92 -0
  83. data/explorer_app/app/views/regions/_table.html.erb +18 -0
  84. data/explorer_app/app/views/regions/index.html.erb +7 -0
  85. data/explorer_app/app/views/regions/show.html.erb +3 -0
  86. data/explorer_app/app/views/shared/_breadcrumbs.html.erb +13 -0
  87. data/explorer_app/app/views/shared/_demographics_cells.html.erb +5 -0
  88. data/explorer_app/app/views/shared/_demographics_headers.html.erb +5 -0
  89. data/explorer_app/app/views/states/_table.html.erb +31 -0
  90. data/explorer_app/app/views/states/index.html.erb +7 -0
  91. data/explorer_app/app/views/states/show.html.erb +54 -0
  92. data/explorer_app/app/views/urban_areas/_table.html.erb +45 -0
  93. data/explorer_app/app/views/urban_areas/index.html.erb +19 -0
  94. data/explorer_app/app/views/urban_areas/show.html.erb +68 -0
  95. data/explorer_app/app/views/zctas/_table.html.erb +60 -0
  96. data/explorer_app/app/views/zctas/show.html.erb +104 -0
  97. data/explorer_app/bin/bundle +109 -0
  98. data/explorer_app/bin/rails +4 -0
  99. data/explorer_app/bin/rake +4 -0
  100. data/explorer_app/bin/setup +33 -0
  101. data/explorer_app/config/application.rb +37 -0
  102. data/explorer_app/config/boot.rb +3 -0
  103. data/explorer_app/config/database.yml +13 -0
  104. data/explorer_app/config/environment.rb +5 -0
  105. data/explorer_app/config/environments/development.rb +59 -0
  106. data/explorer_app/config/initializers/filter_parameter_logging.rb +8 -0
  107. data/explorer_app/config/locales/en.yml +2 -0
  108. data/explorer_app/config/puma.rb +43 -0
  109. data/explorer_app/config/routes.rb +56 -0
  110. data/explorer_app/config.ru +6 -0
  111. data/explorer_app/db/seeds.rb +7 -0
  112. data/explorer_app/lib/assets/.keep +0 -0
  113. data/explorer_app/lib/tasks/.keep +0 -0
  114. data/explorer_app/log/.keep +0 -0
  115. data/explorer_app/public/404.html +67 -0
  116. data/explorer_app/public/422.html +67 -0
  117. data/explorer_app/public/500.html +66 -0
  118. data/explorer_app/public/apple-touch-icon-precomposed.png +0 -0
  119. data/explorer_app/public/apple-touch-icon.png +0 -0
  120. data/explorer_app/public/favicon.ico +0 -0
  121. data/explorer_app/public/robots.txt +1 -0
  122. data/explorer_app/tmp/.keep +0 -0
  123. data/explorer_app/tmp/pids/.keep +0 -0
  124. data/lib/tasks/us_geo/us_geo.rake +44 -3
  125. data/lib/us_geo/area.rb +44 -0
  126. data/lib/us_geo/base_record.rb +22 -16
  127. data/lib/us_geo/combined_statistical_area.rb +18 -8
  128. data/lib/us_geo/core_based_statistical_area.rb +24 -12
  129. data/lib/us_geo/county.rb +67 -16
  130. data/lib/us_geo/county_subdivision.rb +43 -7
  131. data/lib/us_geo/division.rb +17 -7
  132. data/lib/us_geo/metropolitan_area.rb +1 -5
  133. data/lib/us_geo/metropolitan_division.rb +17 -9
  134. data/lib/us_geo/micropolitan_area.rb +1 -5
  135. data/lib/us_geo/place.rb +61 -11
  136. data/lib/us_geo/place_county.rb +1 -4
  137. data/lib/us_geo/population.rb +26 -0
  138. data/lib/us_geo/region.rb +18 -8
  139. data/lib/us_geo/state.rb +32 -11
  140. data/lib/us_geo/urban_area.rb +46 -16
  141. data/lib/us_geo/urban_area_county.rb +4 -21
  142. data/lib/us_geo/urban_area_county_subdivision.rb +51 -0
  143. data/lib/us_geo/urban_cluster.rb +1 -5
  144. data/lib/us_geo/urbanized_area.rb +1 -5
  145. data/lib/us_geo/version.rb +1 -1
  146. data/lib/us_geo/zcta.rb +90 -13
  147. data/lib/us_geo/zcta_county.rb +5 -22
  148. data/lib/us_geo/zcta_county_subdivision.rb +51 -0
  149. data/lib/us_geo/zcta_mapping.rb +35 -0
  150. data/lib/us_geo/zcta_place.rb +5 -12
  151. data/lib/us_geo/zcta_urban_area.rb +3 -20
  152. data/lib/us_geo.rb +34 -31
  153. data/us_geo.gemspec +36 -0
  154. metadata +125 -129
  155. data/Gemfile +0 -5
  156. data/Gemfile.lock +0 -75
  157. data/Rakefile +0 -18
  158. data/db/migrate/20190221054490_create_designated_market_areas.rb +0 -16
  159. data/lib/us_geo/demographics.rb +0 -25
  160. data/lib/us_geo/designated_market_area.rb +0 -30
  161. data/spec/spec_helper.rb +0 -22
  162. data/spec/us_geo/base_record_spec.rb +0 -67
  163. data/spec/us_geo/combined_statistical_area_spec.rb +0 -33
  164. data/spec/us_geo/core_based_statistical_area_spec.rb +0 -56
  165. data/spec/us_geo/county_spec.rb +0 -131
  166. data/spec/us_geo/county_subdivision_spec.rb +0 -37
  167. data/spec/us_geo/demographics_spec.rb +0 -19
  168. data/spec/us_geo/designated_market_area_spec.rb +0 -29
  169. data/spec/us_geo/division_spec.rb +0 -37
  170. data/spec/us_geo/metropolitan_division_spec.rb +0 -41
  171. data/spec/us_geo/place_county_spec.rb +0 -39
  172. data/spec/us_geo/place_spec.rb +0 -71
  173. data/spec/us_geo/region_spec.rb +0 -36
  174. data/spec/us_geo/state_spec.rb +0 -70
  175. data/spec/us_geo/urban_area_county_spec.rb +0 -82
  176. data/spec/us_geo/urban_area_spec.rb +0 -98
  177. data/spec/us_geo/zcta_county_spec.rb +0 -82
  178. data/spec/us_geo/zcta_place_spec.rb +0 -82
  179. data/spec/us_geo/zcta_spec.rb +0 -99
  180. data/spec/us_geo/zcta_urban_area_spec.rb +0 -82
@@ -1,6 +1,9 @@
1
- class CreateZctaCounties < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateZctaCounties < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_zcta_counties)
6
+
4
7
  create_table :us_geo_zcta_counties do |t|
5
8
  t.string :zipcode, limit: 5, null: false
6
9
  t.string :county_geoid, limit: 5, null: false, index: true
@@ -18,5 +21,4 @@ class CreateZctaCounties < ActiveRecord::Migration[5.0]
18
21
  def down
19
22
  drop_table :us_geo_zcta_counties
20
23
  end
21
-
22
24
  end
@@ -1,6 +1,9 @@
1
- class CreateUrbanAreas < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateUrbanAreas < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_urban_areas)
6
+
4
7
  create_table :us_geo_urban_areas, id: false do |t|
5
8
  t.string :geoid, primary_key: true, null: false, limit: 5
6
9
  t.string :name, null: false, limit: 90, index: {unique: true}
@@ -21,5 +24,4 @@ class CreateUrbanAreas < ActiveRecord::Migration[5.0]
21
24
  def down
22
25
  drop_table :us_geo_urban_areas
23
26
  end
24
-
25
27
  end
@@ -1,13 +1,14 @@
1
- class CreateUrbanAreaCounties < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateUrbanAreaCounties < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_urban_area_counties)
6
+
4
7
  create_table :us_geo_urban_area_counties do |t|
5
8
  t.string :urban_area_geoid, limit: 5, null: false
6
9
  t.string :county_geoid, limit: 5, null: false, index: true
7
10
  t.float :land_area, null: false
8
11
  t.float :water_area, null: false
9
- t.integer :population, null: false
10
- t.integer :housing_units, null: false
11
12
  t.datetime :updated_at, null: false
12
13
  t.integer :status, null: false, default: 0, limit: 1
13
14
  end
@@ -18,5 +19,4 @@ class CreateUrbanAreaCounties < ActiveRecord::Migration[5.0]
18
19
  def down
19
20
  drop_table :us_geo_urban_area_counties
20
21
  end
21
-
22
22
  end
@@ -1,13 +1,14 @@
1
- class CreateZctaUrbanAreas < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateZctaUrbanAreas < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_zcta_urban_areas)
6
+
4
7
  create_table :us_geo_zcta_urban_areas do |t|
5
8
  t.string :zipcode, limit: 5, null: false, index: true
6
9
  t.string :urban_area_geoid, limit: 5, null: false
7
10
  t.float :land_area, null: false
8
11
  t.float :water_area, null: false
9
- t.integer :population, null: false
10
- t.integer :housing_units, null: false
11
12
  t.datetime :updated_at, null: false
12
13
  t.integer :status, null: false, default: 0, limit: 1
13
14
  end
@@ -18,5 +19,4 @@ class CreateZctaUrbanAreas < ActiveRecord::Migration[5.0]
18
19
  def down
19
20
  drop_table :us_geo_zcta_urban_areas
20
21
  end
21
-
22
22
  end
@@ -1,6 +1,9 @@
1
- class CreatePlaces < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreatePlaces < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_places)
6
+
4
7
  create_table :us_geo_places, id: false do |t|
5
8
  t.string :geoid, primary_key: true, limit: 7, null: false
6
9
  t.integer :gnis_id, null: false, index: true
@@ -24,5 +27,4 @@ class CreatePlaces < ActiveRecord::Migration[5.0]
24
27
  def down
25
28
  drop_table :us_geo_places
26
29
  end
27
-
28
30
  end
@@ -1,6 +1,9 @@
1
- class CreatePlaceCounties < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreatePlaceCounties < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_place_counties)
6
+
4
7
  create_table :us_geo_place_counties do |t|
5
8
  t.string :place_geoid, limit: 7, null: false
6
9
  t.string :county_geoid, limit: 5, null: false, index: true
@@ -14,5 +17,4 @@ class CreatePlaceCounties < ActiveRecord::Migration[5.0]
14
17
  def down
15
18
  drop_table :us_geo_place_counties
16
19
  end
17
-
18
20
  end
@@ -1,13 +1,14 @@
1
- class CreateZctaPlaces < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateZctaPlaces < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_zcta_places)
6
+
4
7
  create_table :us_geo_zcta_places do |t|
5
8
  t.string :zipcode, limit: 5, null: false
6
9
  t.string :place_geoid, limit: 7, null: false, index: true
7
10
  t.float :land_area, null: false
8
11
  t.float :water_area, null: false
9
- t.integer :population, null: false
10
- t.integer :housing_units, null: false
11
12
  t.datetime :updated_at, null: false
12
13
  t.integer :status, null: false, default: 0, limit: 1
13
14
  end
@@ -18,5 +19,4 @@ class CreateZctaPlaces < ActiveRecord::Migration[5.0]
18
19
  def down
19
20
  drop_table :us_geo_zcta_places
20
21
  end
21
-
22
22
  end
@@ -1,6 +1,9 @@
1
- class CreateCountySubdivisions < ActiveRecord::Migration[5.0]
1
+ # frozen_string_literal: true
2
2
 
3
+ class CreateCountySubdivisions < ActiveRecord::Migration[5.0]
3
4
  def up
5
+ return if table_exists?(:us_geo_county_subdivisions)
6
+
4
7
  create_table :us_geo_county_subdivisions, id: false do |t|
5
8
  t.string :geoid, primary_key: true, limit: 10, null: false
6
9
  t.integer :gnis_id, null: false, index: true
@@ -21,5 +24,4 @@ class CreateCountySubdivisions < ActiveRecord::Migration[5.0]
21
24
  def down
22
25
  drop_table :us_geo_county_subdivisions
23
26
  end
24
-
25
27
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AllowNullZctaCountiesDemographics < ActiveRecord::Migration[5.0]
4
+ def up
5
+ if column_exists?(:us_geo_zcta_counties, :population)
6
+ change_column_null :us_geo_zcta_counties, :population, true
7
+ end
8
+
9
+ if column_exists?(:us_geo_zcta_counties, :housing_units)
10
+ change_column_null :us_geo_zcta_counties, :housing_units, true
11
+ end
12
+ end
13
+
14
+ def down
15
+ if column_exists?(:us_geo_zcta_counties, :population)
16
+ change_column_null :us_geo_zcta_counties, :population, false
17
+ end
18
+
19
+ if column_exists?(:us_geo_zcta_counties, :housing_units)
20
+ change_column_null :us_geo_zcta_counties, :housing_units, false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AllowNullZctaPlacesDemographics < ActiveRecord::Migration[5.0]
4
+ def up
5
+ if column_exists?(:us_geo_zcta_places, :population)
6
+ change_column_null :us_geo_zcta_places, :population, true
7
+ end
8
+
9
+ if column_exists?(:us_geo_zcta_places, :housing_units)
10
+ change_column_null :us_geo_zcta_places, :housing_units, true
11
+ end
12
+ end
13
+
14
+ def down
15
+ if column_exists?(:us_geo_zcta_places, :population)
16
+ change_column_null :us_geo_zcta_places, :population, false
17
+ end
18
+
19
+ if column_exists?(:us_geo_zcta_places, :housing_units)
20
+ change_column_null :us_geo_zcta_places, :housing_units, false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddZctaPrimaryPlace < ActiveRecord::Migration[5.0]
4
+ def up
5
+ return if column_exists?(:us_geo_zctas, :primary_place_geoid)
6
+
7
+ add_column :us_geo_zctas, :primary_place_geoid, :string, limit: 7, null: true, index: true
8
+ end
9
+
10
+ def down
11
+ add_column :us_geo_zctas, :primary_place_geoid, :string, limit: 7, null: true, index: true
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDemographicsToRegions < ActiveRecord::Migration[5.0]
4
+ def up
5
+ unless column_exists?(:us_geo_regions, :land_area)
6
+ add_column :us_geo_regions, :land_area, :float, null: true
7
+ end
8
+
9
+ unless column_exists?(:us_geo_regions, :water_area)
10
+ add_column :us_geo_regions, :water_area, :float, null: true
11
+ end
12
+
13
+ unless column_exists?(:us_geo_regions, :population)
14
+ add_column :us_geo_regions, :population, :integer, null: true
15
+ end
16
+
17
+ unless column_exists?(:us_geo_regions, :housing_units)
18
+ add_column :us_geo_regions, :housing_units, :integer, null: true
19
+ end
20
+ end
21
+
22
+ def down
23
+ remove_column :us_geo_regions, :land_area
24
+ remove_column :us_geo_regions, :water_area
25
+ remove_column :us_geo_regions, :population
26
+ remove_column :us_geo_regions, :housing_units
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDemographicsToDivisions < ActiveRecord::Migration[5.0]
4
+ def up
5
+ unless column_exists?(:us_geo_divisions, :land_area)
6
+ add_column :us_geo_divisions, :land_area, :float, null: true
7
+ end
8
+
9
+ unless column_exists?(:us_geo_divisions, :water_area)
10
+ add_column :us_geo_divisions, :water_area, :float, null: true
11
+ end
12
+
13
+ unless column_exists?(:us_geo_divisions, :population)
14
+ add_column :us_geo_divisions, :population, :integer, null: true
15
+ end
16
+
17
+ unless column_exists?(:us_geo_divisions, :housing_units)
18
+ add_column :us_geo_divisions, :housing_units, :integer, null: true
19
+ end
20
+ end
21
+
22
+ def down
23
+ remove_column :us_geo_divisions, :land_area
24
+ remove_column :us_geo_divisions, :water_area
25
+ remove_column :us_geo_divisions, :population
26
+ remove_column :us_geo_divisions, :housing_units
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDemographicsToStates < ActiveRecord::Migration[5.0]
4
+ def up
5
+ unless column_exists?(:us_geo_states, :land_area)
6
+ add_column :us_geo_states, :land_area, :float, null: true
7
+ end
8
+
9
+ unless column_exists?(:us_geo_states, :water_area)
10
+ add_column :us_geo_states, :water_area, :float, null: true
11
+ end
12
+
13
+ unless column_exists?(:us_geo_states, :population)
14
+ add_column :us_geo_states, :population, :integer, null: true
15
+ end
16
+
17
+ unless column_exists?(:us_geo_states, :housing_units)
18
+ add_column :us_geo_states, :housing_units, :integer, null: true
19
+ end
20
+ end
21
+
22
+ def down
23
+ remove_column :us_geo_states, :land_area
24
+ remove_column :us_geo_states, :water_area
25
+ remove_column :us_geo_states, :population
26
+ remove_column :us_geo_states, :housing_units
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddShortNameToCoreBasedStatisticalAreas < ActiveRecord::Migration[5.0]
4
+ def up
5
+ return if column_exists?(:us_geo_core_based_statistical_areas, :short_name)
6
+
7
+ add_column :us_geo_core_based_statistical_areas, :short_name, :string, null: true
8
+
9
+ select_all("SELECT geoid, name FROM us_geo_core_based_statistical_areas").each do |row|
10
+ city, state = row["name"].split(", ", 2)
11
+ short_name = "#{city.split("-").first}, #{state.split("-").first}"
12
+ update("UPDATE us_geo_core_based_statistical_areas SET short_name = ? WHERE geoid = ?", nil, [short_name, row["geoid"]])
13
+ end
14
+
15
+ change_column_null :us_geo_core_based_statistical_areas, :short_name, false
16
+ add_index :us_geo_core_based_statistical_areas, :short_name, unique: true
17
+ end
18
+
19
+ def down
20
+ remove_column :us_geo_core_based_statistical_areas, :short_name
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddShortNameToCombinedStatisticalAreas < ActiveRecord::Migration[5.0]
4
+ def up
5
+ return if column_exists?(:us_geo_combined_statistical_areas, :short_name)
6
+
7
+ add_column :us_geo_combined_statistical_areas, :short_name, :string, null: true
8
+
9
+ select_all("SELECT geoid, name FROM us_geo_combined_statistical_areas").each do |row|
10
+ city, state = row["name"].split(", ", 2)
11
+ short_name = "#{city.split("-").first}, #{state.split("-").first}"
12
+ update("UPDATE us_geo_combined_statistical_areas SET short_name = ? WHERE geoid = ?", nil, [short_name, row["geoid"]])
13
+ end
14
+
15
+ change_column_null :us_geo_combined_statistical_areas, :short_name, false
16
+ add_index :us_geo_combined_statistical_areas, :short_name, unique: true
17
+ end
18
+
19
+ def down
20
+ remove_column :us_geo_combined_statistical_areas, :short_name
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateZctaMappings < ActiveRecord::Migration[5.0]
4
+ def up
5
+ return if table_exists?(:us_geo_zcta_mappings)
6
+
7
+ create_table :us_geo_zcta_mappings, id: false do |t|
8
+ t.string :zipcode, primary_key: true, null: false, limit: 5
9
+ t.string :zcta_zipcode, null: false, limit: 5, index: true
10
+ t.datetime :updated_at, null: false
11
+ t.integer :status, null: false, default: 0, limit: 1
12
+ end
13
+ end
14
+
15
+ def down
16
+ drop_table :us_geo_zcta_mappings
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateZctaCountySubdivisions < ActiveRecord::Migration[5.0]
4
+ def up
5
+ return if table_exists?(:us_geo_zcta_county_subdivisions)
6
+
7
+ create_table :us_geo_zcta_county_subdivisions do |t|
8
+ t.string :zipcode, limit: 5, null: false
9
+ t.string :county_subdivision_geoid, limit: 10, null: false, index: {name: :index_us_geo_zcta_county_subdivisions_on_geoid}
10
+ t.float :land_area, null: false
11
+ t.float :water_area, null: false
12
+ t.datetime :updated_at, null: false
13
+ t.integer :status, null: false, default: 0, limit: 1
14
+ end
15
+
16
+ add_index :us_geo_zcta_county_subdivisions, [:zipcode, :county_subdivision_geoid], name: :index_us_geo_zcta_county_subdivisions_uniq, unique: true
17
+ end
18
+
19
+ def down
20
+ drop_table :us_geo_zcta_county_subdivisions
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddUniqueNameIndexToCountySubdivisions < ActiveRecord::Migration[5.0]
4
+ def up
5
+ return if index_exists?(:us_geo_county_subdivisions, [:name, :county_geoid], name: "index_us_geo_county_subdivisions_on_unique_name")
6
+
7
+ duplicates_sql = <<~SQL
8
+ SELECT t2.geoid, t2.name
9
+ FROM us_geo_county_subdivisions t1,
10
+ us_geo_county_subdivisions t2
11
+ WHERE t1.geoid < t2.geoid
12
+ AND t1.county_geoid = t2.county_geoid
13
+ AND t1.name = t2.name
14
+ SQL
15
+
16
+ select_all(duplicates_sql).each do |row|
17
+ update("UPDATE us_geo_county_subdivisions SET name = ? WHERE geoid = ?", nil, ["#{row["name"]} (duplicate)", row["geoid"]])
18
+ end
19
+
20
+ add_index :us_geo_county_subdivisions, [:name, :county_geoid], unique: true, name: "index_us_geo_county_subdivisions_on_unique_name"
21
+ end
22
+
23
+ def down
24
+ remove_index :us_geo_county_subdivisions, name: "index_us_geo_county_subdivisions_on_unique_name"
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddZctaPrimaryCountySubdivision < ActiveRecord::Migration[5.0]
4
+ def up
5
+ unless column_exists?(:us_geo_zctas, :primary_county_subdivision_geoid)
6
+ add_column :us_geo_zctas, :primary_county_subdivision_geoid, :string, limit: 10, null: true, index: true
7
+ end
8
+ end
9
+
10
+ def down
11
+ add_column :us_geo_zctas, :primary_county_subdivision_geoid, :string, limit: 10, null: true, index: true
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateUrbanAreaCountySubdivisions < ActiveRecord::Migration[5.0]
4
+ def up
5
+ return if table_exists?(:us_geo_urban_area_county_subdivisions)
6
+
7
+ create_table :us_geo_urban_area_county_subdivisions do |t|
8
+ t.string :urban_area_geoid, limit: 5, null: false
9
+ t.string :county_subdivision_geoid, limit: 10, null: false
10
+ t.float :land_area, null: false
11
+ t.float :water_area, null: false
12
+ t.datetime :updated_at, null: false
13
+ t.integer :status, null: false, default: 0, limit: 1
14
+ end
15
+
16
+ add_index :us_geo_urban_area_county_subdivisions, [:urban_area_geoid, :county_subdivision_geoid], name: :index_us_geo_urban_area_county_subdivisions_uniq, unique: true
17
+ add_index :us_geo_urban_area_county_subdivisions, [:county_subdivision_geoid], name: :index_us_geo_urban_area_county_subdivisions_geoid
18
+ end
19
+
20
+ def down
21
+ drop_table :us_geo_urban_area_county_subdivisions
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AllowNullUrbanAreaCountiesDemographics < ActiveRecord::Migration[5.0]
4
+ def up
5
+ if column_exists?(:us_geo_urban_area_counties, :population)
6
+ change_column_null :us_geo_urban_area_counties, :population, true
7
+ end
8
+
9
+ if column_exists?(:us_geo_urban_area_counties, :housing_units)
10
+ change_column_null :us_geo_urban_area_counties, :housing_units, true
11
+ end
12
+ end
13
+
14
+ def down
15
+ if column_exists?(:us_geo_urban_area_counties, :population)
16
+ change_column_null :us_geo_urban_area_counties, :population, false
17
+ end
18
+
19
+ if column_exists?(:us_geo_urban_area_counties, :housing_units)
20
+ change_column_null :us_geo_urban_area_counties, :housing_units, false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AllowNullZctaUrbanAreasDemographics < ActiveRecord::Migration[5.0]
4
+ def up
5
+ if column_exists?(:us_geo_zcta_urban_areas, :population)
6
+ change_column_null :us_geo_zcta_urban_areas, :population, true
7
+ end
8
+
9
+ if column_exists?(:us_geo_zcta_urban_areas, :housing_units)
10
+ change_column_null :us_geo_zcta_urban_areas, :housing_units, true
11
+ end
12
+ end
13
+
14
+ def down
15
+ if column_exists?(:us_geo_zcta_urban_areas, :population)
16
+ change_column_null :us_geo_zcta_urban_areas, :population, false
17
+ end
18
+
19
+ if column_exists?(:us_geo_zcta_urban_areas, :housing_units)
20
+ change_column_null :us_geo_zcta_urban_areas, :housing_units, false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddAdditionalTimeZoneNameToCounties < ActiveRecord::Migration[5.0]
4
+ def up
5
+ unless column_exists?(:us_geo_counties, :time_zone_2_name)
6
+ add_column :us_geo_counties, :time_zone_2_name, :string, null: true, limit: 30
7
+ end
8
+ end
9
+
10
+ def down
11
+ remove_column :us_geo_counties, :time_zone_2_name
12
+ end
13
+ end