lib/generators/china_regions/templates/migration.rb in china_regions-0.4.3 vs lib/generators/china_regions/templates/migration.rb in china_regions-0.4.4

- old
+ new

@@ -1,44 +1,48 @@ -# encoding: utf-8 +# frozen_string_literal: true class CreateChinaRegionsTables < ActiveRecord::Migration def change - unless table_exists? 'provinces' - create_table :provinces do |t| - t.string :name - t.string :name_en - t.string :name_abbr + setup_provinces unless table_exists? 'provinces' + setup_citites unless table_exists? 'cities' + setup_districts unless table_exists? 'districts' + end - t.timestamps - end + def setup_provinces + create_table :provinces do |t| + t.string :name + t.string :name_en + t.string :name_abbr - add_index :provinces, :name + t.timestamps end - unless table_exists? 'cities' - create_table :cities do |t| - t.string :name - t.integer :province_id - t.integer :level - t.string :zip_code - t.string :name_en - t.string :name_abbr + add_index :provinces, :name + end - t.timestamps - end + def setup_citites + create_table :cities do |t| + t.string :name + t.integer :province_id + t.integer :level + t.string :zip_code + t.string :name_en + t.string :name_abbr - add_index :cities, :name + t.timestamps end - unless table_exists? 'districts' - create_table :districts do |t| - t.string :name - t.integer :city_id - t.string :name_en - t.string :name_abbr + add_index :cities, :name + end - t.timestamps - end - add_index :districts, :name + def setup_districts + create_table :districts do |t| + t.string :name + t.integer :city_id + t.string :name_en + t.string :name_abbr + + t.timestamps end + add_index :districts, :name end end