Commit 292c3bed by Đường Sỹ Hoàng

First commit

parent f5b0ef08
...@@ -32,6 +32,7 @@ gem "nokogiri" ...@@ -32,6 +32,7 @@ gem "nokogiri"
gem "mechanize" gem "mechanize"
gem "rubysl-open-uri" gem "rubysl-open-uri"
gem "whenever", require: false gem "whenever", require: false
gem "activerecord-import"
group :development, :test do group :development, :test do
# Call "byebug" anywhere in the code to stop execution and get a debugger console # Call "byebug" anywhere in the code to stop execution and get a debugger console
......
...@@ -45,6 +45,8 @@ GEM ...@@ -45,6 +45,8 @@ GEM
activerecord (6.0.1) activerecord (6.0.1)
activemodel (= 6.0.1) activemodel (= 6.0.1)
activesupport (= 6.0.1) activesupport (= 6.0.1)
activerecord-import (1.0.3)
activerecord (>= 3.2)
activestorage (6.0.1) activestorage (6.0.1)
actionpack (= 6.0.1) actionpack (= 6.0.1)
activejob (= 6.0.1) activejob (= 6.0.1)
...@@ -246,6 +248,7 @@ PLATFORMS ...@@ -246,6 +248,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
activerecord-import
bootsnap (>= 1.4.2) bootsnap (>= 1.4.2)
byebug byebug
capybara (>= 2.15) capybara (>= 2.15)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
class ChangeIntegerLimitJob < ActiveRecord::Migration[6.0]
def change
change_column :jobs, :company_id, :integer, limit: 8
end
end
class AddColumnsToJob < ActiveRecord::Migration[6.0]
def change
add_column :jobs, :location, :string
add_column :jobs, :company_name, :string
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,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: 2019_12_05_082359) do ActiveRecord::Schema.define(version: 2019_12_10_035904) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
...@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 2019_12_05_082359) do ...@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 2019_12_05_082359) do
t.string "title" t.string "title"
t.text "description" t.text "description"
t.text "short_description" t.text "short_description"
t.integer "company_id" t.bigint "company_id"
t.decimal "salary", precision: 10 t.decimal "salary", precision: 10
t.integer "currency" t.integer "currency"
t.text "requirement" t.text "requirement"
...@@ -66,6 +66,8 @@ ActiveRecord::Schema.define(version: 2019_12_05_082359) do ...@@ -66,6 +66,8 @@ ActiveRecord::Schema.define(version: 2019_12_05_082359) do
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.string "code" t.string "code"
t.string "location"
t.string "company_name"
end end
create_table "user_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "user_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
......
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
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