us_geo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile.lock +75 -0
  4. data/README.md +154 -0
  5. data/Rakefile +18 -0
  6. data/db/migrate/20190221054200_create_regions.rb +16 -0
  7. data/db/migrate/20190221054300_create_divisions.rb +17 -0
  8. data/db/migrate/20190221054400_create_states.rb +20 -0
  9. data/db/migrate/20190221054490_create_designated_market_areas.rb +16 -0
  10. data/db/migrate/20190221054500_create_combined_statistical_areas.rb +20 -0
  11. data/db/migrate/20190221054600_create_core_based_statistical_areas.rb +24 -0
  12. data/db/migrate/20190221054650_create_metropolitan_divisions.rb +21 -0
  13. data/db/migrate/20190221054700_create_counties.rb +34 -0
  14. data/db/migrate/20190221054800_create_zctas.rb +23 -0
  15. data/db/migrate/20190221054900_create_zcta_counties.rb +22 -0
  16. data/db/migrate/20190221055000_create_urban_areas.rb +25 -0
  17. data/db/migrate/20190221055100_create_urban_area_counties.rb +22 -0
  18. data/db/migrate/20190221055200_create_zcta_urban_areas.rb +22 -0
  19. data/db/migrate/20190221060000_create_places.rb +28 -0
  20. data/db/migrate/20190221061000_create_place_counties.rb +18 -0
  21. data/db/migrate/20190221062000_create_zcta_places.rb +22 -0
  22. data/db/migrate/20190221063000_create_county_subdivisions.rb +25 -0
  23. data/lib/tasks/us_geo/us_geo.rake +43 -0
  24. data/lib/us_geo/base_record.rb +104 -0
  25. data/lib/us_geo/combined_statistical_area.rb +40 -0
  26. data/lib/us_geo/core_based_statistical_area.rb +57 -0
  27. data/lib/us_geo/county.rb +89 -0
  28. data/lib/us_geo/county_subdivision.rb +46 -0
  29. data/lib/us_geo/demographics.rb +25 -0
  30. data/lib/us_geo/designated_market_area.rb +30 -0
  31. data/lib/us_geo/division.rb +29 -0
  32. data/lib/us_geo/engine.rb +6 -0
  33. data/lib/us_geo/metropolitan_area.rb +18 -0
  34. data/lib/us_geo/metropolitan_division.rb +42 -0
  35. data/lib/us_geo/micropolitan_area.rb +18 -0
  36. data/lib/us_geo/place.rb +61 -0
  37. data/lib/us_geo/place_county.rb +28 -0
  38. data/lib/us_geo/region.rb +28 -0
  39. data/lib/us_geo/state.rb +56 -0
  40. data/lib/us_geo/urban_area.rb +66 -0
  41. data/lib/us_geo/urban_area_county.rb +68 -0
  42. data/lib/us_geo/urban_cluster.rb +18 -0
  43. data/lib/us_geo/urbanized_area.rb +18 -0
  44. data/lib/us_geo/version.rb +5 -0
  45. data/lib/us_geo/zcta.rb +63 -0
  46. data/lib/us_geo/zcta_county.rb +68 -0
  47. data/lib/us_geo/zcta_place.rb +68 -0
  48. data/lib/us_geo/zcta_urban_area.rb +68 -0
  49. data/lib/us_geo.rb +53 -0
  50. data/spec/spec_helper.rb +22 -0
  51. data/spec/us_geo/base_record_spec.rb +67 -0
  52. data/spec/us_geo/combined_statistical_area_spec.rb +33 -0
  53. data/spec/us_geo/core_based_statistical_area_spec.rb +56 -0
  54. data/spec/us_geo/county_spec.rb +130 -0
  55. data/spec/us_geo/county_subdivision_spec.rb +37 -0
  56. data/spec/us_geo/demographics_spec.rb +19 -0
  57. data/spec/us_geo/designated_market_area_spec.rb +29 -0
  58. data/spec/us_geo/division_spec.rb +37 -0
  59. data/spec/us_geo/metropolitan_division_spec.rb +41 -0
  60. data/spec/us_geo/place_county_spec.rb +39 -0
  61. data/spec/us_geo/place_spec.rb +71 -0
  62. data/spec/us_geo/region_spec.rb +36 -0
  63. data/spec/us_geo/state_spec.rb +70 -0
  64. data/spec/us_geo/urban_area_county_spec.rb +82 -0
  65. data/spec/us_geo/urban_area_spec.rb +98 -0
  66. data/spec/us_geo/zcta_county_spec.rb +82 -0
  67. data/spec/us_geo/zcta_place_spec.rb +82 -0
  68. data/spec/us_geo/zcta_spec.rb +99 -0
  69. data/spec/us_geo/zcta_urban_area_spec.rb +82 -0
  70. metadata +229 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3830cec3c8dd872df73d2c290854040f8f755f92f4762e64fb1dfb36330e6885
4
+ data.tar.gz: 0f0923a5aca71c60ce3b80789dd4751b16d2881ae67a49a5ee1acd596fb6b7f2
5
+ SHA512:
6
+ metadata.gz: f6e7bc70588ed2d7175f8f42d138bf8be7ed181d93ff838332f5dd8e3cd1ee80e7fe8ba8e2b556be164832df749084dd41d2af1e0ce16524342e9d8fe4fac070
7
+ data.tar.gz: 280b9fcc0ffb2a5f78b749ff8d02e0223e5071b7fa9c08cda37dede29c6c0a026979ae457f4770544b77d9212ff78662b6e2628de12f2f328e40e8fdb32639ac
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ us_geo (1.0.0)
5
+ activerecord (~> 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.2.1)
11
+ activesupport (= 5.2.2.1)
12
+ activerecord (5.2.2.1)
13
+ activemodel (= 5.2.2.1)
14
+ activesupport (= 5.2.2.1)
15
+ arel (>= 9.0)
16
+ activesupport (5.2.2.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ addressable (2.6.0)
22
+ public_suffix (>= 2.0.2, < 4.0)
23
+ appraisal (2.2.0)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ arel (9.0.0)
28
+ concurrent-ruby (1.1.5)
29
+ crack (0.4.3)
30
+ safe_yaml (~> 1.0.0)
31
+ diff-lcs (1.3)
32
+ hashdiff (0.3.7)
33
+ i18n (1.6.0)
34
+ concurrent-ruby (~> 1.0)
35
+ minitest (5.11.3)
36
+ public_suffix (3.0.3)
37
+ rake (10.5.0)
38
+ rspec (3.8.0)
39
+ rspec-core (~> 3.8.0)
40
+ rspec-expectations (~> 3.8.0)
41
+ rspec-mocks (~> 3.8.0)
42
+ rspec-core (3.8.0)
43
+ rspec-support (~> 3.8.0)
44
+ rspec-expectations (3.8.2)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.8.0)
47
+ rspec-mocks (3.8.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-support (3.8.0)
51
+ safe_yaml (1.0.4)
52
+ sqlite3 (1.3.13)
53
+ thor (0.20.3)
54
+ thread_safe (0.3.6)
55
+ tzinfo (1.2.5)
56
+ thread_safe (~> 0.1)
57
+ webmock (3.4.2)
58
+ addressable (>= 2.3.6)
59
+ crack (>= 0.3.2)
60
+ hashdiff
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ appraisal
67
+ bundler (~> 1.16)
68
+ rake (~> 10.0)
69
+ rspec (~> 3.8)
70
+ sqlite3 (~> 1.3.0)
71
+ us_geo!
72
+ webmock (~> 3.4)
73
+
74
+ BUNDLED WITH
75
+ 1.16.5
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # USGeo
2
+
3
+ [![Build Status](https://travis-ci.com/bdurand/us_geo.svg?branch=master)](https://travis-ci.com/bdurand/us_geo)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a01ffc7f707686416c0d/maintainability)](https://codeclimate.com/github/bdurand/us_geo/maintainability)
5
+
6
+ This gem provides a variety of U.S. geographic data ActiveRecord models. It is designed to provide a normalized way to access the data from a relational database. This is by no means a complete set of data. The primary purpose it was built is to provide a way to match most ZIP codes to higher level geographic entities.
7
+
8
+ ## Entities
9
+
10
+ All of the entities except for DMA are defined by the U.S. Census Bureau. For more details.
11
+
12
+ https://www2.census.gov/geo/pdfs/reference/geodiagram.pdf
13
+ https://www2.census.gov/geo/pdfs/reference/GARM/Ch2GARM.pdf
14
+
15
+ All entities in the system are keyed using external identifier.
16
+
17
+ * The various `geoid` columns reference the id used by the U.S. Census Bureau.
18
+
19
+ * The `gnis_id` columns are the official ID's assigned by the U.S. Board on Geographic Names https://geonames.usgs.gov.
20
+
21
+
22
+ There are no foreign key constraints defined on the tables. This is intentional so that you can only import as much data as you need if you don't need the whole set.
23
+
24
+ The data set currently contains
25
+
26
+ * 4 Regions
27
+ * 9 Divisions
28
+ * 59 States and Territories
29
+ * 210 Designated Market Areas
30
+ * 175 Combined Statistical Areas
31
+ * 938 Core Based Statistical Areas
32
+ * 31 Metropolitan Divisions
33
+ * 3223 Counties or equivalents
34
+ * 36429 County Subdivisions
35
+ * 3601 Urban Areas
36
+ * 30187 Places
37
+ * 33120 ZIP Code Tabulation Areas
38
+
39
+ In addition, there entity to entity mapping tables:
40
+
41
+ * 44388 ZCTA to County
42
+ * 17389 ZCTA to Urban Area
43
+ * 49843 ZCTA to Place
44
+ * 4945 Urban Area to County
45
+ * 31492 Place to County
46
+
47
+ The land and water area for all entities is given in square miles.
48
+
49
+ ### Region
50
+
51
+ A grouping of divisions into four regions: Northeast, Midwest, South, West.
52
+
53
+ ### Division
54
+
55
+ A grouping of states within a region.
56
+
57
+ ### State
58
+
59
+ Includes both states and territories and the District of Columbia.
60
+
61
+ ### Designated Market Area (DMA)
62
+
63
+ Media marketing areas of counties served by the same over the air radio and television signals. DMA's are not official government designations and are defined by the Nielsen Company.
64
+
65
+ ### Combined Statistical Areas
66
+
67
+ Groupings of adjacent CBSA's with regional ties to each other.
68
+
69
+ ### Core Based Statistical Area (CBSA)
70
+
71
+ A grouping of counties around an urban core defined by commuting patterns. CBSA's are split into metropolitan (population > 50,000) and micropolitan areas. Counties within a CBSA are either identified as being core or outlyer counties. Not all counties belong to a CBSA.
72
+
73
+ ### Metropolitan Division
74
+
75
+ The largest CBSAs (New York, Chicago, etc.) are split into metropolitan divisions.
76
+
77
+ ### County (or county equivalent)
78
+
79
+ Basic organizational unit of states and territories. The actual name of the unit can vary depending on the state (i.e. parishes is Louisiana).
80
+
81
+ County data is only provided for states, the District of Columbia, Puerto Rico. It is not provided for other U.S. territories.
82
+
83
+ ### County Subdivision
84
+
85
+ Subdivision of counties. These could be minor civil divisions like townships or borroughs, but in some states that don't divide counties, they are census designated places. See https://www.census.gov/geo/reference/gtc/gtc_cousub.html.
86
+
87
+ ### Urban Area
88
+
89
+ Urbanized areas or clusters. Areas with 2,500 to 50,000 inhabitants is considered an urban cluster while more than 50,000 is an urbanized area. Urban areas can span counties, but the one with the majority of the population is identified as the primary county.
90
+
91
+ Urban area data is only provided for states, the District of Columbia, Puerto Rico. It is not provided for other U.S. territories.
92
+
93
+ ### Place
94
+
95
+ A place is an organized area within a state usually corresponding to a city, town, village, etc. Places are within a single state, but may span counties. If a place spans multiple counties, the county with the most population will be identified as the primary county. Places may belong to an urban area.
96
+
97
+ ### ZIP Code Tabulation Area (ZCTA)
98
+
99
+ Approximate equivalent to U.S. Postal Service ZIP codes, but designed for geographic and demographic purposes rather than mail routing. Not all postal ZIP codes are mapped to ZCTAs (i.e. ZIP codes mapped to a single building) and the borders of ZCTAs smooth out some of the irregularities of ZIP codes. Otherwise, they are mostly interchangeable.
100
+
101
+ ZCTAs can span counties, urban areas, places. The primary county and primary urban area will be the ones that contain most of the ZCTA's population.
102
+
103
+ ZCTA data is only provided for states, the District of Columbia, Puerto Rico. It is not provided for other U.S. territories.
104
+
105
+
106
+ ## Usage
107
+
108
+ First add to you Gemfile:
109
+
110
+ `gem us_geo`
111
+
112
+ Install the migrations:
113
+
114
+ ```bash
115
+ rake us_geo_engine:install:migrations
116
+ ```
117
+
118
+ Import the data:
119
+
120
+ ```bash
121
+ rake us_geo:import:all
122
+ ```
123
+
124
+ Or, if you only want to import some subset of the data, you can run any number of the following.
125
+
126
+ ```bash
127
+ rake us_geo:import:regions
128
+ rake us_geo:import:divisions
129
+ rake us_geo:import:states
130
+ rake us_geo:import:designated_market_areas
131
+ rake us_geo:import:combined_statistical_areas
132
+ rake us_geo:import:core_based_statistical_areas
133
+ rake us_geo:import:metropolitan_divisions
134
+ rake us_geo:import:counties
135
+ rake us_geo:import:county_subdivisions
136
+ rake us_geo:import:urban_areas
137
+ rake us_geo:import:places
138
+ rake us_geo:import:zctas
139
+ rake us_geo:import:place_counties
140
+ rake us_geo:import:urban_area_counties
141
+ rake us_geo:import:zcta_counties
142
+ rake us_geo:import:zcta_places
143
+ rake us_geo:import:zcta_urban_areas
144
+ ```
145
+
146
+ By default this will download the data from files hosted with the project on GitHub and insert/update into the database. If any entity records are found that don't exist in the data files, the `removed` flag on the database rows will be set to `TRUE`.
147
+
148
+ If you want, you can download the file data files and point to them locally by setting `USGeo.base_data_uri` in an initializer.
149
+
150
+ You can also load the data programatically by simply calling the `load!` method on each class. This will do the same thing the rake tasks do.
151
+
152
+ All records imported from the data files will have their status set to 1 (imported). Any records that were previously imported, but that are no longer in the data file, will have their status changed to -1 (removed) to indicate that they are no longer in the official data set. Finally, records added to the tables manually will have their status set to 0 (manual). It is perfectly acceptable to augment the data set to, for example, add new Postal Service ZIP codes that did not exist during the last census.
153
+
154
+ This gem can be used outside of a Rails application. You'll just need to copy the migrations by hand and install the import rake tasks.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :appraisals
7
+
8
+ desc "run the specs using appraisal"
9
+ task :appraisals do
10
+ exec "bundle exec appraisal rake spec"
11
+ end
12
+
13
+ namespace :appraisals do
14
+ desc "install all the appraisal gemspecs"
15
+ task :install do
16
+ exec "bundle exec appraisal install"
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ class CreateRegions < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_regions, id: false do |t|
5
+ t.integer :id, primary_key: true, null: false, limit: 1
6
+ t.string :name, null: false, limit: 30, index: {unique: true}
7
+ t.datetime :updated_at, null: false
8
+ t.integer :status, null: false, default: 0, limit: 1
9
+ end
10
+ end
11
+
12
+ def down
13
+ drop_table :us_geo_regions
14
+ end
15
+
16
+ end
@@ -0,0 +1,17 @@
1
+ class CreateDivisions < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_divisions, id: false do |t|
5
+ t.integer :id, primary_key: true, null: false, limit: 1
6
+ t.integer :region_id, null: false, limit: 1, index: true
7
+ t.string :name, null: false, limit: 30, index: {unique: true}
8
+ t.datetime :updated_at, null: false
9
+ t.integer :status, null: false, default: 0, limit: 1
10
+ end
11
+ end
12
+
13
+ def down
14
+ drop_table :us_geo_divisions
15
+ end
16
+
17
+ end
@@ -0,0 +1,20 @@
1
+ class CreateStates < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_states, id: false do |t|
5
+ t.string :code, primary_key: true, null: false, limit: 2
6
+ t.string :name, null: false, limit: 30, index: {unique: true}
7
+ t.string :fips, null: false, limit: 2, index: {unique: true}
8
+ t.string :type, null: false, limit: 30
9
+ t.integer :region_id, null: true, limit: 1, index: true
10
+ t.integer :division_id, null: true, limit: 1, index: true
11
+ t.datetime :updated_at, null: false
12
+ t.integer :status, null: false, default: 0, limit: 1
13
+ end
14
+ end
15
+
16
+ def down
17
+ drop_table :us_geo_states
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ class CreateDesignatedMarketAreas < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_designated_market_areas, id: false do |t|
5
+ t.string :code, primary_key: true, null: false, limit: 3
6
+ t.string :name, null: false, limit: 60, index: {unique: true}
7
+ t.datetime :updated_at, null: false
8
+ t.integer :status, null: false, default: 0, limit: 1
9
+ end
10
+ end
11
+
12
+ def down
13
+ drop_table :us_geo_designated_market_areas
14
+ end
15
+
16
+ end
@@ -0,0 +1,20 @@
1
+ class CreateCombinedStatisticalAreas < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_combined_statistical_areas, id: false do |t|
5
+ t.string :geoid, primary_key: true, null: false, limit: 3
6
+ t.string :name, null: false, limit: 60, index: {unique: true}
7
+ t.float :land_area, null: false
8
+ t.float :water_area, null: false
9
+ t.integer :population, null: false
10
+ t.integer :housing_units, null: false
11
+ t.datetime :updated_at, null: false
12
+ t.integer :status, null: false, default: 0, limit: 1
13
+ end
14
+ end
15
+
16
+ def down
17
+ drop_table :us_geo_combined_statistical_areas
18
+ end
19
+
20
+ end
@@ -0,0 +1,24 @@
1
+ class CreateCoreBasedStatisticalAreas < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_core_based_statistical_areas, id: false do |t|
5
+ t.string :geoid, primary_key: true, null: false, limit: 5
6
+ t.string :csa_geoid, limit: 5, index: true
7
+ t.string :name, null: false, limit: 60, index: {unique: true}
8
+ t.string :type, null: false, limit: 30
9
+ t.float :land_area, null: false
10
+ t.float :water_area, null: false
11
+ t.integer :population, null: false
12
+ t.integer :housing_units, null: false
13
+ t.float :lat, null: false
14
+ t.float :lng, null: false
15
+ t.datetime :updated_at, null: false
16
+ t.integer :status, null: false, default: 0, limit: 1
17
+ end
18
+ end
19
+
20
+ def down
21
+ drop_table :us_geo_core_based_statistical_areas
22
+ end
23
+
24
+ end
@@ -0,0 +1,21 @@
1
+ class CreateMetropolitanDivisions < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_metropolitan_divisions, id: false do |t|
5
+ t.string :geoid, primary_key: true, null: false, limit: 5
6
+ t.string :cbsa_geoid, limit: 5, index: true
7
+ t.string :name, null: false, limit: 60, index: {unique: true}
8
+ t.float :land_area, null: false
9
+ t.float :water_area, null: false
10
+ t.integer :population, null: false
11
+ t.integer :housing_units, null: false
12
+ t.datetime :updated_at, null: false
13
+ t.integer :status, null: false, default: 0, limit: 1
14
+ end
15
+ end
16
+
17
+ def down
18
+ drop_table :us_geo_metropolitan_divisions
19
+ end
20
+
21
+ end
@@ -0,0 +1,34 @@
1
+ class CreateCounties < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_counties, id: false do |t|
5
+ t.string :geoid, primary_key: true, limit: 5, null: false
6
+ t.integer :gnis_id, null: false, index: true
7
+ t.string :cbsa_geoid, null: true, limit: 5, index: true
8
+ t.string :metropolitan_division_geoid, limit: 5, null: true, index: true
9
+ t.string :name, null: false, limit: 60
10
+ t.string :short_name, null: false, limit: 30
11
+ t.string :state_code, null: false, limit: 2, index: true
12
+ t.boolean :central, default: false
13
+ t.string :fips_class_code, null: false, limit: 2
14
+ t.string :time_zone_name, null: true, limit: 30
15
+ t.string :dma_code, limit: 3, null: true, index: true
16
+ t.float :land_area, null: true
17
+ t.float :water_area, null: true
18
+ t.integer :population, null: true
19
+ t.integer :housing_units, null: true
20
+ t.float :lat, null: true
21
+ t.float :lng, null: true
22
+ t.datetime :updated_at, null: false
23
+ t.integer :status, null: false, default: 0, limit: 1
24
+ end
25
+
26
+ add_index :us_geo_counties, [:name, :state_code], unique: true
27
+ add_index :us_geo_counties, [:short_name, :state_code], unique: true
28
+ end
29
+
30
+ def down
31
+ drop_table :us_geo_counties
32
+ end
33
+
34
+ end
@@ -0,0 +1,23 @@
1
+ class CreateZctas < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_zctas, id: false do |t|
5
+ t.string :zipcode, primary_key: true, null: false, limit: 5
6
+ t.string :primary_county_geoid, null: false, limit: 5, index: true
7
+ t.string :primary_urban_area_geoid, null: true, limit: 5, index: true
8
+ t.float :land_area, null: false
9
+ t.float :water_area, null: false
10
+ t.integer :population, null: false
11
+ t.integer :housing_units, null: false
12
+ t.float :lat, null: false
13
+ t.float :lng, null: false
14
+ t.datetime :updated_at, null: false
15
+ t.integer :status, null: false, default: 0, limit: 1
16
+ end
17
+ end
18
+
19
+ def down
20
+ drop_table :us_geo_zctas
21
+ end
22
+
23
+ end
@@ -0,0 +1,22 @@
1
+ class CreateZctaCounties < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_zcta_counties do |t|
5
+ t.string :zipcode, limit: 5, null: false
6
+ t.string :county_geoid, limit: 5, null: false, index: true
7
+ t.float :land_area, null: false
8
+ t.float :water_area, null: false
9
+ t.integer :population, null: false
10
+ t.integer :housing_units, null: false
11
+ t.datetime :updated_at, null: false
12
+ t.integer :status, null: false, default: 0, limit: 1
13
+ end
14
+
15
+ add_index :us_geo_zcta_counties, [:zipcode, :county_geoid], name: :index_us_geo_zcta_counties_uniq, unique: true
16
+ end
17
+
18
+ def down
19
+ drop_table :us_geo_zcta_counties
20
+ end
21
+
22
+ end
@@ -0,0 +1,25 @@
1
+ class CreateUrbanAreas < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_urban_areas, id: false do |t|
5
+ t.string :geoid, primary_key: true, null: false, limit: 5
6
+ t.string :name, null: false, limit: 90, index: {unique: true}
7
+ t.string :short_name, null: false, limit: 60, index: {unique: true}
8
+ t.string :primary_county_geoid, null: false, limit: 5, index: true
9
+ t.string :type, null: false, limit: 30
10
+ t.float :land_area, null: false
11
+ t.float :water_area, null: false
12
+ t.integer :population, null: false
13
+ t.integer :housing_units, null: false
14
+ t.float :lat, null: false
15
+ t.float :lng, null: false
16
+ t.datetime :updated_at, null: false
17
+ t.integer :status, null: false, default: 0, limit: 1
18
+ end
19
+ end
20
+
21
+ def down
22
+ drop_table :us_geo_urban_areas
23
+ end
24
+
25
+ end
@@ -0,0 +1,22 @@
1
+ class CreateUrbanAreaCounties < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_urban_area_counties do |t|
5
+ t.string :urban_area_geoid, limit: 5, null: false
6
+ t.string :county_geoid, limit: 5, null: false, index: true
7
+ t.float :land_area, null: false
8
+ t.float :water_area, null: false
9
+ t.integer :population, null: false
10
+ t.integer :housing_units, null: false
11
+ t.datetime :updated_at, null: false
12
+ t.integer :status, null: false, default: 0, limit: 1
13
+ end
14
+
15
+ add_index :us_geo_urban_area_counties, [:urban_area_geoid, :county_geoid], name: :index_us_geo_urban_area_counties_uniq, unique: true
16
+ end
17
+
18
+ def down
19
+ drop_table :us_geo_urban_area_counties
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ class CreateZctaUrbanAreas < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_zcta_urban_areas do |t|
5
+ t.string :zipcode, limit: 5, null: false, index: true
6
+ t.string :urban_area_geoid, limit: 5, null: false
7
+ t.float :land_area, null: false
8
+ t.float :water_area, null: false
9
+ t.integer :population, null: false
10
+ t.integer :housing_units, null: false
11
+ t.datetime :updated_at, null: false
12
+ t.integer :status, null: false, default: 0, limit: 1
13
+ end
14
+
15
+ add_index :us_geo_zcta_urban_areas, [:urban_area_geoid, :zipcode], name: :index_us_geo_urban_area_zctas_uniq, unique: true
16
+ end
17
+
18
+ def down
19
+ drop_table :us_geo_zcta_urban_areas
20
+ end
21
+
22
+ end
@@ -0,0 +1,28 @@
1
+ class CreatePlaces < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_places, id: false do |t|
5
+ t.string :geoid, primary_key: true, limit: 7, null: false
6
+ t.integer :gnis_id, null: false, index: true
7
+ t.string :name, null: false, limit: 60, index: true
8
+ t.string :short_name, null: false, limit: 30, index: true
9
+ t.string :state_code, null: false, limit: 2, index: true
10
+ t.string :primary_county_geoid, null: false, limit: 5, index: true
11
+ t.string :urban_area_geoid, null: true, limit: 5, index: true
12
+ t.string :fips_class_code, null: false, limit: 2
13
+ t.float :land_area, null: true
14
+ t.float :water_area, null: true
15
+ t.integer :population, null: true
16
+ t.integer :housing_units, null: true
17
+ t.float :lat, null: false
18
+ t.float :lng, null: false
19
+ t.datetime :updated_at, null: false
20
+ t.integer :status, null: false, default: 0, limit: 1
21
+ end
22
+ end
23
+
24
+ def down
25
+ drop_table :us_geo_places
26
+ end
27
+
28
+ end
@@ -0,0 +1,18 @@
1
+ class CreatePlaceCounties < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_place_counties do |t|
5
+ t.string :place_geoid, limit: 7, null: false
6
+ t.string :county_geoid, limit: 5, null: false, index: true
7
+ t.datetime :updated_at, null: false
8
+ t.integer :status, null: false, default: 0, limit: 1
9
+ end
10
+
11
+ add_index :us_geo_place_counties, [:place_geoid, :county_geoid], name: :index_us_geo_place_counties_uniq, unique: true
12
+ end
13
+
14
+ def down
15
+ drop_table :us_geo_place_counties
16
+ end
17
+
18
+ end
@@ -0,0 +1,22 @@
1
+ class CreateZctaPlaces < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_zcta_places do |t|
5
+ t.string :zipcode, limit: 5, null: false
6
+ t.string :place_geoid, limit: 7, null: false, index: true
7
+ t.float :land_area, null: false
8
+ t.float :water_area, null: false
9
+ t.integer :population, null: false
10
+ t.integer :housing_units, null: false
11
+ t.datetime :updated_at, null: false
12
+ t.integer :status, null: false, default: 0, limit: 1
13
+ end
14
+
15
+ add_index :us_geo_zcta_places, [:zipcode, :place_geoid], name: :index_us_geo_us_geo_zcta_places_uniq, unique: true
16
+ end
17
+
18
+ def down
19
+ drop_table :us_geo_zcta_places
20
+ end
21
+
22
+ end
@@ -0,0 +1,25 @@
1
+ class CreateCountySubdivisions < ActiveRecord::Migration[5.0]
2
+
3
+ def up
4
+ create_table :us_geo_county_subdivisions, id: false do |t|
5
+ t.string :geoid, primary_key: true, limit: 10, null: false
6
+ t.integer :gnis_id, null: false, index: true
7
+ t.string :name, null: false, limit: 60
8
+ t.string :county_geoid, null: false, limit: 5, index: true
9
+ t.string :fips_class_code, null: false, limit: 2
10
+ t.float :land_area, null: true
11
+ t.float :water_area, null: true
12
+ t.integer :population, null: true
13
+ t.integer :housing_units, null: true
14
+ t.float :lat, null: false
15
+ t.float :lng, null: false
16
+ t.datetime :updated_at, null: false
17
+ t.integer :status, null: false, default: 0, limit: 1
18
+ end
19
+ end
20
+
21
+ def down
22
+ drop_table :us_geo_county_subdivisions
23
+ end
24
+
25
+ end