diff --git a/Gemfile b/Gemfile index e8aaec961..f44b49b85 100644 --- a/Gemfile +++ b/Gemfile @@ -51,6 +51,9 @@ gem 'daemons', '~> 1.1.9' # process delayed jobs # monitors gem 'newrelic_rpm', '~> 3.9.9.275' +# country listing +# gem 'countries', '~> 0.10.0' + group :development do # dev tools gem 'spring', '~> 1.2.0' diff --git a/app/models/address.rb b/app/models/address.rb index d19177f1b..acc147985 100644 --- a/app/models/address.rb +++ b/app/models/address.rb @@ -8,7 +8,7 @@ class Address < ActiveRecord::Base ] belongs_to :contact - belongs_to :country + belongs_to :country_deprecated, foreign_key: "country_id" has_paper_trail class_name: 'AddressVersion' diff --git a/app/models/country.rb b/app/models/country_deprecated.rb similarity index 56% rename from app/models/country.rb rename to app/models/country_deprecated.rb index d4e8698bf..e2047c3c7 100644 --- a/app/models/country.rb +++ b/app/models/country_deprecated.rb @@ -1,4 +1,6 @@ -class Country < ActiveRecord::Base +class CountryDeprecated < ActiveRecord::Base + self.table_name = "countries" + def to_s name end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 29df5ccd3..53db6d3cc 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -1,5 +1,5 @@ class Registrar < ActiveRecord::Base - belongs_to :country + belongs_to :country_deprecated, foreign_key: "country_id" has_many :domains, dependent: :restrict_with_error has_many :contacts, dependent: :restrict_with_error has_many :api_users, dependent: :restrict_with_error diff --git a/app/models/user.rb b/app/models/user.rb index 4df12fab5..aed260b28 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,7 +6,7 @@ class User < ActiveRecord::Base # After activisation, system should require to change temp password. # TODO: Estonian id validation - belongs_to :country + belongs_to :country_deprecated, foreign_key: "country_id" validates :username, :password, presence: true validates :identity_code, uniqueness: true, allow_blank: true diff --git a/db/migrate/20150202084444_refactor_countries.rb b/db/migrate/20150202084444_refactor_countries.rb new file mode 100644 index 000000000..b82ff1701 --- /dev/null +++ b/db/migrate/20150202084444_refactor_countries.rb @@ -0,0 +1,22 @@ +class RefactorCountries < ActiveRecord::Migration + def change + add_column :registrars, :country_code, :string + add_column :users, :country_code, :string + add_column :addresses, :country_code, :string + + Registrar.all.each do |x| + x.country_code = x.country_deprecated.try(:iso) + x.save(validate: false) + end + + User.all.each do |x| + x.country_code = x.country_deprecated.try(:iso) + x.save(validate: false) + end + + Address.all.each do |x| + x.country_code = x.country_deprecated.try(:iso) + x.save(validate: false) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7c9a0d47f..e2cf73cba 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150130085458) do +ActiveRecord::Schema.define(version: 20150202084444) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -30,13 +30,14 @@ ActiveRecord::Schema.define(version: 20150130085458) do create_table "addresses", force: :cascade do |t| t.integer "contact_id" t.integer "country_id" - t.string "city", limit: 255 - t.string "street", limit: 255 - t.string "zip", limit: 255 + t.string "city", limit: 255 + t.string "street", limit: 255 + t.string "zip", limit: 255 t.datetime "created_at" t.datetime "updated_at" - t.string "street2", limit: 255 - t.string "street3", limit: 255 + t.string "street2", limit: 255 + t.string "street3", limit: 255 + t.string "country_code" end create_table "api_users", force: :cascade do |t| @@ -206,7 +207,6 @@ ActiveRecord::Schema.define(version: 20150130085458) do t.string "name", limit: 255 t.integer "registrar_id" t.datetime "registered_at" - t.string "status", limit: 255 t.datetime "valid_from" t.datetime "valid_to" t.integer "owner_contact_id" @@ -217,6 +217,7 @@ ActiveRecord::Schema.define(version: 20150130085458) do t.string "name_puny", limit: 255 t.integer "period" t.string "period_unit", limit: 1 + t.string "status" end create_table "epp_sessions", force: :cascade do |t| @@ -296,6 +297,7 @@ ActiveRecord::Schema.define(version: 20150130085458) do t.string "phone" t.string "email" t.string "billing_email" + t.string "country_code" end create_table "reserved_domains", force: :cascade do |t| @@ -329,6 +331,7 @@ ActiveRecord::Schema.define(version: 20150130085458) do t.string "identity_code", limit: 255 t.integer "country_id" t.string "roles", array: true + t.string "country_code" end create_table "version_associations", force: :cascade do |t|