Commit 59fe41f7 by Mai Hoang Thai Ha

fixed association, add model option

parent 35560bfd
...@@ -5,8 +5,8 @@ ruby '3.0.1' ...@@ -5,8 +5,8 @@ ruby '3.0.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.2' gem 'rails', '~> 6.1.3', '>= 6.1.3.2'
# Use sqlite3 as the database for Active Record # Use mysql2 as the database for Active Record
gem 'sqlite3', '~> 1.4' gem 'mysql2', '~> 0.5'
# Use Puma as the app server # Use Puma as the app server
gem 'puma', '~> 5.0' gem 'puma', '~> 5.0'
# Use SCSS for stylesheets # Use SCSS for stylesheets
......
...@@ -100,6 +100,7 @@ GEM ...@@ -100,6 +100,7 @@ GEM
mini_mime (1.1.0) mini_mime (1.1.0)
minitest (5.14.4) minitest (5.14.4)
msgpack (1.4.2) msgpack (1.4.2)
mysql2 (0.5.3)
nio4r (2.5.7) nio4r (2.5.7)
nokogiri (1.11.7-x86_64-linux) nokogiri (1.11.7-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
...@@ -182,7 +183,6 @@ GEM ...@@ -182,7 +183,6 @@ GEM
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sqlite3 (1.4.2)
temple (0.8.2) temple (0.8.2)
thor (1.1.0) thor (1.1.0)
tilt (2.0.10) tilt (2.0.10)
...@@ -221,6 +221,7 @@ DEPENDENCIES ...@@ -221,6 +221,7 @@ DEPENDENCIES
capybara (>= 3.26) capybara (>= 3.26)
jbuilder (~> 2.7) jbuilder (~> 2.7)
listen (~> 3.3) listen (~> 3.3)
mysql2 (~> 0.5)
pry-nav (~> 0.3.0) pry-nav (~> 0.3.0)
pry-rails (~> 0.3.9) pry-rails (~> 0.3.9)
puma (~> 5.0) puma (~> 5.0)
...@@ -230,7 +231,6 @@ DEPENDENCIES ...@@ -230,7 +231,6 @@ DEPENDENCIES
selenium-webdriver selenium-webdriver
slim-rails (~> 3.2) slim-rails (~> 3.2)
spring spring
sqlite3 (~> 1.4)
turbolinks (~> 5) turbolinks (~> 5)
tzinfo-data tzinfo-data
web-console (>= 4.1.0) web-console (>= 4.1.0)
......
class Company < ApplicationRecord class Company < ApplicationRecord
has_many :jobs has_many :jobs, dependent: :destroy
end end
...@@ -2,7 +2,7 @@ class Job < ApplicationRecord ...@@ -2,7 +2,7 @@ class Job < ApplicationRecord
has_and_belongs_to_many :industries has_and_belongs_to_many :industries
has_and_belongs_to_many :cities has_and_belongs_to_many :cities
belongs_to :company belongs_to :company
has_many :apply_jobs has_many :apply_jobs, dependent: :destroy
has_many :favorite_jobs has_many :favorite_jobs, dependent: :destroy
has_many :history_job has_many :history_job, dependent: :destroy
end end
class User < ApplicationRecord class User < ApplicationRecord
has_many :apply_jobs has_many :apply_jobs, dependent: :destroy
has_many :favorite_jobs has_many :favorite_jobs, dependent: :destroy
has_many :history_jobs has_many :history_jobs, dependent: :destroy
has_one_attached :cv has_one_attached :cv
end end
# SQLite. Versions 3.8.0 and up are supported. # MySQL. Versions 5.5.8 and up are supported.
# gem install sqlite3
# #
# Ensure the SQLite 3 gem is defined in your Gemfile # Install the MySQL driver
# gem 'sqlite3' # gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# https://dev.mysql.com/doc/refman/5.7/en/password-hashing.html
# #
default: &default default: &default
adapter: sqlite3 adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000 username: root
password: 'admin'
socket: /var/run/mysqld/mysqld.sock
development: development:
<<: *default <<: *default
database: db/development.sqlite3 database: VenJob_development
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production. # Do not set this db to the same as development or production.
test: test:
<<: *default <<: *default
database: db/test.sqlite3 database: VenJob_test
# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
# DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production: production:
<<: *default <<: *default
database: db/production.sqlite3 database: VenJob_production
username: VenJob
password: <%= ENV['VENJOB_DATABASE_PASSWORD'] %>
...@@ -2,8 +2,6 @@ class CreateCompanies < ActiveRecord::Migration[6.1] ...@@ -2,8 +2,6 @@ class CreateCompanies < ActiveRecord::Migration[6.1]
def change def change
create_table :companies do |t| create_table :companies do |t|
t.string :name t.string :name
t.text :description
t.string :address
t.timestamps t.timestamps
end end
......
class IndustriesJobs < ActiveRecord::Migration[6.1]
def change
end
end
class CitiesJobs < ActiveRecord::Migration[6.1]
def change
end
end
class CreateIndustriesJobs < ActiveRecord::Migration[6.1]
def change
create_table :industries_jobs do |t|
t.references :job, null: false, foreign_key: true
t.references :industry, null: false, foreign_key: true
t.timestamps
end
end
end
class CreateCitiesJobs < ActiveRecord::Migration[6.1]
def change
create_table :cities_jobs do |t|
t.references :job, null: false, foreign_key: true
t.references :city, null: false, foreign_key: true
t.timestamps
end
end
end
...@@ -10,19 +10,19 @@ ...@@ -10,19 +10,19 @@
# #
# 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: 2021_07_06_093559) do ActiveRecord::Schema.define(version: 2021_07_20_055614) do
create_table "active_storage_attachments", force: :cascade do |t| create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "record_type", null: false t.string "record_type", null: false
t.integer "record_id", null: false t.bigint "record_id", null: false
t.integer "blob_id", null: false t.bigint "blob_id", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end end
create_table "active_storage_blobs", force: :cascade do |t| create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "key", null: false t.string "key", null: false
t.string "filename", null: false t.string "filename", null: false
t.string "content_type" t.string "content_type"
...@@ -34,61 +34,77 @@ ActiveRecord::Schema.define(version: 2021_07_06_093559) do ...@@ -34,61 +34,77 @@ ActiveRecord::Schema.define(version: 2021_07_06_093559) do
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end end
create_table "active_storage_variant_records", force: :cascade do |t| create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "blob_id", null: false t.bigint "blob_id", null: false
t.string "variation_digest", null: false t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end end
create_table "apply_jobs", force: :cascade do |t| create_table "apply_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "job_id", null: false t.bigint "job_id", null: false
t.integer "user_id", null: false t.bigint "user_id", null: false
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.index ["job_id"], name: "index_apply_jobs_on_job_id" t.index ["job_id"], name: "index_apply_jobs_on_job_id"
t.index ["user_id"], name: "index_apply_jobs_on_user_id" t.index ["user_id"], name: "index_apply_jobs_on_user_id"
end end
create_table "cities", force: :cascade do |t| create_table "cities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name" t.string "name"
t.integer "region" t.integer "region"
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
end end
create_table "companies", force: :cascade do |t| create_table "cities_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "job_id", null: false
t.bigint "city_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["city_id"], name: "index_cities_jobs_on_city_id"
t.index ["job_id"], name: "index_cities_jobs_on_job_id"
end
create_table "companies", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name" t.string "name"
t.text "description"
t.string "address"
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
end end
create_table "favorite_jobs", force: :cascade do |t| create_table "favorite_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "job_id", null: false t.bigint "job_id", null: false
t.integer "user_id", null: false t.bigint "user_id", null: false
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.index ["job_id"], name: "index_favorite_jobs_on_job_id" t.index ["job_id"], name: "index_favorite_jobs_on_job_id"
t.index ["user_id"], name: "index_favorite_jobs_on_user_id" t.index ["user_id"], name: "index_favorite_jobs_on_user_id"
end end
create_table "history_jobs", force: :cascade do |t| create_table "history_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.integer "job_id", null: false t.bigint "job_id", null: false
t.integer "user_id", null: false t.bigint "user_id", null: false
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.index ["job_id"], name: "index_history_jobs_on_job_id" t.index ["job_id"], name: "index_history_jobs_on_job_id"
t.index ["user_id"], name: "index_history_jobs_on_user_id" t.index ["user_id"], name: "index_history_jobs_on_user_id"
end end
create_table "industries", force: :cascade do |t| create_table "industries", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name" t.string "name"
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
end end
create_table "jobs", force: :cascade do |t| create_table "industries_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "job_id", null: false
t.bigint "industry_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["industry_id"], name: "index_industries_jobs_on_industry_id"
t.index ["job_id"], name: "index_industries_jobs_on_job_id"
end
create_table "jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "title" t.string "title"
t.string "type" t.string "type"
t.string "salary" t.string "salary"
...@@ -99,13 +115,13 @@ ActiveRecord::Schema.define(version: 2021_07_06_093559) do ...@@ -99,13 +115,13 @@ ActiveRecord::Schema.define(version: 2021_07_06_093559) do
t.text "benefit" t.text "benefit"
t.text "requirement" t.text "requirement"
t.text "other_info" t.text "other_info"
t.integer "company_id", null: false t.bigint "company_id", null: false
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.index ["company_id"], name: "index_jobs_on_company_id" t.index ["company_id"], name: "index_jobs_on_company_id"
end end
create_table "users", force: :cascade do |t| create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name" t.string "name"
t.string "email", null: false t.string "email", null: false
t.string "password_digest" t.string "password_digest"
...@@ -126,9 +142,13 @@ ActiveRecord::Schema.define(version: 2021_07_06_093559) do ...@@ -126,9 +142,13 @@ ActiveRecord::Schema.define(version: 2021_07_06_093559) do
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "apply_jobs", "jobs" add_foreign_key "apply_jobs", "jobs"
add_foreign_key "apply_jobs", "users" add_foreign_key "apply_jobs", "users"
add_foreign_key "cities_jobs", "cities"
add_foreign_key "cities_jobs", "jobs"
add_foreign_key "favorite_jobs", "jobs" add_foreign_key "favorite_jobs", "jobs"
add_foreign_key "favorite_jobs", "users" add_foreign_key "favorite_jobs", "users"
add_foreign_key "history_jobs", "jobs" add_foreign_key "history_jobs", "jobs"
add_foreign_key "history_jobs", "users" add_foreign_key "history_jobs", "users"
add_foreign_key "industries_jobs", "industries"
add_foreign_key "industries_jobs", "jobs"
add_foreign_key "jobs", "companies" add_foreign_key "jobs", "companies"
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