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

Merge tasks

parent fcc712c5
class CreateCompanies < ActiveRecord::Migration[6.0]
def change
create_table :companies do |t|
t.string :email, null: false, default: ""
t.string :email
t.text :description
t.string :address
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
end
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.string "address"
t.string "url"
......@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 2019_12_10_035904) do
t.string "title"
t.text "description"
t.text "short_description"
t.bigint "company_id"
t.integer "company_id"
t.decimal "salary", precision: 10
t.integer "currency"
t.text "requirement"
......
......@@ -2,25 +2,25 @@ require "csv"
namespace :import_job_csv do
desc "Import CSV file into database"
task create_job: :environment do
file = "db/Venjob.csv"
CSV.foreach(file, headers: true) do |row|
job_hash = row.to_hash
job = Job.where(id: job_hash["id"])
if job.count == 1
job.first.update_attributes(job_hash)
else
Job.create!({
company_id: row[4],
company_name: row[5],
location: row[16],
title: row[9],
description: row[7],
position: row[8],
salary: row[11],
requirement: row[10]
})
end
task import_job: :environment do
CSV.foreach("db/Venjob.csv", headers: true) do |row|
company_params = {
email: row["contact email"],
name: row["company name"],
address: row["company address"],
code: row["company id"]
}
Company.create!(company_params)
job_params = {
company_id: Company.find_by(code: row["company id"]).id,
location: row["workplace"],
title: row["name"],
description: row["description"],
position: row["level"],
salary: row["salary"],
requirement: row["requirement"]
}
Job.create!(job_params)
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