diff --git a/Gemfile b/Gemfile index fc26d9d02..85f348462 100644 --- a/Gemfile +++ b/Gemfile @@ -71,6 +71,9 @@ gem 'depp', github: 'domify/depp', ref: '800ab30dcb6dae33095bcb9df47b4e0a390891a # gem 'depp', path: '~/projects/depp' gem 'epp', '~> 1.4.2', github: 'gitlabeu/epp' +# for importing legacy db +gem 'activerecord-import', '~> 0.7.0' # for inserting dummy data + group :development do # dev tools gem 'spring', '~> 1.3.3' @@ -102,7 +105,6 @@ group :development, :test do gem 'launchy', '~> 2.4.3' # for opening browser automatically # helper gems - gem 'activerecord-import', '~> 0.6.0' # for inserting dummy data gem 'database_cleaner', '~> 1.3.0' # For cleaning db in feature and epp tests gem 'faker', '~> 1.3.0' # Library to generate fake data diff --git a/Gemfile.lock b/Gemfile.lock index 40dce6b12..f92ac9739 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,7 +79,7 @@ GEM activemodel (= 4.2.1) activesupport (= 4.2.1) arel (~> 6.0) - activerecord-import (0.6.0) + activerecord-import (0.7.0) activerecord (>= 3.0) activesupport (4.2.1) i18n (~> 0.7) @@ -87,15 +87,15 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.3.6) - akami (1.2.2) + addressable (2.3.8) + akami (1.3.0) gyoku (>= 0.4.0) nokogiri arel (6.0.0) ast (2.0.0) astrolabe (1.3.0) parser (>= 2.2.0.pre.3, < 3.0) - autodoc (0.4.3) + autodoc (0.4.4) actionpack activesupport (>= 3.0.0) rspec @@ -103,7 +103,7 @@ GEM descendants_tracker (~> 0.0.4) ice_nine (~> 0.11.0) thread_safe (~> 0.3, >= 0.3.1) - bcrypt (3.1.9) + bcrypt (3.1.10) better_errors (2.0.0) coderay (>= 1.0.0) erubis (>= 2.6.6) @@ -186,14 +186,14 @@ GEM epp-xml (0.10.4) activesupport (~> 4.1) builder (~> 3.2) - equalizer (0.0.9) + equalizer (0.0.11) erubis (2.7.0) execjs (2.4.0) fabrication (2.12.2) faker (1.3.0) i18n (~> 0.5) fastercsv (1.5.5) - ffi (1.9.6) + ffi (1.9.8) figaro (1.1.0) thor (~> 0.14) flay (2.4.0) @@ -229,7 +229,7 @@ GEM guard-rubocop (1.1.0) guard (~> 2.0) rubocop (~> 0.20) - gyoku (1.2.3) + gyoku (1.3.0) builder (>= 2.1.2) haml (4.0.6) tilt @@ -239,22 +239,21 @@ GEM haml (>= 4.0.6, < 5.0) html2haml (>= 1.0.1) railties (>= 4.0.1) - hashie (3.3.2) - hashie_rails (0.0.1) + hashie (3.4.1) + hashie_rails (0.0.4) hashie (>= 3.0) - rails (~> 4.0) highline (1.6.21) hike (1.2.3) hitimes (1.2.2) hpricot (0.8.6) httpclient (2.6.0.1) - httpi (2.3.0) + httpi (2.4.0) rack i18n (0.7.0) ice_nine (0.11.1) isikukood (0.1.2) - iso8601 (0.8.2) - jbuilder (2.2.6) + iso8601 (0.8.5) + jbuilder (2.2.12) activesupport (>= 3.0.0, < 5) multi_json (~> 1.2) jquery-rails (4.0.3) @@ -270,8 +269,8 @@ GEM addressable (~> 2.3) libv8 (3.16.14.7) libxml-ruby (2.8.0) - listen (2.8.5) - celluloid (>= 0.15.2) + listen (2.10.0) + celluloid (~> 0.16.0) rb-fsevent (>= 0.9.3) rb-inotify (>= 0.9) loofah (2.0.1) @@ -283,7 +282,7 @@ GEM mime-types (>= 1.16, < 3) method_source (0.8.2) mime-types (2.4.3) - mina (0.3.1) + mina (0.3.4) open4 (~> 1.3.4) rake mini_portile (0.6.2) @@ -293,11 +292,11 @@ GEM newrelic_rpm (3.9.9.275) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) - nori (2.4.0) - nprogress-rails (0.1.6.5) + nori (2.5.0) + nprogress-rails (0.1.6.6) open4 (1.3.4) orm_adapter (0.5.0) - parser (2.2.0.2) + parser (2.2.0.3) ast (>= 1.1, < 3.0) pg (0.18.1) phantomjs (1.9.7.1) @@ -369,8 +368,8 @@ GEM sexp_processor ref (1.0.5) request_store (1.1.0) - responders (2.0.2) - railties (>= 4.2.0.alpha, < 5) + responders (2.1.0) + railties (>= 4.2.0, < 5) rspec (3.0.0) rspec-core (~> 3.0.0) rspec-expectations (~> 3.0.0) @@ -397,7 +396,7 @@ GEM powerpack (~> 0.0.6) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.4) - ruby-progressbar (1.7.1) + ruby-progressbar (1.7.5) ruby2ruby (2.1.3) ruby_parser (~> 3.1) sexp_processor (~> 4.0) @@ -412,13 +411,13 @@ GEM virtus (~> 1.0) safe_yaml (1.0.4) sass (3.4.13) - sass-rails (5.0.1) + sass-rails (5.0.2) railties (>= 4.0.0, < 5.0) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (~> 1.1) - savon (2.10.1) + savon (2.11.0) akami (~> 1.2) builder (>= 2.1.2) gyoku (~> 1.2) @@ -434,11 +433,11 @@ GEM sexp_processor (4.5.0) shoulda-matchers (2.6.2) activesupport (>= 3.0.0) - simplecov (0.9.1) + simplecov (0.9.2) docile (~> 1.1.0) multi_json (~> 1.0) - simplecov-html (~> 0.8.0) - simplecov-html (0.8.0) + simplecov-html (~> 0.9.0) + simplecov-html (0.9.0) simpleidn (0.0.5) slim (2.1.0) temple (~> 0.6.9) @@ -486,19 +485,19 @@ GEM uuid (2.3.7) macaddr (~> 1.0) uuidtools (2.1.5) - virtus (1.0.4) + virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) equalizer (~> 0.0, >= 0.0.9) warden (1.2.3) rack (>= 1.0) - wasabi (3.4.0) + wasabi (3.5.0) httpi (~> 2.0) nokogiri (>= 1.4.2) - websocket-driver (0.5.1) + websocket-driver (0.5.4) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.1) + websocket-extensions (0.1.2) whenever (0.9.4) chronic (>= 0.6.3) xpath (2.0.0) @@ -508,7 +507,7 @@ PLATFORMS ruby DEPENDENCIES - activerecord-import (~> 0.6.0) + activerecord-import (~> 0.7.0) autodoc better_errors (~> 2.0.0) binding_of_caller (~> 0.7.2) diff --git a/app/models/legacy/db.rb b/app/models/legacy/db.rb new file mode 100644 index 000000000..f960683d0 --- /dev/null +++ b/app/models/legacy/db.rb @@ -0,0 +1,10 @@ +module Legacy + class Db < ActiveRecord::Base + self.abstract_class = true + establish_connection :fred + + def readonly? + true + end + end +end diff --git a/app/models/legacy/registrar.rb b/app/models/legacy/registrar.rb new file mode 100644 index 000000000..0dc124085 --- /dev/null +++ b/app/models/legacy/registrar.rb @@ -0,0 +1,5 @@ +module Legacy + class Registrar < Db + self.table_name = :registrar + end +end diff --git a/db/migrate/20150226121252_remove_country_id_columns.rb b/db/migrate/20150226121252_remove_country_id_columns.rb new file mode 100644 index 000000000..f5036f496 --- /dev/null +++ b/db/migrate/20150226121252_remove_country_id_columns.rb @@ -0,0 +1,7 @@ +class RemoveCountryIdColumns < ActiveRecord::Migration + def change + remove_column :registrars, :country_id, :integer + remove_column :users, :country_id, :integer + remove_column :addresses, :country_id, :integer + end +end diff --git a/db/migrate/20150226144723_add_legacy_columns_for_registrar.rb b/db/migrate/20150226144723_add_legacy_columns_for_registrar.rb new file mode 100644 index 000000000..212e882bc --- /dev/null +++ b/db/migrate/20150226144723_add_legacy_columns_for_registrar.rb @@ -0,0 +1,8 @@ +class AddLegacyColumnsForRegistrar < ActiveRecord::Migration + def change + add_column :registrars, :url, :string + add_column :registrars, :directo_handle, :string + add_column :registrars, :vat, :boolean + add_column :registrars, :legacy_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 23f93762c..19104f421 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -18,7 +18,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do create_table "addresses", force: :cascade do |t| t.integer "contact_id" - t.integer "country_id" t.string "city" t.string "street" t.string "zip" @@ -579,7 +578,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do t.string "name" t.string "reg_no" t.string "vat_no" - t.integer "country_id" t.string "billing_address" t.datetime "created_at" t.datetime "updated_at" @@ -594,6 +592,10 @@ ActiveRecord::Schema.define(version: 20150330083700) do t.string "street" t.string "zip" t.string "code" + t.string "url" + t.string "directo_handle" + t.boolean "vat" + t.integer "legacy_id" end add_index "registrars", ["code"], name: "index_registrars_on_code", using: :btree @@ -631,8 +633,6 @@ ActiveRecord::Schema.define(version: 20150330083700) do t.inet "current_sign_in_ip" t.inet "last_sign_in_ip" t.string "identity_code" - t.integer "country_id" - t.string "roles", array: true t.string "creator_str" t.string "updator_str" t.string "country_code" diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake new file mode 100644 index 000000000..5ddd26ece --- /dev/null +++ b/lib/tasks/import.rake @@ -0,0 +1,36 @@ +namespace :import do + desc "Imports registrars" + task registrars: :environment do + puts '-----> Importing registrars...' + + # Registrar.where('legacy_id IS NOT NULL').delete_all + + registrars = [] + Legacy::Registrar.all.each do |x| + next if Registrar.exists?(legacy_id: x.id) + + registrars << Registrar.new({ + name: x.organization.try(:strip).presence || x.name.try(:strip).presence || x.handle.try(:strip).presence, + reg_no: x.ico.try(:strip), + vat_no: x.dic.try(:strip), + billing_address: nil, + phone: x.telephone.try(:strip), + email: x.email.try(:strip), + billing_email: x.billing_address.try(:strip), + country_code: x.country.try(:strip), + state: x.stateorprovince.try(:strip), + city: x.city.try(:strip), + street: x.street1.try(:strip), + zip: x.postalcode.try(:strip), + url: x.url.try(:strip), + directo_handle: x.directo_handle.try(:strip), + vat: x.vat, + legacy_id: x.id + }) + end + + Registrar.import registrars, validate: false + + puts '-----> Registrars imported' + end +end