mirror of
https://github.com/internetee/registry.git
synced 2025-06-04 11:47:30 +02:00
implement asynchronous rake task for collect contact data from csv
This commit is contained in:
parent
cf450d373a
commit
aaaae888bf
5 changed files with 92 additions and 3 deletions
21
app/jobs/scan_csv_registry_businnes_contacts_job.rb
Normal file
21
app/jobs/scan_csv_registry_businnes_contacts_job.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class ScanCsvRegistryBusinnesContactsJob < ApplicationJob
|
||||
FILE_NAME = './ettevotja_rekvisiidid_init.csv'.freeze
|
||||
def perform
|
||||
BusinessRegistryContact.delete_all
|
||||
|
||||
return p 'File not exist!' unless File.exist?(FILE_NAME)
|
||||
|
||||
CSV.foreach(FILE_NAME, headers: true, col_sep: ";") do |row|
|
||||
name = row[0]
|
||||
code = row[1]
|
||||
status = row[5]
|
||||
|
||||
record = BusinessRegistryContact.create({
|
||||
name: name,
|
||||
registry_code: code,
|
||||
status: status
|
||||
})
|
||||
p "#{record} is successfully created - #{BusinessRegistryContact.count} count"
|
||||
end
|
||||
end
|
||||
end
|
2
app/models/business_registry_contact.rb
Normal file
2
app/models/business_registry_contact.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class BusinessRegistryContact < ApplicationRecord
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class CreateBusinessRegistryContacts < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :business_registry_contacts do |t|
|
||||
t.string :name
|
||||
t.string :registry_code
|
||||
t.string :status
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -497,6 +497,39 @@ CREATE SEQUENCE public.bounced_mail_addresses_id_seq
|
|||
ALTER SEQUENCE public.bounced_mail_addresses_id_seq OWNED BY public.bounced_mail_addresses.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: business_registry_contacts; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.business_registry_contacts (
|
||||
id bigint NOT NULL,
|
||||
name character varying,
|
||||
registry_code character varying,
|
||||
status character varying,
|
||||
created_at timestamp(6) without time zone NOT NULL,
|
||||
updated_at timestamp(6) without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: business_registry_contacts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.business_registry_contacts_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: business_registry_contacts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.business_registry_contacts_id_seq OWNED BY public.business_registry_contacts.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: certificates; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -541,7 +574,6 @@ ALTER SEQUENCE public.certificates_id_seq OWNED BY public.certificates.id;
|
|||
--
|
||||
|
||||
CREATE TABLE public.contact_requests (
|
||||
|
||||
id integer NOT NULL,
|
||||
whois_record_id integer NOT NULL,
|
||||
secret character varying NOT NULL,
|
||||
|
@ -553,7 +585,6 @@ CREATE TABLE public.contact_requests (
|
|||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
message_id character varying
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
@ -575,6 +606,7 @@ CREATE SEQUENCE public.contact_requests_id_seq
|
|||
|
||||
ALTER SEQUENCE public.contact_requests_id_seq OWNED BY public.contact_requests.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: contacts; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -2766,6 +2798,13 @@ ALTER TABLE ONLY public.blocked_domains ALTER COLUMN id SET DEFAULT nextval('pub
|
|||
ALTER TABLE ONLY public.bounced_mail_addresses ALTER COLUMN id SET DEFAULT nextval('public.bounced_mail_addresses_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: business_registry_contacts id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.business_registry_contacts ALTER COLUMN id SET DEFAULT nextval('public.business_registry_contacts_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: certificates id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -3230,6 +3269,14 @@ ALTER TABLE ONLY public.bounced_mail_addresses
|
|||
ADD CONSTRAINT bounced_mail_addresses_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: business_registry_contacts business_registry_contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.business_registry_contacts
|
||||
ADD CONSTRAINT business_registry_contacts_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: certificates certificates_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -5104,6 +5151,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||
('20200916125326'),
|
||||
('20200917104213'),
|
||||
('20200921084356'),
|
||||
('20210215101019');
|
||||
('20210215101019'),
|
||||
('20210616112332');
|
||||
|
||||
|
||||
|
|
7
lib/tasks/scan_csv_registry_business_contacts.rake
Normal file
7
lib/tasks/scan_csv_registry_business_contacts.rake
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace :collect_csv_data do
|
||||
desc 'Import from csv registry business contact into BusinessRegistryContact model'
|
||||
|
||||
task business_contacts: :environment do
|
||||
ScanCsvRegistryBusinnesContactsJob.perform_later
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue