Project initialize
This commit is contained in:
10
db/migrate/20260120093711_create_tasks.rb
Normal file
10
db/migrate/20260120093711_create_tasks.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class CreateTasks < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
create_table :tasks do |t|
|
||||
t.string :title
|
||||
t.boolean :completed
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
5
db/migrate/20260120101432_add_description_to_tasks.rb
Normal file
5
db/migrate/20260120101432_add_description_to_tasks.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddDescriptionToTasks < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_column :tasks, :description, :text
|
||||
end
|
||||
end
|
||||
11
db/migrate/20260121074647_create_departments.rb
Normal file
11
db/migrate/20260121074647_create_departments.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class CreateDepartments < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
create_table :departments do |t|
|
||||
t.string :name, null: false
|
||||
t.text :description
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :departments, :name, unique: true
|
||||
end
|
||||
end
|
||||
14
db/migrate/20260121074803_create_users.rb
Normal file
14
db/migrate/20260121074803_create_users.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class CreateUsers < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
create_table :users do |t|
|
||||
t.string :name, null: false
|
||||
t.string :email, null: false
|
||||
t.string :role, null: false, default: 'employee'
|
||||
t.references :department, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :users, :email, unique: true
|
||||
add_index :users, :role
|
||||
end
|
||||
end
|
||||
39
db/migrate/20260121075301_add_devise_to_users.rb
Normal file
39
db/migrate/20260121075301_add_devise_to_users.rb
Normal file
@@ -0,0 +1,39 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddDeviseToUsers < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
change_table :users do |t|
|
||||
## Database authenticatable
|
||||
t.string :encrypted_password, null: false, default: ""
|
||||
|
||||
## Recoverable
|
||||
t.string :reset_password_token
|
||||
t.datetime :reset_password_sent_at
|
||||
|
||||
## Rememberable
|
||||
t.datetime :remember_created_at
|
||||
|
||||
## Trackable
|
||||
t.integer :sign_in_count, default: 0, null: false
|
||||
t.datetime :current_sign_in_at
|
||||
t.datetime :last_sign_in_at
|
||||
t.string :current_sign_in_ip
|
||||
t.string :last_sign_in_ip
|
||||
|
||||
## Confirmable
|
||||
t.string :confirmation_token
|
||||
t.datetime :confirmed_at
|
||||
t.datetime :confirmation_sent_at
|
||||
t.string :unconfirmed_email # Only if using reconfirmable
|
||||
|
||||
## Lockable
|
||||
t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
||||
t.string :unlock_token # Only if unlock strategy is :email or : both
|
||||
t.datetime :locked_at
|
||||
end
|
||||
|
||||
add_index :users, :reset_password_token, unique: true
|
||||
add_index :users, :confirmation_token, unique: true
|
||||
add_index :users, :unlock_token, unique: true
|
||||
end
|
||||
end
|
||||
13
db/migrate/20260122034424_add_company_fields_to_tasks.rb
Normal file
13
db/migrate/20260122034424_add_company_fields_to_tasks.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class AddCompanyFieldsToTasks < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
add_column :tasks, :priority, :string, null: false, default: 'planning'
|
||||
add_column :tasks, :status, :string, null: false, default: 'open'
|
||||
add_reference :tasks, :department, foreign_key: true
|
||||
add_reference :tasks, :assignee, foreign_key: { to_table: :users }
|
||||
add_reference :tasks, :creator, foreign_key: { to_table: :users }
|
||||
|
||||
add_index :tasks, :priority
|
||||
add_index :tasks, :status
|
||||
add_index :tasks, [:department_id, :status]
|
||||
end
|
||||
end
|
||||
12
db/migrate/20260122043706_create_task_activities.rb
Normal file
12
db/migrate/20260122043706_create_task_activities.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class CreateTaskActivities < ActiveRecord::Migration[5.1]
|
||||
def change
|
||||
create_table :task_activities do |t|
|
||||
t.references :task, foreign_key: true
|
||||
t.references :user, foreign_key: true
|
||||
t.string :action
|
||||
t.text :details
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
84
db/schema.rb
Normal file
84
db/schema.rb
Normal file
@@ -0,0 +1,84 @@
|
||||
# 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.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20260122043706) do
|
||||
|
||||
create_table "departments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.text "description"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["name"], name: "index_departments_on_name", unique: true
|
||||
end
|
||||
|
||||
create_table "task_activities", force: :cascade do |t|
|
||||
t.integer "task_id"
|
||||
t.integer "user_id"
|
||||
t.string "action"
|
||||
t.text "details"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["task_id"], name: "index_task_activities_on_task_id"
|
||||
t.index ["user_id"], name: "index_task_activities_on_user_id"
|
||||
end
|
||||
|
||||
create_table "tasks", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.boolean "completed"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "description"
|
||||
t.string "priority", default: "planning", null: false
|
||||
t.string "status", default: "open", null: false
|
||||
t.integer "department_id"
|
||||
t.integer "assignee_id"
|
||||
t.integer "creator_id"
|
||||
t.index ["assignee_id"], name: "index_tasks_on_assignee_id"
|
||||
t.index ["creator_id"], name: "index_tasks_on_creator_id"
|
||||
t.index ["department_id", "status"], name: "index_tasks_on_department_id_and_status"
|
||||
t.index ["department_id"], name: "index_tasks_on_department_id"
|
||||
t.index ["priority"], name: "index_tasks_on_priority"
|
||||
t.index ["status"], name: "index_tasks_on_status"
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "email", null: false
|
||||
t.string "role", default: "employee", null: false
|
||||
t.integer "department_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", default: 0, null: false
|
||||
t.datetime "current_sign_in_at"
|
||||
t.datetime "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "unconfirmed_email"
|
||||
t.integer "failed_attempts", default: 0, null: false
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
||||
t.index ["department_id"], name: "index_users_on_department_id"
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
t.index ["role"], name: "index_users_on_role"
|
||||
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
|
||||
end
|
||||
|
||||
end
|
||||
127
db/seeds.rb
Normal file
127
db/seeds.rb
Normal file
@@ -0,0 +1,127 @@
|
||||
# This file should contain all the record creation needed to seed the database with its default values.
|
||||
|
||||
puts "Creating departments..."
|
||||
# Create default departments
|
||||
Department.find_or_create_by!(name: 'Engineering') do |dept|
|
||||
dept.description = 'Software development and technical operations'
|
||||
end
|
||||
|
||||
Department.find_or_create_by!(name: 'Marketing') do |dept|
|
||||
dept.description = 'Marketing campaigns and brand management'
|
||||
end
|
||||
|
||||
Department.find_or_create_by!(name: 'Human Resources') do |dept|
|
||||
dept.description = 'Employee management and company culture'
|
||||
end
|
||||
|
||||
Department.find_or_create_by!(name: 'Sales') do |dept|
|
||||
dept.description = 'Customer relations and revenue generation'
|
||||
end
|
||||
|
||||
puts "Creating users..."
|
||||
# Create admin user
|
||||
admin = User.find_or_create_by!(email: 'admin@company.com') do |user|
|
||||
user.name = 'System Admin'
|
||||
user.password = 'password123'
|
||||
user.role = 'admin'
|
||||
end
|
||||
|
||||
puts "Creating manager users..."
|
||||
# Create manager users
|
||||
hr_manager = User.find_or_create_by!(email: 'hr@company.com') do |user|
|
||||
user.name = 'HR Manager'
|
||||
user.password = 'password123'
|
||||
user.role = 'manager'
|
||||
user.department = Department.find_by(name: 'Human Resources')
|
||||
end
|
||||
|
||||
eng_manager = User.find_or_create_by!(email: 'eng@company.com') do |user|
|
||||
user.name = 'Engineering Manager'
|
||||
user.password = 'password123'
|
||||
user.role = 'manager'
|
||||
user.department = Department.find_by(name: 'Engineering')
|
||||
end
|
||||
|
||||
puts "Creating employee users..."
|
||||
# Create employee users
|
||||
john_employee = User.find_or_create_by!(email: 'john@company.com') do |user|
|
||||
user.name = 'John Doe'
|
||||
user.password = 'password123'
|
||||
user.role = 'employee'
|
||||
user.department = Department.find_by(name: 'Engineering')
|
||||
end
|
||||
|
||||
jane_employee = User.find_or_create_by!(email: 'jane@company.com') do |user|
|
||||
user.name = 'Jane Smith'
|
||||
user.password = 'password123'
|
||||
user.role = 'employee'
|
||||
user.department = Department.find_by(name: 'Marketing')
|
||||
end
|
||||
|
||||
bob_employee = User.find_or_create_by!(email: 'bob@company.com') do |user|
|
||||
user.name = 'Bob Johnson'
|
||||
user.password = 'password123'
|
||||
user.role = 'employee'
|
||||
user.department = Department.find_by(name: 'Sales')
|
||||
end
|
||||
|
||||
puts "Creating tasks..."
|
||||
# Get department references
|
||||
eng_dept = Department.find_by(name: 'Engineering')
|
||||
hr_dept = Department.find_by(name: 'Human Resources')
|
||||
marketing_dept = Department.find_by(name: 'Marketing')
|
||||
sales_dept = Department.find_by(name: 'Sales')
|
||||
|
||||
# Create sample tasks
|
||||
Task.find_or_create_by!(title: 'Setup development environment') do |task|
|
||||
task.description = 'Configure the development server and database connections'
|
||||
task.priority = 'planning'
|
||||
task.status = 'open'
|
||||
task.department = eng_dept
|
||||
task.creator = eng_manager
|
||||
task.assignee = john_employee
|
||||
end
|
||||
|
||||
Task.find_or_create_by!(title: 'Review Q1 marketing strategy') do |task|
|
||||
task.description = 'Analyze marketing campaign performance and plan Q2 initiatives'
|
||||
task.priority = 'review'
|
||||
task.status = 'in_progress'
|
||||
task.department = marketing_dept
|
||||
task.creator = eng_manager
|
||||
task.assignee = jane_employee
|
||||
end
|
||||
|
||||
Task.find_or_create_by!(title: 'Update employee handbook') do |task|
|
||||
task.description = 'Review and update company policies for 2024'
|
||||
task.priority = 'approval'
|
||||
task.status = 'open'
|
||||
task.department = hr_dept
|
||||
task.creator = hr_manager
|
||||
end
|
||||
|
||||
Task.find_or_create_by!(title: 'Client meeting preparation') do |task|
|
||||
task.description = 'Prepare presentation materials and agenda for upcoming client meeting'
|
||||
task.priority = 'urgent'
|
||||
task.status = 'in_progress'
|
||||
task.department = sales_dept
|
||||
task.creator = eng_manager
|
||||
task.assignee = bob_employee
|
||||
end
|
||||
|
||||
Task.find_or_create_by!(title: 'Database optimization') do |task|
|
||||
task.description = 'Optimize database queries and improve performance'
|
||||
task.priority = 'execution'
|
||||
task.status = 'open'
|
||||
task.department = eng_dept
|
||||
task.creator = eng_manager
|
||||
end
|
||||
|
||||
puts "Seed data created successfully!"
|
||||
puts "\nLogin credentials:"
|
||||
puts "Admin: admin@company.com / password123"
|
||||
puts "HR Manager: hr@company.com / password123"
|
||||
puts "Engineering Manager: eng@company.com / password123"
|
||||
puts "Employees:"
|
||||
puts "- john@company.com / password123"
|
||||
puts "- jane@company.com / password123"
|
||||
puts "- bob@company.com / password123"
|
||||
Reference in New Issue
Block a user