ecom_core 1.2.3 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/app/constants/ecom/core/status_constants.rb +11 -0
  3. data/app/models/ecom/core/attendance_sheet.rb +38 -26
  4. data/app/models/ecom/core/attendance_sheet_entry.rb +1 -1
  5. data/app/models/ecom/core/company.rb +10 -0
  6. data/app/models/ecom/core/crew.rb +4 -4
  7. data/app/models/ecom/core/crew_overtime.rb +6 -1
  8. data/app/models/ecom/core/crew_time.rb +8 -3
  9. data/app/models/ecom/core/overtime_sheet.rb +18 -15
  10. data/app/models/ecom/core/payment_detail.rb +1 -1
  11. data/app/models/ecom/core/payroll.rb +5 -0
  12. data/app/models/ecom/core/project.rb +4 -0
  13. data/app/models/ecom/core/project_crew.rb +15 -0
  14. data/config/database.ci.yml +1 -0
  15. data/db/migrate/20190101085530_create_ecom_core_companies.rb +14 -0
  16. data/db/migrate/20191119012030_create_ecom_core_task_templates.rb +4 -3
  17. data/db/migrate/20191119013236_create_ecom_core_work_product_templates.rb +4 -3
  18. data/db/migrate/20191119144618_create_ecom_core_stakeholders.rb +4 -3
  19. data/db/migrate/20191201131341_create_ecom_core_product_types.rb +4 -2
  20. data/db/migrate/20191201134420_create_ecom_core_work_component_templates.rb +8 -6
  21. data/db/migrate/20191201145848_create_ecom_core_projects.rb +28 -13
  22. data/db/migrate/20191202103735_create_ecom_core_tasks.rb +8 -5
  23. data/db/migrate/20191202105355_create_task_templates_resource_types.rb +8 -7
  24. data/db/migrate/20191202220832_create_ecom_core_users.rb +9 -6
  25. data/db/migrate/20191202220953_create_ecom_core_user_roles.rb +13 -8
  26. data/db/migrate/20191202221423_create_ecom_core_menus.rb +16 -9
  27. data/db/migrate/20191202235434_create_ecom_core_work_products.rb +29 -15
  28. data/db/migrate/20191206104247_create_ecom_core_work_components.rb +24 -14
  29. data/db/migrate/20191225100054_create_ecom_core_crews.rb +8 -4
  30. data/db/migrate/20191225121850_create_ecom_core_project_crews.rb +19 -0
  31. data/db/migrate/{20200401040433_create_ecom_core_attendance_sheets.rb → 20191225140433_create_ecom_core_attendance_sheets.rb} +6 -1
  32. data/db/migrate/20191225162539_create_ecom_core_attendance_sheet_entries.rb +17 -0
  33. data/db/migrate/20191225211712_create_ecom_core_crew_times.rb +15 -9
  34. data/db/migrate/20200126081005_create_ecom_core_payrolls.rb +4 -0
  35. data/db/migrate/20200126082103_create_ecom_core_payments.rb +6 -3
  36. data/db/migrate/20200126183218_create_ecom_core_payment_details.rb +10 -5
  37. data/db/migrate/20200307112519_create_ecom_core_custom_payment_details.rb +4 -3
  38. data/db/migrate/20200315145215_create_ecom_core_equipment_locations.rb +4 -3
  39. data/db/migrate/20200315150500_create_ecom_core_equipment_categories.rb +4 -2
  40. data/db/migrate/20200315152143_create_ecom_core_equipment.rb +4 -2
  41. data/db/migrate/20200315153640_create_ecom_core_equipment_items.rb +8 -5
  42. data/db/migrate/20200315160810_create_ecom_core_equipment_valuations.rb +4 -3
  43. data/db/migrate/20200316125323_create_ecom_core_equipment_components.rb +4 -3
  44. data/db/migrate/20200410090701_create_ecom_core_overtime_sheets.rb +7 -1
  45. data/db/migrate/20200410100035_create_ecom_core_overtime_sheet_entries.rb +8 -5
  46. data/db/migrate/20200410111827_create_ecom_core_crew_overtimes.rb +17 -11
  47. data/lib/ecom/core/version.rb +1 -1
  48. data/spec/factories/ecom/core/application_modules.rb +1 -1
  49. data/spec/factories/ecom/core/attendance_sheet_entries.rb +1 -1
  50. data/spec/factories/ecom/core/attendance_sheets.rb +3 -2
  51. data/spec/factories/ecom/core/companies.rb +9 -0
  52. data/spec/factories/ecom/core/crew_overtimes.rb +1 -1
  53. data/spec/factories/ecom/core/crew_times.rb +1 -1
  54. data/spec/factories/ecom/core/crew_types.rb +1 -1
  55. data/spec/factories/ecom/core/crews.rb +3 -1
  56. data/spec/factories/ecom/core/currencies.rb +1 -1
  57. data/spec/factories/ecom/core/custom_payment_details.rb +1 -1
  58. data/spec/factories/ecom/core/equipment.rb +1 -1
  59. data/spec/factories/ecom/core/equipment_categories.rb +1 -1
  60. data/spec/factories/ecom/core/equipment_components.rb +1 -1
  61. data/spec/factories/ecom/core/equipment_items.rb +1 -1
  62. data/spec/factories/ecom/core/equipment_locations.rb +1 -1
  63. data/spec/factories/ecom/core/equipment_types.rb +1 -1
  64. data/spec/factories/ecom/core/equipment_valuations.rb +1 -1
  65. data/spec/factories/ecom/core/location_types.rb +1 -1
  66. data/spec/factories/ecom/core/lookups.rb +1 -1
  67. data/spec/factories/ecom/core/material_types.rb +1 -1
  68. data/spec/factories/ecom/core/menus.rb +1 -1
  69. data/spec/factories/ecom/core/overtime_sheet_entries.rb +1 -1
  70. data/spec/factories/ecom/core/overtime_sheets.rb +3 -2
  71. data/spec/factories/ecom/core/overtime_types.rb +1 -1
  72. data/spec/factories/ecom/core/payment_details.rb +1 -1
  73. data/spec/factories/ecom/core/payments.rb +1 -1
  74. data/spec/factories/ecom/core/payrolls.rb +2 -1
  75. data/spec/factories/ecom/core/product_types.rb +1 -1
  76. data/spec/factories/ecom/core/project_crews.rb +9 -0
  77. data/spec/factories/ecom/core/projects.rb +2 -1
  78. data/spec/factories/ecom/core/resource_types.rb +1 -1
  79. data/spec/factories/ecom/core/stakeholder_types.rb +1 -1
  80. data/spec/factories/ecom/core/stakeholders.rb +1 -1
  81. data/spec/factories/ecom/core/task_template_types.rb +1 -1
  82. data/spec/factories/ecom/core/task_templates.rb +1 -1
  83. data/spec/factories/ecom/core/tasks.rb +1 -1
  84. data/spec/factories/ecom/core/user_roles.rb +1 -1
  85. data/spec/factories/ecom/core/users.rb +1 -1
  86. data/spec/factories/ecom/core/work_component_templates.rb +1 -1
  87. data/spec/factories/ecom/core/work_components.rb +1 -1
  88. data/spec/factories/ecom/core/work_product_templates.rb +1 -1
  89. data/spec/factories/ecom/core/work_products.rb +2 -2
  90. metadata +15 -18
  91. data/db/migrate/20200207035823_add_additional_columns_to_payment.rb +0 -6
  92. data/db/migrate/20200207040844_add_net_pay_column_to_payment_details.rb +0 -5
  93. data/db/migrate/20200210095535_add_advance_column_to_payment_details.rb +0 -5
  94. data/db/migrate/20200221123207_add_employee_id_to_crew.rb +0 -5
  95. data/db/migrate/20200401071343_remove_date_column_from_crew_times.rb +0 -5
  96. data/db/migrate/20200401122539_create_ecom_core_attendance_sheet_entries.rb +0 -14
  97. data/db/migrate/20200401142959_relate_crew_time_with_attendance_sheet_entry.rb +0 -8
  98. data/db/migrate/20200401144137_remove_crew_time_id_from_crew.rb +0 -7
  99. data/db/migrate/20200413144023_fix_crew_time_columns.rb +0 -17
  100. data/db/migrate/20200414044144_adjust_crew_overtime_column_names.rb +0 -6
  101. data/db/migrate/20200414185248_change_time_columns_to_datetime.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4caca2e265572f6c3af86b8969329871e853a43e660adc8ecdb5b190ce69f3eb
4
- data.tar.gz: 80d51b9cd7383710642c4646e81b2b5ec951f164b3557eb4d0b5b377396fd925
3
+ metadata.gz: 7ec4b0205003456f436aa5ec2ffc99f73d9f9dae97b5038f95b598fa259b6c66
4
+ data.tar.gz: 818efd4bff74c94646dd9fc96f99ee60f2e932e42183fbbdf240e277d9beacac
5
5
  SHA512:
6
- metadata.gz: 40808b1cb74da0ebd94aad66ee309829fd85a54dd709bce3ccecc426c67311f39d1fd1688a6846459470ca38f68cc90b7f23b03a8f22a438e5bb87ea87d80e5f
7
- data.tar.gz: 2bc74384e4f768b179b5e89cc6df416b9cae75de00a13a0355e4cd03e10ed0b4058cc18fc0b79e4495d67fbdd83014207b32a99c8252a45bcd78a88049918ad1
6
+ metadata.gz: 98e9f053543924c0b852c263d6185f5e09e8e7d5557a17835fc7e99b3d3b5f33eb26e2f4f1a4b01bad8195da0d950db9e924bb9ad4899e258c8a9393dac4fd73
7
+ data.tar.gz: ab3f72029a9386058701711220ac5884eb093385c292596d6cd4c0f34d31d71e5431b06e93df294e7e97de53db68afea0896032c0fd10ba8632d194b98532ea3
@@ -0,0 +1,11 @@
1
+ module Ecom
2
+ module Core
3
+ class StatusConstants
4
+ OPEN = 'Open'.freeze
5
+ SUBMITTED = 'Submitted'.freeze
6
+ APPROVED = 'Approved'.freeze
7
+
8
+ STATUSES = [OPEN, SUBMITTED, APPROVED].freeze
9
+ end
10
+ end
11
+ end
@@ -1,33 +1,43 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class AttendanceSheet < ApplicationRecord
4
- OPEN = 'Open'.freeze
5
- SUBMITTED = 'Submitted'.freeze
6
- APPROVED = 'Approved'.freeze
4
+ validates :date, presence: true, uniqueness: { scope: :project_id }
5
+ validates :status, inclusion: StatusConstants::STATUSES
7
6
 
8
- validates :date, presence: true, uniqueness: true
9
- validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
7
+ belongs_to :project
10
8
 
11
9
  has_many :attendance_sheet_entries
10
+ has_many :crew_times, through: :attendance_sheet_entries
12
11
 
13
- scope :open, -> { where(status: OPEN) }
14
- scope :current, -> { where(date: Date.today) }
15
- scope :current_open, -> { open.current }
12
+ scope :by_project, ->(id) { where(project_id: id) }
13
+ scope :by_date, ->(date) { where(date: date) }
14
+ scope :by_status, ->(status) { where(status: status) }
15
+ scope :by_date_between, ->(from, to) { where('date BETWEEN ? AND ?', from, to) }
16
16
 
17
- def self.open_for_date(date)
18
- AttendanceSheet.find_by(status: OPEN, date: date)
17
+ def self.open_for_date(date, project_id)
18
+ AttendanceSheet.find_by(status: StatusConstants::OPEN, date: date, project_id: project_id)
19
19
  end
20
20
 
21
- def self.open_exists?
22
- AttendanceSheet.open.exists?
21
+ def self.open_exists?(project_id)
22
+ AttendanceSheet
23
+ .by_project(project_id)
24
+ .by_status(StatusConstants::OPEN)
25
+ .exists?
23
26
  end
24
27
 
25
- def self.exists_for_today?
26
- AttendanceSheet.current.exists?
28
+ def self.exists_for_today?(project_id)
29
+ AttendanceSheet
30
+ .by_project(project_id)
31
+ .by_date(Date.today)
32
+ .exists?
27
33
  end
28
34
 
29
- def self.open_exists_for_today?
30
- AttendanceSheet.current_open.exists?
35
+ def self.open_exists_for_today?(project_id)
36
+ AttendanceSheet
37
+ .by_project(project_id)
38
+ .by_date(Date.today)
39
+ .by_status(StatusConstants::OPEN)
40
+ .exists?
31
41
  end
32
42
 
33
43
  # Attendance sheet should be created using the
@@ -35,21 +45,23 @@ module Ecom
35
45
  # check if there is an open attendance already,
36
46
  # and also that we have only one attendace sheet
37
47
  # per day.
38
- def self.create_current
39
- raise 'Attendance sheet already created for the day.' if AttendanceSheet.exists_for_today?
48
+ def self.create_current(project_id)
49
+ raise 'Attendance sheet already created for the day.' if AttendanceSheet.exists_for_today?(project_id)
40
50
 
41
- raise 'There is an open attendance sheet which needs to be submitted before creating a new one.' if AttendanceSheet.open_exists?
51
+ if AttendanceSheet.open_exists?(project_id)
52
+ raise 'There is an open attendance sheet which needs to be submitted before creating a new one.'
53
+ end
42
54
 
43
- AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: OPEN)
55
+ AttendanceSheet.create(date: Date.today, opened_at: Time.now, status: StatusConstants::OPEN, project_id: project_id)
44
56
  end
45
57
 
46
- def self.submit_current
47
- sheet = AttendanceSheet.find_by(date: Date.today, status: OPEN)
58
+ def self.submit_current(project_id)
59
+ sheet = AttendanceSheet.find_by(date: Date.today, status: StatusConstants::OPEN, project_id: project_id)
48
60
 
49
61
  raise 'There is no open attendance sheet to submit.' if sheet.nil?
50
62
 
51
63
  sheet.closed_at = Time.now
52
- sheet.status = SUBMITTED
64
+ sheet.status = StatusConstants::SUBMITTED
53
65
  sheet.save
54
66
  sheet
55
67
  end
@@ -58,12 +70,12 @@ module Ecom
58
70
  # to submit the attendance sheet after the date has
59
71
  # passed. Normally, timekeepers need to open and close
60
72
  # an attendance sheet of a date on the specific date.
61
- def self.submit(date)
62
- sheet = AttendanceSheet.open_for_date(date)
73
+ def self.submit(date, project_id)
74
+ sheet = AttendanceSheet.open_for_date(date, project_id)
63
75
  raise 'There is no open attendance sheet to submit for the selected day.' unless sheet
64
76
 
65
77
  sheet.closed_at = Time.now
66
- sheet.status = SUBMITTED
78
+ sheet.status = StatusConstants::SUBMITTED
67
79
  sheet.save
68
80
  sheet
69
81
  end
@@ -6,4 +6,4 @@ module Ecom
6
6
  has_many :crew_times
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Ecom
2
+ module Core
3
+ class Company < ApplicationRecord
4
+ has_many :projects
5
+
6
+ validates :code, :name, :address, :telephone, presence: true
7
+ validates :code, :name, uniqueness: true
8
+ end
9
+ end
10
+ end
@@ -2,17 +2,17 @@ module Ecom
2
2
  module Core
3
3
  class Crew < ApplicationRecord
4
4
  PERMANENT = 'Permanent'.freeze
5
+ SUPERVISOR = 'Supervisor'.freeze
5
6
  TEMPORARY = 'Temporary'.freeze
7
+ EMPLOYMENT_TYPES = [PERMANENT, SUPERVISOR, TEMPORARY].freeze
6
8
 
7
9
  before_save :set_employment_date,
8
10
  if: proc { |c| c.employment_date.nil? }
9
11
 
10
12
  belongs_to :crew_type
11
13
 
12
- validates :name, :qualification, presence: true
13
- validates :employment, inclusion: [PERMANENT, TEMPORARY]
14
- #validates :wage, presence: true, if: ->(o) { o.employment == PERMANENT }
15
- #validates :wage, absence: true, if: ->(o) { o.employment == TEMPORARY }
14
+ validates :name, :address, :qualification, :employment, :wage, :wage_in_words, presence: true
15
+ validates :employment, inclusion: EMPLOYMENT_TYPES
16
16
 
17
17
  def set_employment_date
18
18
  self.employment_date = Date.today
@@ -10,6 +10,11 @@ module Ecom
10
10
 
11
11
  validates :hours, :raw_hours, presence: true
12
12
 
13
+ scope :by_overtime, lambda { |id|
14
+ joins(:overtime_sheet_entry).where(ecom_core_overtime_sheet_entries: { overtime_sheet_id: id })
15
+ }
16
+ scope :revised, ->(revised) { where(revised: revised) }
17
+
13
18
  before_save :calculate_hours
14
19
 
15
20
  def calculate_hours
@@ -18,4 +23,4 @@ module Ecom
18
23
  end
19
24
  end
20
25
  end
21
- end
26
+ end
@@ -7,8 +7,8 @@ module Ecom
7
7
  BOTH = 'Both'.freeze
8
8
 
9
9
  TIME_RANGE = {
10
- MORNING => {start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('9:00 AM')},
11
- AFTERNOON => {start: Time.zone.parse('10:00 AM'), end: Time.zone.parse('2:00 PM')},
10
+ MORNING => { start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('9:00 AM') },
11
+ AFTERNOON => { start: Time.zone.parse('10:00 AM'), end: Time.zone.parse('2:00 PM') },
12
12
  BOTH => {start: Time.zone.parse('5:00 AM'), end: Time.zone.parse('2:00 PM')}
13
13
  }.freeze
14
14
 
@@ -19,8 +19,13 @@ module Ecom
19
19
 
20
20
  validates :checkin_time, presence: true, if: :checkout_time
21
21
 
22
+ scope :by_attendance, lambda { |id|
23
+ joins(:attendance_sheet_entry).where(ecom_core_attendance_sheet_entries: { attendance_sheet_id: id })
24
+ }
25
+ scope :revised, ->(revised) { where(revised: revised) }
26
+
22
27
  before_save :calculate_hours
23
- after_commit :calculate_total
28
+ after_save :calculate_total
24
29
 
25
30
  def calculate_hours
26
31
  self.hours = if checkout_time.nil? || checkin_time.nil?
@@ -1,24 +1,27 @@
1
1
  module Ecom
2
2
  module Core
3
3
  class OvertimeSheet < ApplicationRecord
4
- OPEN = 'Open'.freeze
5
- SUBMITTED = 'Submitted'.freeze
6
- APPROVED = 'Approved'.freeze
4
+ validates :date, :opened_at, presence: true, uniqueness: { scope: :project_id }
5
+ validates :status, inclusion: StatusConstants::STATUSES
7
6
 
8
- validates :date, :opened_at, presence: true, uniqueness: true
9
- validates :status, inclusion: [OPEN, SUBMITTED, APPROVED]
7
+ belongs_to :project
10
8
 
11
9
  has_many :overtime_sheet_entries
10
+ has_many :crew_overtimes, through: :overtime_sheet_entries
12
11
 
13
- scope :open, -> { where(status: OPEN) }
14
- scope :for_date, ->(date) { where(date: date) }
12
+ scope :by_project, ->(id) { where(project_id: id) }
13
+ scope :by_date, ->(date) { where(date: date) }
14
+ scope :by_status, ->(status) { where(status: status) }
15
+ scope :by_date_between, ->(from, to) { where('date BETWEEN ? AND ?', from, to) }
16
+ scope :open, ->(id) { where(status: StatusConstants::OPEN, project_id: id) }
17
+ scope :submitted, ->(id) { where(status: StatusConstants::SUBMITTED, project_id: id) }
15
18
 
16
- def self.open_exists?
17
- OvertimeSheet.open.exists?
19
+ def self.open_exists?(project_id)
20
+ OvertimeSheet.open(project_id).exists?
18
21
  end
19
22
 
20
- def self.open_for_date_exists?(date)
21
- OvertimeSheet.open.for_date(date).exists?
23
+ def self.open_for_date_exists?(date, project_id)
24
+ OvertimeSheet.open(project_id).where(date: date).exists?
22
25
  end
23
26
 
24
27
  # Overtime sheet should be created using the
@@ -26,16 +29,16 @@ module Ecom
26
29
  # check if there is an open overtime already,
27
30
  # and also that we have only one open overtime
28
31
  # sheet at a time.
29
- def self.create_new(date)
30
- if OvertimeSheet.open_for_date_exists?(date)
32
+ def self.create_new(date, project_id)
33
+ if OvertimeSheet.open_for_date_exists?(date, project_id)
31
34
  raise 'There is already an open overtime sheet for the selected date.'
32
35
  end
33
36
 
34
- if OvertimeSheet.open_exists?
37
+ if OvertimeSheet.open_exists?(project_id)
35
38
  raise 'There is already an open overtime sheet. It has to be submitted before creating a new one.'
36
39
  end
37
40
 
38
- OvertimeSheet.create(date: date, opened_at: Time.now, status: OPEN)
41
+ OvertimeSheet.create(date: date, opened_at: Time.now, status: StatusConstants::OPEN, project_id: project_id)
39
42
  end
40
43
  end
41
44
  end
@@ -8,4 +8,4 @@ module Ecom
8
8
  :advance, presence: true
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -4,6 +4,11 @@ module Ecom
4
4
  validates :month, :year, presence: true
5
5
 
6
6
  has_many :payments, class_name: 'Ecom::Core::Payment'
7
+ belongs_to :project
8
+
9
+ scope :by_project, ->(id) { where(project_id: id) }
10
+ scope :by_month, ->(month) { where(month: month) }
11
+ scope :by_year, ->(year) { where(year: year) }
7
12
  end
8
13
  end
9
14
  end
@@ -7,6 +7,10 @@ module Ecom
7
7
  belongs_to :project_manager, class_name: 'Ecom::Core::Stakeholder'
8
8
  belongs_to :task_template
9
9
  belongs_to :currency
10
+ belongs_to :company
11
+
12
+ has_many :project_crews
13
+ has_many :crews, through: :project_crews
10
14
 
11
15
  validates :name, :location, :contract_number, :date_contract_signed, :commencement_date, :completion_date,
12
16
  :contract_amount, :advance_payment, :retention, presence: true
@@ -0,0 +1,15 @@
1
+ module Ecom
2
+ module Core
3
+ class ProjectCrew < ApplicationRecord
4
+ ACTIVE = 'Active'.freeze
5
+ INACTIVE = 'Inactive'.freeze
6
+ STATUSES = [ACTIVE, INACTIVE].freeze
7
+
8
+ belongs_to :project
9
+ belongs_to :crew
10
+
11
+ validates :start_date, :status, presence: true
12
+ validates :status, inclusion: STATUSES
13
+ end
14
+ end
15
+ end
@@ -4,6 +4,7 @@ default: &default
4
4
  pool: 5
5
5
  timeout: 5000
6
6
  host: <%= ENV['DB_HOST'] %>
7
+ port: <%= ENV['DB_PORT'] %>
7
8
  username: <%= ENV['POSTGRES_USER'] %>
8
9
  password: <%= ENV['POSTGRES_PASSWORD'] %>
9
10
  database: <%= ENV['POSTGRES_DB'] %>
@@ -0,0 +1,14 @@
1
+ class CreateEcomCoreCompanies < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :ecom_core_companies do |t|
4
+ t.string :code, null: false, unique: true
5
+ t.string :name, null: false, unique: true
6
+ t.string :address, null: false
7
+ t.string :telephone, null: false
8
+ t.string :email
9
+ t.json :settings
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -4,12 +4,13 @@ class CreateEcomCoreTaskTemplates < ActiveRecord::Migration[6.0]
4
4
  t.string :code, null: false
5
5
  t.string :name, null: false
6
6
  t.string :description
7
- t.references :task_template_type, index: { name: 'ttt_on_tt_indx' }
7
+ t.references :task_template_type,
8
+ null: false,
9
+ index: { name: 'tt_on_ttt_indx' },
10
+ foreign_key: { to_table: :ecom_core_task_template_types }
8
11
  t.string :ancestry, index: true
9
12
 
10
13
  t.timestamps
11
14
  end
12
-
13
- add_foreign_key :ecom_core_task_templates, :ecom_core_task_template_types, column: :task_template_type_id
14
15
  end
15
16
  end
@@ -5,11 +5,12 @@ class CreateEcomCoreWorkProductTemplates < ActiveRecord::Migration[6.0]
5
5
  t.string :name, null: false, unique: true
6
6
  t.string :description
7
7
  t.string :remark
8
- t.references :task_template, index: { name: 'tt_on_wpt_indx' }
8
+ t.references :task_template,
9
+ null: false,
10
+ index: { name: 'tt_on_wpt_indx' },
11
+ foreign_key: { to_table: :ecom_core_task_templates }
9
12
 
10
13
  t.timestamps
11
14
  end
12
-
13
- add_foreign_key :ecom_core_work_product_templates, :ecom_core_task_templates, column: :task_template_id
14
15
  end
15
16
  end
@@ -9,11 +9,12 @@ class CreateEcomCoreStakeholders < ActiveRecord::Migration[6.0]
9
9
  t.string :contact_name, null: false
10
10
  t.string :contact_phone, null: false
11
11
  t.string :contact_email, null: false
12
- t.references :stakeholder_type, index: { name: 'em_stakeholders_on_type_indx' }
12
+ t.references :stakeholder_type,
13
+ null: false,
14
+ index: { name: 'stakeholders_on_st_indx' },
15
+ foreign_key: { to_table: :ecom_core_stakeholder_types }
13
16
 
14
17
  t.timestamps
15
18
  end
16
-
17
- add_foreign_key :ecom_core_stakeholders, :ecom_core_stakeholder_types, column: :stakeholder_type_id
18
19
  end
19
20
  end
@@ -2,13 +2,15 @@ class CreateEcomCoreProductTypes < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :ecom_core_product_types do |t|
4
4
  t.string :name, null: false
5
- t.references :work_product_template, index: { name: 'pt_on_wpt_indx' }
5
+ t.references :work_product_template,
6
+ null: false,
7
+ index: { name: 'pt_on_wpt_indx' },
8
+ foreign_key: { to_table: :ecom_core_work_product_templates }
6
9
  t.json :dimension
7
10
 
8
11
  t.timestamps
9
12
  end
10
13
 
11
14
  add_index :ecom_core_product_types, %i[name work_product_template_id], unique: true, name: 'wpt_on_pt_name_indx'
12
- add_foreign_key :ecom_core_product_types, :ecom_core_work_product_templates, column: :work_product_template_id
13
15
  end
14
16
  end
@@ -6,8 +6,14 @@ class CreateEcomCoreWorkComponentTemplates < ActiveRecord::Migration[6.0]
6
6
  t.string :description
7
7
  t.integer :relative_percentage
8
8
  t.json :dimension
9
- t.references :work_product_template, index: { name: 'wct_on_wpt_indx' }
10
- t.references :task_template, index: { name: 'wct_on_tt_indx' }
9
+ t.references :work_product_template,
10
+ null: false,
11
+ index: { name: 'wct_on_wpt_indx' },
12
+ foreign_key: { to_table: :ecom_core_work_product_templates }
13
+ t.references :task_template,
14
+ null: false,
15
+ index: { name: 'wct_on_tt_indx' },
16
+ foreign_key: { to_table: :ecom_core_task_templates }
11
17
 
12
18
  t.timestamps
13
19
  end
@@ -15,9 +21,5 @@ class CreateEcomCoreWorkComponentTemplates < ActiveRecord::Migration[6.0]
15
21
  add_index :ecom_core_work_component_templates, %i[code work_product_template_id task_template_id],
16
22
  unique: true,
17
23
  name: 'wct_on_code_wpt_id_tt_id_indx'
18
- add_foreign_key :ecom_core_work_component_templates, :ecom_core_work_product_templates,
19
- column: :work_product_template_id
20
- add_foreign_key :ecom_core_work_component_templates, :ecom_core_task_templates,
21
- column: :task_template_id
22
24
  end
23
25
  end