Commit ca4035a9 by phuctmZigexn

Merge branch 'Task/3_create_database_migration' into 'master'

Create migration, add option to model and install Active Record

See merge request !3
parents c4f21c57 59fe41f7
......@@ -5,8 +5,8 @@ ruby '3.0.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.3', '>= 6.1.3.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use mysql2 as the database for Active Record
gem 'mysql2', '~> 0.5'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
......
......@@ -100,6 +100,7 @@ GEM
mini_mime (1.1.0)
minitest (5.14.4)
msgpack (1.4.2)
mysql2 (0.5.3)
nio4r (2.5.7)
nokogiri (1.11.7-x86_64-linux)
racc (~> 1.4)
......@@ -182,7 +183,6 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
temple (0.8.2)
thor (1.1.0)
tilt (2.0.10)
......@@ -221,6 +221,7 @@ DEPENDENCIES
capybara (>= 3.26)
jbuilder (~> 2.7)
listen (~> 3.3)
mysql2 (~> 0.5)
pry-nav (~> 0.3.0)
pry-rails (~> 0.3.9)
puma (~> 5.0)
......@@ -230,7 +231,6 @@ DEPENDENCIES
selenium-webdriver
slim-rails (~> 3.2)
spring
sqlite3 (~> 1.4)
turbolinks (~> 5)
tzinfo-data
web-console (>= 4.1.0)
......
class ApplyJob < ApplicationRecord
belongs_to :job
belongs_to :user
has_one_attached :cv
end
class City < ApplicationRecord
has_and_belongs_to_many :jobs
end
class Company < ApplicationRecord
has_many :jobs, dependent: :destroy
end
class FavoriteJob < ApplicationRecord
belongs_to :job
belongs_to :user
end
class HistoryJob < ApplicationRecord
belongs_to :job
belongs_to :user
end
class Industry < ApplicationRecord
has_and_belongs_to_many :jobs
end
class Job < ApplicationRecord
has_and_belongs_to_many :industries
has_and_belongs_to_many :cities
belongs_to :company
has_many :apply_jobs, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy
has_many :history_job, dependent: :destroy
end
class User < ApplicationRecord
has_many :apply_jobs, dependent: :destroy
has_many :favorite_jobs, dependent: :destroy
has_many :history_jobs, dependent: :destroy
has_one_attached :cv
end
# SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
# MySQL. Versions 5.5.8 and up are supported.
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
# Install the MySQL driver
# 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
adapter: sqlite3
adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
username: root
password: 'admin'
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
database: db/development.sqlite3
database: VenJob_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *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:
<<: *default
database: db/production.sqlite3
database: VenJob_production
username: VenJob
password: <%= ENV['VENJOB_DATABASE_PASSWORD'] %>
class CreateCompanies < ActiveRecord::Migration[6.1]
def change
create_table :companies do |t|
t.string :name
t.timestamps
end
end
end
class CreateJobs < ActiveRecord::Migration[6.1]
def change
create_table :jobs do |t|
t.string :title
t.string :type
t.string :salary
t.string :experience
t.string :position
t.datetime :expiration_date
t.text :description
t.text :benefit
t.text :requirement
t.text :other_info
t.references :company, null: false, foreign_key: true
t.timestamps
end
end
end
class CreateIndustries < ActiveRecord::Migration[6.1]
def change
create_table :industries do |t|
t.string :name
t.timestamps
end
end
end
class CreateCities < ActiveRecord::Migration[6.1]
def change
create_table :cities do |t|
t.string :name
t.integer :region
t.timestamps
end
end
end
class CreateUsers < ActiveRecord::Migration[6.1]
def change
create_table :users do |t|
t.string :name
t.string :email, null: false
t.string :password_digest
t.string :remember_digest
t.boolean :admin, default: false
t.string :activation_digest
t.boolean :activated, default: false
t.datetime :activated_at
t.string :password_reset_digest
t.datetime :password_reset_sent_at
t.timestamps
end
add_index :users, :email, unique: true
add_index :users, :password_reset_digest, unique: true
end
end
class CreateApplyJobs < ActiveRecord::Migration[6.1]
def change
create_table :apply_jobs do |t|
t.references :job, null: false, foreign_key: true
t.references :user, null: false, foreign_key: true
t.timestamps
end
end
end
class CreateFavoriteJobs < ActiveRecord::Migration[6.1]
def change
create_table :favorite_jobs do |t|
t.references :job, null: false, foreign_key: true
t.references :user, null: false, foreign_key: true
t.timestamps
end
end
end
class CreateHistoryJobs < ActiveRecord::Migration[6.1]
def change
create_table :history_jobs do |t|
t.references :job, null: false, foreign_key: true
t.references :user, null: false, foreign_key: true
t.timestamps
end
end
end
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
def change
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false
t.index [ :key ], unique: true
end
create_table :active_storage_attachments do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false
t.references :blob, null: false
t.datetime :created_at, null: false
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
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
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_07_20_055614) do
create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
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
end
create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.string "service_name", null: false
t.bigint "byte_size", null: false
t.string "checksum", null: false
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end
create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
create_table "apply_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "job_id", null: false
t.bigint "user_id", null: false
t.datetime "created_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 ["user_id"], name: "index_apply_jobs_on_user_id"
end
create_table "cities", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name"
t.integer "region"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
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.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "favorite_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "job_id", null: false
t.bigint "user_id", null: false
t.datetime "created_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 ["user_id"], name: "index_favorite_jobs_on_user_id"
end
create_table "history_jobs", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "job_id", null: false
t.bigint "user_id", null: false
t.datetime "created_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 ["user_id"], name: "index_history_jobs_on_user_id"
end
create_table "industries", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
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 "type"
t.string "salary"
t.string "experience"
t.string "position"
t.datetime "expiration_date"
t.text "description"
t.text "benefit"
t.text "requirement"
t.text "other_info"
t.bigint "company_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["company_id"], name: "index_jobs_on_company_id"
end
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name"
t.string "email", null: false
t.string "password_digest"
t.string "remember_digest"
t.boolean "admin", default: false
t.string "activation_digest"
t.boolean "activated", default: false
t.datetime "activated_at"
t.string "password_reset_digest"
t.datetime "password_reset_sent_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["password_reset_digest"], name: "index_users_on_password_reset_digest", unique: true
end
add_foreign_key "active_storage_attachments", "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", "users"
add_foreign_key "cities_jobs", "cities"
add_foreign_key "cities_jobs", "jobs"
add_foreign_key "favorite_jobs", "jobs"
add_foreign_key "favorite_jobs", "users"
add_foreign_key "history_jobs", "jobs"
add_foreign_key "history_jobs", "users"
add_foreign_key "industries_jobs", "industries"
add_foreign_key "industries_jobs", "jobs"
add_foreign_key "jobs", "companies"
end
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
job: one
user: one
two:
job: two
user: two
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
region: 1
two:
name: MyString
region: 1
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
description: MyText
address: MyString
two:
name: MyString
description: MyText
address: MyString
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
job: one
user: one
two:
job: two
user: two
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
job: one
user: one
two:
job: two
user: two
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
type:
salary: MyString
experience: MyString
position: MyString
expiration_date: 2021-07-06 16:22:30
description: MyText
benefit: MyText
requirement: MyText
other_info: MyText
company: one
two:
title: MyString
type:
salary: MyString
experience: MyString
position: MyString
expiration_date: 2021-07-06 16:22:30
description: MyText
benefit: MyText
requirement: MyText
other_info: MyText
company: two
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
email: MyString
password_digest: MyString
remember_digest: MyString
admin: false
activation_digest: MyString
activated: false
activated_at: 2021-07-06 16:29:05
password_reset_digest: MyString
password_reset_sent_at: 2021-07-06 16:29:05
two:
name: MyString
email: MyString
password_digest: MyString
remember_digest: MyString
admin: false
activation_digest: MyString
activated: false
activated_at: 2021-07-06 16:29:05
password_reset_digest: MyString
password_reset_sent_at: 2021-07-06 16:29:05
require "test_helper"
class ApplyJobTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require "test_helper"
class CityTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require "test_helper"
class CompanyTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require "test_helper"
class FavoriteJobTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require "test_helper"
class HistoryJobTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require "test_helper"
class IndustryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require "test_helper"
class JobTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require "test_helper"
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# 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