User import added

This commit is contained in:
Stas 2015-10-30 13:56:15 +02:00
parent a3272fab43
commit 66d7d80bcc
6 changed files with 57 additions and 2 deletions

View file

@ -3,6 +3,7 @@ module Legacy
self.table_name = :registrar self.table_name = :registrar
has_many :invoices, foreign_key: :registrarid has_many :invoices, foreign_key: :registrarid
has_one :acl, foreign_key: :registrarid, class_name: "Legacy::RegistrarAcl"
def account_balance def account_balance
invoices.sum(:credit) invoices.sum(:credit)

View file

@ -0,0 +1,5 @@
module Legacy
class RegistrarAcl < Db
self.table_name = :registraracl
end
end

View file

@ -0,0 +1,5 @@
class AddLegacyIdToUsers < ActiveRecord::Migration
def change
add_column :users, :legacy_id, :integer
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: 20150921111842) do ActiveRecord::Schema.define(version: 20151029152638) 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"
@ -1053,6 +1053,7 @@ ActiveRecord::Schema.define(version: 20150921111842) do
t.datetime "remember_created_at" t.datetime "remember_created_at"
t.integer "failed_attempts", default: 0, null: false t.integer "failed_attempts", default: 0, null: false
t.datetime "locked_at" t.datetime "locked_at"
t.integer "legacy_id"
end end
add_index "users", ["identity_code"], name: "index_users_on_identity_code", using: :btree add_index "users", ["identity_code"], name: "index_users_on_identity_code", using: :btree

View file

@ -2658,7 +2658,8 @@ CREATE TABLE users (
encrypted_password character varying DEFAULT ''::character varying NOT NULL, encrypted_password character varying DEFAULT ''::character varying NOT NULL,
remember_created_at timestamp without time zone, remember_created_at timestamp without time zone,
failed_attempts integer DEFAULT 0 NOT NULL, failed_attempts integer DEFAULT 0 NOT NULL,
locked_at timestamp without time zone locked_at timestamp without time zone,
legacy_id integer
); );
@ -4946,3 +4947,5 @@ INSERT INTO schema_migrations (version) VALUES ('20150921110152');
INSERT INTO schema_migrations (version) VALUES ('20150921111842'); INSERT INTO schema_migrations (version) VALUES ('20150921111842');
INSERT INTO schema_migrations (version) VALUES ('20151029152638');

View file

@ -52,6 +52,7 @@ namespace :import do
desc 'Import all' desc 'Import all'
task all: :environment do task all: :environment do
Rake::Task['import:registrars'].invoke Rake::Task['import:registrars'].invoke
Rake::Task['import:users'].invoke
Rake::Task['import:contacts'].invoke Rake::Task['import:contacts'].invoke
Rake::Task['import:domains'].invoke Rake::Task['import:domains'].invoke
Rake::Task['import:zones'].invoke Rake::Task['import:zones'].invoke
@ -123,6 +124,45 @@ namespace :import do
puts "-----> Imported #{count} new registrars in #{(Time.zone.now.to_f - start).round(2)} seconds" puts "-----> Imported #{count} new registrars in #{(Time.zone.now.to_f - start).round(2)} seconds"
end end
desc 'Import users'
task users: :environment do
start = Time.zone.now.to_f
puts '-----> Importing users...'
users = []
ips = []
existing_ids = ApiUser.pluck(:legacy_id)
count = 0
Legacy::Registrar.all.each do |x|
next if existing_ids.include?(x.id)
count += 1
users << ApiUser.new({
username: x.handle.try(:strip),
password: x.acl.try(:password),
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
legacy_id: x.try(:id)
})
if x.acl.try(:ipaddr)
ips << WhiteIp.new({
registrar_id: Registrar.find_by(legacy_id: x.try(:id)).try(:id),
ipv4: x.acl.try(:ipaddr)
})
end
end
ApiUser.import users, validate: false
if ips
WhiteIp.import ips, validate: false
end
puts "-----> Imported #{count} new users in #{(Time.zone.now.to_f - start).round(2)} seconds"
end
desc 'Import contacts' desc 'Import contacts'
task contacts: :environment do task contacts: :environment do
start = Time.zone.now.to_f start = Time.zone.now.to_f