Commit 09737968 by Đường Sỹ Hoàng

Merge tasks

parent fcc712c5
class CreateCompanies < ActiveRecord::Migration[6.0] class CreateCompanies < ActiveRecord::Migration[6.0]
def change def change
create_table :companies do |t| create_table :companies do |t|
t.string :email, null: false, default: "" t.string :email
t.text :description t.text :description
t.string :address t.string :address
t.string :url t.string :url
......
class ChangeIntegerLimitJob < ActiveRecord::Migration[6.0]
def change
change_column :jobs, :company_id, :integer, limit: 8
end
end
...@@ -27,7 +27,7 @@ ActiveRecord::Schema.define(version: 2019_12_10_035904) do ...@@ -27,7 +27,7 @@ ActiveRecord::Schema.define(version: 2019_12_10_035904) do
end end
create_table "companies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "companies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email"
t.text "description" t.text "description"
t.string "address" t.string "address"
t.string "url" t.string "url"
...@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 2019_12_10_035904) do ...@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 2019_12_10_035904) do
t.string "title" t.string "title"
t.text "description" t.text "description"
t.text "short_description" t.text "short_description"
t.bigint "company_id" t.integer "company_id"
t.decimal "salary", precision: 10 t.decimal "salary", precision: 10
t.integer "currency" t.integer "currency"
t.text "requirement" t.text "requirement"
......
...@@ -2,25 +2,25 @@ require "csv" ...@@ -2,25 +2,25 @@ require "csv"
namespace :import_job_csv do namespace :import_job_csv do
desc "Import CSV file into database" desc "Import CSV file into database"
task create_job: :environment do task import_job: :environment do
file = "db/Venjob.csv" CSV.foreach("db/Venjob.csv", headers: true) do |row|
CSV.foreach(file, headers: true) do |row| company_params = {
job_hash = row.to_hash email: row["contact email"],
job = Job.where(id: job_hash["id"]) name: row["company name"],
if job.count == 1 address: row["company address"],
job.first.update_attributes(job_hash) code: row["company id"]
else }
Job.create!({ Company.create!(company_params)
company_id: row[4], job_params = {
company_name: row[5], company_id: Company.find_by(code: row["company id"]).id,
location: row[16], location: row["workplace"],
title: row[9], title: row["name"],
description: row[7], description: row["description"],
position: row[8], position: row["level"],
salary: row[11], salary: row["salary"],
requirement: row[10] requirement: row["requirement"]
}) }
end Job.create!(job_params)
end end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment