Migrate country id-s to country codes

This commit is contained in:
Martin Lensment 2015-02-02 11:22:03 +02:00
parent ea6bdc19f9
commit 864c451a61
7 changed files with 41 additions and 11 deletions

View file

@ -51,6 +51,9 @@ gem 'daemons', '~> 1.1.9' # process delayed jobs
# monitors # monitors
gem 'newrelic_rpm', '~> 3.9.9.275' gem 'newrelic_rpm', '~> 3.9.9.275'
# country listing
# gem 'countries', '~> 0.10.0'
group :development do group :development do
# dev tools # dev tools
gem 'spring', '~> 1.2.0' gem 'spring', '~> 1.2.0'

View file

@ -8,7 +8,7 @@ class Address < ActiveRecord::Base
] ]
belongs_to :contact belongs_to :contact
belongs_to :country belongs_to :country_deprecated, foreign_key: "country_id"
has_paper_trail class_name: 'AddressVersion' has_paper_trail class_name: 'AddressVersion'

View file

@ -1,4 +1,6 @@
class Country < ActiveRecord::Base class CountryDeprecated < ActiveRecord::Base
self.table_name = "countries"
def to_s def to_s
name name
end end

View file

@ -1,5 +1,5 @@
class Registrar < ActiveRecord::Base class Registrar < ActiveRecord::Base
belongs_to :country belongs_to :country_deprecated, foreign_key: "country_id"
has_many :domains, dependent: :restrict_with_error has_many :domains, dependent: :restrict_with_error
has_many :contacts, dependent: :restrict_with_error has_many :contacts, dependent: :restrict_with_error
has_many :api_users, dependent: :restrict_with_error has_many :api_users, dependent: :restrict_with_error

View file

@ -6,7 +6,7 @@ class User < ActiveRecord::Base
# After activisation, system should require to change temp password. # After activisation, system should require to change temp password.
# TODO: Estonian id validation # TODO: Estonian id validation
belongs_to :country belongs_to :country_deprecated, foreign_key: "country_id"
validates :username, :password, presence: true validates :username, :password, presence: true
validates :identity_code, uniqueness: true, allow_blank: true validates :identity_code, uniqueness: true, allow_blank: true

View file

@ -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

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -37,6 +37,7 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.datetime "updated_at" t.datetime "updated_at"
t.string "street2", limit: 255 t.string "street2", limit: 255
t.string "street3", limit: 255 t.string "street3", limit: 255
t.string "country_code"
end end
create_table "api_users", force: :cascade do |t| create_table "api_users", force: :cascade do |t|
@ -206,7 +207,6 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.string "name", limit: 255 t.string "name", limit: 255
t.integer "registrar_id" t.integer "registrar_id"
t.datetime "registered_at" t.datetime "registered_at"
t.string "status", limit: 255
t.datetime "valid_from" t.datetime "valid_from"
t.datetime "valid_to" t.datetime "valid_to"
t.integer "owner_contact_id" t.integer "owner_contact_id"
@ -217,6 +217,7 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.string "name_puny", limit: 255 t.string "name_puny", limit: 255
t.integer "period" t.integer "period"
t.string "period_unit", limit: 1 t.string "period_unit", limit: 1
t.string "status"
end end
create_table "epp_sessions", force: :cascade do |t| create_table "epp_sessions", force: :cascade do |t|
@ -296,6 +297,7 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.string "phone" t.string "phone"
t.string "email" t.string "email"
t.string "billing_email" t.string "billing_email"
t.string "country_code"
end end
create_table "reserved_domains", force: :cascade do |t| 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.string "identity_code", limit: 255
t.integer "country_id" t.integer "country_id"
t.string "roles", array: true t.string "roles", array: true
t.string "country_code"
end end
create_table "version_associations", force: :cascade do |t| create_table "version_associations", force: :cascade do |t|