erp_base_erp_svcs 4.0.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v1/base_controller.rb +17 -0
  3. data/app/controllers/api/v1/categories_controller.rb +165 -0
  4. data/app/controllers/api/v1/contact_purposes_controller.rb +24 -0
  5. data/app/controllers/api/v1/geo_zones_controller.rb +25 -0
  6. data/app/controllers/api/v1/note_types_controller.rb +27 -0
  7. data/app/controllers/api/v1/parties_controller.rb +182 -0
  8. data/app/controllers/api/v1/role_types_controller.rb +146 -0
  9. data/app/controllers/api/v1/status_applications_controller.rb +40 -0
  10. data/app/controllers/api/v1/tracked_status_types_controller.rb +146 -0
  11. data/app/controllers/api/v1/unit_of_measurements_controller.rb +16 -0
  12. data/app/models/category.rb +116 -4
  13. data/app/models/contact.rb +16 -2
  14. data/app/models/contact_purpose.rb +13 -0
  15. data/app/models/descriptive_asset.rb +17 -0
  16. data/app/models/email_address.rb +21 -3
  17. data/app/models/entity_party_role.rb +8 -0
  18. data/app/models/fixed_asset.rb +2 -0
  19. data/app/models/fixed_asset_type.rb +1 -0
  20. data/app/models/generated_item.rb +17 -0
  21. data/app/models/geo_country.rb +12 -1
  22. data/app/models/individual.rb +11 -20
  23. data/app/models/note.rb +9 -0
  24. data/app/models/note_type.rb +2 -0
  25. data/app/models/organization.rb +19 -16
  26. data/app/models/party.rb +134 -229
  27. data/app/models/party_unit_of_measurement.rb +17 -1
  28. data/app/models/phone_number.rb +32 -12
  29. data/app/models/postal_address.rb +42 -11
  30. data/app/models/relationship_type.rb +28 -1
  31. data/app/models/role_type.rb +25 -2
  32. data/app/models/status_application.rb +40 -0
  33. data/app/models/tracked_status_type.rb +12 -0
  34. data/app/models/unit_of_measurement.rb +46 -7
  35. data/app/models/view_type.rb +14 -0
  36. data/config/routes.rb +24 -0
  37. data/db/data_migrations/20110913145838_setup_compass_ae_instance.rb +22 -9
  38. data/db/migrate/20080805000020_base_erp_services.rb +235 -6
  39. data/db/migrate/20130713171653_create_party_unit_of_measurements.rb +28 -0
  40. data/db/migrate/20150716201200_add_record_to_contact.rb +42 -0
  41. data/db/migrate/20150814202823_add_party_id_to_status_application.rb +10 -0
  42. data/db/migrate/20160310163040_add_created_by_updated_by_to_erp_base_erp_svcs.rb +44 -0
  43. data/lib/erp_base_erp_svcs.rb +1 -0
  44. data/lib/erp_base_erp_svcs/config.rb +3 -2
  45. data/lib/erp_base_erp_svcs/engine.rb +8 -1
  46. data/lib/erp_base_erp_svcs/extensions.rb +7 -1
  47. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_category.rb +5 -4
  48. data/lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb +48 -9
  49. data/lib/erp_base_erp_svcs/extensions/active_record/can_be_generated.rb +54 -0
  50. data/lib/erp_base_erp_svcs/extensions/active_record/has_contacts.rb +383 -0
  51. data/lib/erp_base_erp_svcs/extensions/active_record/has_notes.rb +15 -4
  52. data/lib/erp_base_erp_svcs/extensions/active_record/has_party_roles.rb +94 -0
  53. data/lib/erp_base_erp_svcs/extensions/active_record/has_tracked_status.rb +118 -35
  54. data/lib/erp_base_erp_svcs/extensions/active_record/is_contact_mechanism.rb +94 -0
  55. data/lib/erp_base_erp_svcs/extensions/active_record/is_describable.rb +46 -42
  56. data/lib/erp_base_erp_svcs/extensions/active_record/is_tenantable.rb +40 -0
  57. data/lib/erp_base_erp_svcs/extensions/active_record/tracks_created_by_updated_by.rb +39 -0
  58. data/lib/erp_base_erp_svcs/extensions/core/numbers.rb +29 -18
  59. data/lib/erp_base_erp_svcs/extensions/core/object.rb +5 -0
  60. data/lib/erp_base_erp_svcs/extensions/core/string.rb +53 -0
  61. data/lib/erp_base_erp_svcs/non_escape_json_string.rb +1 -1
  62. data/lib/erp_base_erp_svcs/time_zone_helper.rb +57 -0
  63. data/lib/erp_base_erp_svcs/version.rb +1 -1
  64. data/lib/tasks/erp_base_erp_svcs_tasks.rake +20 -23
  65. data/spec/dummy/log/development.log +3 -0
  66. metadata +29 -22
  67. data/db/data_migrations/20110525001935_add_usd_currency.rb +0 -11
  68. data/db/data_migrations/20110609150135_add_iso_codes.rb +0 -18
  69. data/db/data_migrations/20130211555555_upgrade_compass_ae_instances_data.rb +0 -18
  70. data/db/data_migrations/20130404201756_add_guid_to_instances.rb +0 -9
  71. data/db/migrate/20120606183856_add_txn_status.rb +0 -36
  72. data/db/migrate/20130211444444_upgrade_compass_ae_instances.rb +0 -33
  73. data/db/migrate/20130404171435_add_uuid_compass_ae_instance.rb +0 -16
  74. data/db/migrate/20130411125210_add_long_lat_to_address.rb +0 -15
  75. data/db/migrate/20130522125404_create_facilities.rb +0 -114
  76. data/db/migrate/20130621182047_create_unit_of_measurements.rb +0 -18
  77. data/db/migrate/20130909163912_add_iid_index_to_role_types.rb +0 -9
  78. data/db/migrate/20130926023541_add_domain_to_unit_of_measure.rb +0 -13
  79. data/db/migrate/20130929025342_add_type_semantics_to_uom.rb +0 -54
  80. data/db/migrate/20131112013047_add_primary_to_contacts.rb +0 -13
  81. data/db/migrate/20131112013048_add_erp_base_erp_svcs_missing_indexes.rb +0 -33
  82. data/db/migrate/20131211180831_add_postal_address_to_facility.rb +0 -5
  83. data/db/migrate/20140102154311_create_fixed_asset_party_roles.rb +0 -12
  84. data/db/migrate/20140401072612_add_custom_fields_to_party.rb +0 -12
  85. data/lib/erp_base_erp_svcs/extensions/active_record/has_contact.rb +0 -69
@@ -1,5 +1,21 @@
1
+ # create_table :party_unit_of_measurements do |t|
2
+ #
3
+ # t.string :description
4
+ # t.string :internal_identifier
5
+ # t.string :scope_filter
6
+ # t.references :party
7
+ # t.references :unit_of_measurement
8
+ #
9
+ # t.timestamps
10
+ # end
11
+ #
12
+ # add_index :party_unit_of_measurements, :party_id, name: 'party_uom_party_idx'
13
+ #
14
+ # add_index :party_unit_of_measurements, :unit_of_measurement, name: 'party_uom_uom_idx'
15
+
1
16
  class PartyUnitOfMeasurement < ActiveRecord::Base
2
- attr_accessible :description, :scope_filter, :party_id, :unit_of_measurement_id, :internal_identifier
17
+ attr_protected :created_at, :updated_at
18
+
3
19
  belongs_to :party
4
20
  belongs_to :unit_of_measurement
5
21
 
@@ -1,22 +1,42 @@
1
+ # create_table :phone_numbers do |t|
2
+ # t.column :phone_number, :string
3
+ # t.column :description, :string
4
+ #
5
+ # t.timestamps
6
+ # end
7
+
1
8
  class PhoneNumber < ActiveRecord::Base
2
9
  attr_protected :created_at, :updated_at
3
10
 
4
- has_contact
5
-
6
- def summary_line
7
- "#{description} : #{phone_number}"
8
- end
11
+ validates_format_of :phone_number,
12
+ with: /^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?)\s*(\d+))?$/,
13
+ message: "Not a valid North American phone number. Must be 10 digits, extensions are allowed in the format #123 or x123"
14
+ is_contact_mechanism
15
+
16
+ def summary_line
17
+ "#{description} : #{phone_number}"
18
+ end
9
19
 
10
20
  def eql_to?(phone)
11
- self.phone_number.reverse.gsub(/[^0-9]/,"")[0..9] == phone.reverse.gsub(/[^0-9]/,"")[0..9]
21
+ self.phone_number.reverse.gsub(/[^0-9]/, "")[0..9] == phone.reverse.gsub(/[^0-9]/, "")[0..9]
22
+ end
23
+
24
+ def to_label
25
+ "#{description} : #{to_s}"
26
+ end
27
+
28
+ def to_s
29
+ "#{phone_number}"
12
30
  end
13
31
 
14
- def to_label
15
- "#{description} : #{to_s}"
16
- end
17
-
18
- def to_s
19
- "#{phone_number}"
32
+ def to_data_hash
33
+ to_hash(only: [
34
+ :phone_number,
35
+ :description,
36
+ :created_at,
37
+ :updated_at
38
+ ]
39
+ )
20
40
  end
21
41
 
22
42
  end
@@ -1,29 +1,60 @@
1
+ # create_table :postal_addresses do |t|
2
+ # t.column :address_line_1, :string
3
+ # t.column :address_line_2, :string
4
+ # t.column :city, :string
5
+ # t.column :state, :string
6
+ # t.column :zip, :string
7
+ # t.column :country, :string
8
+ # t.column :description, :string
9
+ # t.column :geo_country_id, :integer
10
+ # t.column :geo_zone_id, :integer
11
+ # t.timestamps
12
+ # end
13
+ # add_index :postal_addresses, :geo_country_id
14
+ # add_index :postal_addresses, :geo_zone_id
15
+
1
16
  class PostalAddress < ActiveRecord::Base
2
17
  attr_protected :created_at, :updated_at
3
18
 
4
- has_contact
5
-
19
+ is_contact_mechanism
20
+
6
21
  belongs_to :geo_country
7
22
  belongs_to :geo_zone
8
23
 
9
24
  def summary_line
10
- "#{description} : #{address_line_1}, #{city}"
11
- end
12
-
13
- def to_label(&block)
25
+ "#{description} : #{address_line_1}, #{city}"
26
+ end
27
+
28
+ def to_label(&block)
14
29
  if block_given?
15
30
  block.call(self)
16
31
  else
17
32
  "#{description} : #{to_s}"
18
33
  end
19
- end
20
-
21
- def to_s
22
- "#{address_line_1}, #{city}, #{state} - #{zip}"
34
+ end
35
+
36
+ def to_s
37
+ "#{address_line_1}, #{city}, #{state} - #{zip}"
23
38
  end
24
39
 
25
40
  def zip_eql_to?(zip)
26
- self.zip.downcase.gsub(/[^a-zA-Z0-9]/, "")[0..4] == zip.to_s.downcase.gsub(/[^a-zA-Z0-9]/,"")[0..4]
41
+ self.zip.downcase.gsub(/[^a-zA-Z0-9]/, "")[0..4] == zip.to_s.downcase.gsub(/[^a-zA-Z0-9]/, "")[0..4]
42
+ end
43
+
44
+ def to_data_hash
45
+ to_hash(only: [
46
+ :address_line_1,
47
+ :address_line_2,
48
+ :city,
49
+ :state,
50
+ :zip,
51
+ :country,
52
+ :description,
53
+ :created_at,
54
+ :updated_at
55
+ ],
56
+ name: self.try(:contact).try(:party).try(:description)
57
+ )
27
58
  end
28
59
 
29
60
  end
@@ -1,9 +1,36 @@
1
1
  class RelationshipType < ActiveRecord::Base
2
2
  attr_protected :created_at, :updated_at
3
3
 
4
- acts_as_nested_set
5
4
  acts_as_erp_type
5
+ acts_as_nested_set
6
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
6
7
 
7
8
  belongs_to :valid_from_role, :class_name => "RoleType", :foreign_key => "valid_from_role_type_id"
8
9
  belongs_to :valid_to_role, :class_name => "RoleType", :foreign_key => "valid_to_role_type_id"
10
+
11
+ # find existing role type or create it and return it. Parent can be passed
12
+ # which will scope this type by the parent
13
+ def self.find_or_create(to_role_type, from_role_type, parent=nil)
14
+ relationship_type = if parent
15
+ parent.children.where('valid_to_role_type_id = ? and valid_from_role_type_id = ?',
16
+ to_role_type, from_role_type).first
17
+ else
18
+ RelationshipType.where('valid_to_role_type_id = ? and valid_from_role_type_id = ?',
19
+ to_role_type, from_role_type).first
20
+ end
21
+
22
+ unless relationship_type
23
+ relationship_type = RelationshipType.create(
24
+ description: "#{from_role_type.description} to #{to_role_type.description}",
25
+ internal_identifier: "#{from_role_type.internal_identifier}_to_#{to_role_type.internal_identifier}",
26
+ valid_from_role: from_role_type,
27
+ valid_to_role: to_role_type)
28
+
29
+ if parent
30
+ relationship_type.move_to_child_of(parent)
31
+ end
32
+ end
33
+
34
+ relationship_type
35
+ end
9
36
  end
@@ -1,9 +1,32 @@
1
1
  class RoleType < ActiveRecord::Base
2
2
  attr_protected :created_at, :updated_at
3
-
3
+
4
4
  acts_as_nested_set
5
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
5
6
  acts_as_erp_type
6
-
7
+
8
+ validates :internal_identifier, uniqueness: {message: "should be unique"}
9
+
7
10
  has_many :party_roles
8
11
  has_many :parties, :through => :party_roles
12
+
13
+ # finds all child role types for given role types.
14
+ #
15
+ # @param role_types [Array] role type internal identifiers or records
16
+ # @returns [Array] role types based and any of their children in a flat array
17
+ def self.find_child_role_types(role_types)
18
+ all_role_types = []
19
+
20
+ role_types.each do |role_type|
21
+
22
+ if role_type.is_a?(String)
23
+ role_type = RoleType.iid(role_type)
24
+ end
25
+
26
+ all_role_types.concat role_type.self_and_descendants
27
+ end
28
+
29
+ all_role_types.flatten
30
+ end
31
+
9
32
  end
@@ -1,5 +1,45 @@
1
+ # create_table :status_applications do |t|
2
+ # t.references :tracked_status_type
3
+ # t.references :status_application_record, :polymorphic => true
4
+ # t.references :party
5
+ # t.datetime :from_date
6
+ # t.datetime :thru_date
7
+ #
8
+ # t.timestamps
9
+ # end
10
+ #
11
+ # add_index :status_applications, [:status_application_record_id, :status_application_record_type], :name => 'status_applications_record_idx'
12
+ # add_index :status_applications, :tracked_status_type_id, :name => 'tracked_status_type_id_idx'
13
+ # add_index :status_applications, :from_date, :name => 'from_date_idx'
14
+ # add_index :status_applications, :thru_date, :name => 'thru_date_idx'
15
+
1
16
  class StatusApplication < ActiveRecord::Base
17
+
2
18
  belongs_to :tracked_status_type
3
19
  belongs_to :status_application_record, :polymorphic => true
4
20
 
21
+ belongs_to :party
22
+
23
+ def to_data_hash
24
+ data = to_hash only: [:id,
25
+ :created_at,
26
+ :updated_at],
27
+ username: username
28
+
29
+ data[:tracked_status_type] = tracked_status_type.to_data_hash
30
+
31
+ data
32
+ end
33
+
34
+ def username
35
+ user_name = "System"
36
+ unless party.nil?
37
+ unless party.user.nil?
38
+ user_name = party.user.username
39
+ end
40
+ end
41
+
42
+ user_name
43
+ end
44
+
5
45
  end
@@ -1,6 +1,18 @@
1
1
  class TrackedStatusType < ActiveRecord::Base
2
2
  attr_accessible :description, :internal_identifier
3
3
 
4
+ acts_as_erp_type
5
+ acts_as_nested_set
6
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
7
+
4
8
  has_many :status_applications
5
9
 
10
+ def to_data_hash
11
+ to_hash(only: [:id,
12
+ :description,
13
+ :internal_identifier,
14
+ :created_at,
15
+ :updated_at])
16
+ end
17
+
6
18
  end
@@ -1,16 +1,55 @@
1
+ # create_table :unit_of_measurements do |t|
2
+ # t.string :description
3
+ # t.string :domain
4
+ # t.string :internal_identifier
5
+ # t.string :comments
6
+ # t.string :external_identifier
7
+ # t.string :external_id_source
8
+ #
9
+ # t.integer :lft
10
+ # t.integer :rgt
11
+ # t.integer :parent_id
12
+ #
13
+ # t.timestamps
14
+ # end
15
+ #
16
+ # add_index :unit_of_measurements, :lft
17
+ # add_index :unit_of_measurements, :rgt
18
+ # add_index :unit_of_measurements, :parent_id
19
+
1
20
  class UnitOfMeasurement < ActiveRecord::Base
21
+ attr_protected :created_at, :updated_at
2
22
 
3
- has_one :carrier_unit_of_measurement
23
+ acts_as_nested_set
24
+ include ErpTechSvcs::Utils::DefaultNestedSetMethods
4
25
 
5
- attr_accessible :description
26
+ tracks_created_by_updated_by
6
27
 
7
- def to_data_hash
28
+ has_many :party_unit_of_measurements
8
29
 
9
- {
10
- :id => self.id,
11
- :description => self.description
12
- }
30
+ class << self
31
+ # scope by dba organization
32
+ #
33
+ # @param dba_organization [Party, Array] dba organization to scope by or Array of dba organizations to
34
+ # scope by
35
+ #
36
+ # @return [ActiveRecord::Relation]
37
+ def scope_by_dba_organization(dba_organization)
38
+ joins(:party_unit_of_measurements)
39
+ .where({party_unit_of_measurements: {party_id: dba_organization}})
40
+ end
41
+ end
13
42
 
43
+ def to_data_hash
44
+ to_hash(only: [:id,
45
+ :description,
46
+ :domain,
47
+ :internal_identifier,
48
+ :comments,
49
+ :external_identifier,
50
+ :external_id_source,
51
+ :created_at,
52
+ :updated_at])
14
53
  end
15
54
 
16
55
  end
@@ -1,5 +1,19 @@
1
+ # create_table :view_types do |t|
2
+ # t.string :internal_identifier
3
+ # t.string :description
4
+ #
5
+ # # these columns are required to support the behavior of the plugin 'awesome_nested_set'
6
+ # t.integer :lft
7
+ # t.integer :rgt
8
+ # t.integer :parent_id
9
+ #
10
+ # t.timestamps
11
+ # end
12
+
1
13
  class ViewType < ActiveRecord::Base
2
14
  attr_protected :created_at, :updated_at
3
15
 
16
+ acts_as_nested_set
17
+
4
18
  has_many :descriptive_assets
5
19
  end
@@ -1,3 +1,27 @@
1
+ Rails.application.routes.draw do
2
+
3
+ namespace :api do
4
+ namespace :v1 do
5
+ resources :parties, defaults: { :format => 'json' } do
6
+ member do
7
+ put :update_roles
8
+ end
9
+
10
+ resources :role_types, defaults: { :format => 'json' }
11
+ end
12
+ resources :tracked_status_types, defaults: { :format => 'json' }
13
+ resources :role_types, defaults: { :format => 'json' }
14
+ resources :note_types, defaults: { :format => 'json' }
15
+ resources :categories, defaults: { :format => 'json' }
16
+ resources :contact_purposes, defaults: { :format => 'json' }
17
+ resources :geo_zones, defaults: { :format => 'json' }
18
+ resources :status_applications, defaults: { :format => 'json' }
19
+ resources :unit_of_measurements, defaults: { :format => 'json' }
20
+ end
21
+ end
22
+
23
+ end
24
+
1
25
  ErpBaseErpSvcs::Engine.routes.draw do
2
26
 
3
27
  namespace 'shared' do
@@ -1,16 +1,29 @@
1
1
  class SetupCompassAeInstance
2
2
 
3
3
  def self.up
4
- c = CompassAeInstance.new
5
- c.description = 'Base CompassAE Instance'
6
- c.internal_identifier = 'base'
7
- c.version = '3.1'
8
- c.save
4
+ # setup currency
5
+ Currency.create(:name => 'US Dollar', :internal_identifier => 'USD', :major_unit_symbol => "$")
9
6
 
10
- rt = RoleType.new
11
- rt.description = 'CompassAE Instance Owner'
12
- rt.internal_identifier = 'compass_ae_instance_owner'
13
- rt.save
7
+ # setup iso codes
8
+ #find the erp_base_erp_svcs engine
9
+ engine_path = Rails::Application::Railties.engines.find{|item| item.engine_name == 'erp_base_erp_svcs'}.config.root.to_s
10
+
11
+ GeoCountry.load_from_file(File.join(engine_path,'db/data_sets/geo_countries.yml'))
12
+ GeoZone.load_from_file(File.join(engine_path,'db/data_sets/geo_zones.yml'))
13
+
14
+ # setup instance
15
+ instance = CompassAeInstance.new
16
+ instance.description = 'Base CompassAE Instance'
17
+ instance.internal_identifier = 'base'
18
+ instance.version = '3.1'
19
+ instance.save
20
+
21
+ instance.setup_guid
22
+
23
+ role_type = RoleType.new
24
+ role_type.description = 'CompassAE Instance Owner'
25
+ role_type.internal_identifier = 'compass_ae_instance_owner'
26
+ role_type.save
14
27
  end
15
28
 
16
29
  def self.down
@@ -9,7 +9,8 @@ class BaseErpServices < ActiveRecord::Migration
9
9
  t.string :type
10
10
  t.string :schema, :default => 'public'
11
11
  t.integer :parent_id
12
-
12
+ t.string :guid
13
+
13
14
  t.timestamps
14
15
  end
15
16
 
@@ -17,6 +18,7 @@ class BaseErpServices < ActiveRecord::Migration
17
18
  add_index :compass_ae_instances, :schema, :name => "schema_idx"
18
19
  add_index :compass_ae_instances, :type, :name => "type_idx"
19
20
  add_index :compass_ae_instances, :parent_id, :name => "parent_id_idx"
21
+ add_index :compass_ae_instances, :guid, :name => "guid_idx"
20
22
  end
21
23
 
22
24
  unless table_exists?(:compass_ae_instance_party_roles)
@@ -25,7 +27,7 @@ class BaseErpServices < ActiveRecord::Migration
25
27
  t.integer :compass_ae_instance_id
26
28
  t.integer :party_id
27
29
  t.integer :role_type_id
28
-
30
+
29
31
  t.timestamps
30
32
  end
31
33
 
@@ -83,7 +85,11 @@ class BaseErpServices < ActiveRecord::Migration
83
85
  t.column :external_id_source, :string
84
86
  t.timestamps
85
87
  end
88
+
86
89
  add_index :role_types, :internal_identifier, :name => "role_types_iid_idx"
90
+ add_index :role_types, :parent_id, :name => "role_types_parent_id_idx"
91
+ add_index :role_types, :lft, :name => "role_types_lft_idx"
92
+ add_index :role_types, :rgt, :name => "role_types_rgt_idx"
87
93
  end
88
94
 
89
95
  # Create relationship_types table
@@ -104,8 +110,11 @@ class BaseErpServices < ActiveRecord::Migration
104
110
  t.column :external_id_source, :string
105
111
  t.timestamps
106
112
  end
113
+
107
114
  add_index :relationship_types, :valid_from_role_type_id
108
115
  add_index :relationship_types, :valid_to_role_type_id
116
+ add_index :relationship_types, :parent_id, :name => 'relationship_types_parent_id_idx'
117
+ add_index :relationship_types, :internal_identifier, :name => 'relationship_types_internal_identifier_idx'
109
118
  end
110
119
 
111
120
  # Create party_relationships table
@@ -176,6 +185,7 @@ class BaseErpServices < ActiveRecord::Migration
176
185
  t.column :party_id, :integer
177
186
  t.column :contact_mechanism_id, :integer
178
187
  t.column :contact_mechanism_type, :string
188
+ t.column :is_primary, :boolean
179
189
 
180
190
  t.column :external_identifier, :string
181
191
  t.column :external_id_source, :string
@@ -183,6 +193,7 @@ class BaseErpServices < ActiveRecord::Migration
183
193
  t.timestamps
184
194
  end
185
195
  add_index :contacts, :party_id
196
+ add_index :contacts, :is_primary
186
197
  add_index :contacts, [:contact_mechanism_id, :contact_mechanism_type], :name => "besi_2"
187
198
  end
188
199
 
@@ -205,6 +216,9 @@ class BaseErpServices < ActiveRecord::Migration
205
216
  t.timestamps
206
217
  end
207
218
  add_index :contact_types, :parent_id
219
+ add_index :contact_types, :lft
220
+ add_index :contact_types, :rgt
221
+ add_index :contact_types, :internal_identifier, :name => 'contact_types_internal_identifier_idx'
208
222
  end
209
223
 
210
224
  # Create contact_purposes
@@ -235,7 +249,9 @@ class BaseErpServices < ActiveRecord::Migration
235
249
  t.column :contact_id, :integer
236
250
  t.column :contact_purpose_id, :integer
237
251
  end
252
+
238
253
  add_index :contact_purposes_contacts, [:contact_id, :contact_purpose_id], :name => "contact_purposes_contacts_index"
254
+ add_index :contact_purposes, :internal_identifier, :name => 'contact_purposes_internal_identifier_idx'
239
255
  end
240
256
 
241
257
  # Create postal_addresses (a contact_mechanism)
@@ -250,6 +266,8 @@ class BaseErpServices < ActiveRecord::Migration
250
266
  t.column :description, :string
251
267
  t.column :geo_country_id, :integer
252
268
  t.column :geo_zone_id, :integer
269
+ t.column :latitude, :decimal, :precision => 12, :scale => 8
270
+ t.column :longitude, :decimal, :precision => 12, :scale => 8
253
271
  t.timestamps
254
272
  end
255
273
  add_index :postal_addresses, :geo_country_id
@@ -278,9 +296,9 @@ class BaseErpServices < ActiveRecord::Migration
278
296
 
279
297
  unless table_exists?(:money)
280
298
  create_table :money do |t|
281
- t.string :description
282
- t.decimal :amount, :precision => 8, :scale => 2
283
- t.references :currency
299
+ t.string :description
300
+ t.decimal :amount, :precision => 8, :scale => 2
301
+ t.references :currency
284
302
  t.timestamps
285
303
  end
286
304
  add_index :money, :currency_id
@@ -324,6 +342,10 @@ class BaseErpServices < ActiveRecord::Migration
324
342
  t.timestamps
325
343
  end
326
344
  add_index :categories, [:category_record_id, :category_record_type], :name => "category_polymorphic"
345
+ add_index :categories, :internal_identifier, :name => 'categories_internal_identifier_idx'
346
+ add_index :categories, :parent_id, :name => 'categories_parent_id_idx'
347
+ add_index :categories, :lft, :name => 'categories_lft_idx'
348
+ add_index :categories, :rgt, :name => 'categories_rgt_idx'
327
349
  end
328
350
 
329
351
  ## category_classifications
@@ -337,7 +359,9 @@ class BaseErpServices < ActiveRecord::Migration
337
359
 
338
360
  t.timestamps
339
361
  end
362
+
340
363
  add_index :category_classifications, [:classification_id, :classification_type], :name => "classification_polymorphic"
364
+ add_index :category_classifications, :category_id, :name => 'category_classifications_category_id_idx'
341
365
  end
342
366
 
343
367
  ## descriptive_assets
@@ -355,6 +379,7 @@ class BaseErpServices < ActiveRecord::Migration
355
379
 
356
380
  add_index :descriptive_assets, :view_type_id
357
381
  add_index :descriptive_assets, [:described_record_id, :described_record_type], :name => 'described_record_idx'
382
+ add_index :descriptive_assets, :internal_identifier, :name => 'descriptive_assets_internal_identifier_idx'
358
383
  end
359
384
 
360
385
  unless table_exists?(:view_types)
@@ -362,8 +387,17 @@ class BaseErpServices < ActiveRecord::Migration
362
387
  t.string :internal_identifier
363
388
  t.string :description
364
389
 
390
+ t.integer :lft
391
+ t.integer :rgt
392
+ t.integer :parent_id
393
+
365
394
  t.timestamps
366
395
  end
396
+
397
+ add_index :view_types, :lft
398
+ add_index :view_types, :rgt
399
+ add_index :view_types, :parent_id
400
+ add_index :view_types, :internal_identifier, :name => 'view_types_internal_identifier_idx'
367
401
  end
368
402
 
369
403
  unless table_exists?(:geo_countries)
@@ -422,6 +456,8 @@ class BaseErpServices < ActiveRecord::Migration
422
456
  end
423
457
 
424
458
  add_index :note_types, [:note_type_record_id, :note_type_record_type], :name => "note_type_record_idx"
459
+ add_index :note_types, :parent_id, :name => 'note_types_parent_id_idx'
460
+ add_index :note_types, :internal_identifier, :name => 'note_types_internal_identifier_idx'
425
461
  end
426
462
 
427
463
  unless table_exists?(:valid_note_types)
@@ -436,6 +472,195 @@ class BaseErpServices < ActiveRecord::Migration
436
472
  add_index :valid_note_types, :note_type_id
437
473
  end
438
474
 
475
+ unless table_exists?(:status_applications)
476
+ create_table :status_applications do |t|
477
+ t.references :tracked_status_type
478
+ t.references :status_application_record, :polymorphic => true
479
+ t.datetime :from_date
480
+ t.datetime :thru_date
481
+
482
+ t.timestamps
483
+ end
484
+
485
+ add_index :status_applications, [:status_application_record_id, :status_application_record_type], :name => 'status_applications_record_idx'
486
+ add_index :status_applications, :tracked_status_type_id, :name => 'tracked_status_type_id_idx'
487
+ add_index :status_applications, :from_date, :name => 'from_date_idx'
488
+ add_index :status_applications, :thru_date, :name => 'thru_date_idx'
489
+ end
490
+
491
+ unless table_exists?(:tracked_status_types)
492
+ create_table :tracked_status_types do |t|
493
+ t.string :description
494
+ t.string :internal_identifier
495
+ t.string :external_identifier
496
+
497
+ t.integer :lft
498
+ t.integer :rgt
499
+ t.integer :parent_id
500
+
501
+ t.timestamps
502
+ end
503
+
504
+ add_index :tracked_status_types, :internal_identifier, :name => 'tracked_status_types_iid_idx'
505
+ add_index :tracked_status_types, :lft
506
+ add_index :tracked_status_types, :rgt
507
+ add_index :tracked_status_types, :parent_id
508
+ end
509
+
510
+ unless table_exists?(:facilities)
511
+ create_table :facilities do |t|
512
+
513
+ t.string :description
514
+ t.string :internal_identifier
515
+ t.integer :facility_type_id
516
+ t.references :postal_address
517
+
518
+ #polymorphic columns
519
+ t.integer :facility_record_id
520
+ t.integer :facility_record_type
521
+
522
+ t.timestamps
523
+ end
524
+
525
+ add_index :facilities, [:facility_record_id, :facility_record_type], :name => "facility_record_idx"
526
+ add_index :facilities, :postal_address_id, :name => "facility_postal_address_idx"
527
+ end
528
+
529
+ unless table_exists?(:facility_types)
530
+ create_table :facility_types do |t|
531
+
532
+ t.string :description
533
+ t.string :internal_identifier
534
+ t.string :external_identifier
535
+ t.string :external_identifer_source
536
+
537
+ #these columns are required to support the behavior of the plugin 'awesome_nested_set'
538
+ t.integer :parent_id
539
+ t.integer :lft
540
+ t.integer :rgt
541
+
542
+ t.timestamps
543
+ end
544
+
545
+ add_index :facility_types, [:parent_id, :lft, :rgt], :name => "facility_types_nested_set_idx"
546
+ end
547
+
548
+ unless table_exists?(:fixed_assets)
549
+ create_table :fixed_assets do |t|
550
+
551
+ #foreign key references
552
+ t.references :fixed_asset_type
553
+
554
+ #custom columns go here
555
+ t.string :description
556
+ t.string :comments
557
+ t.string :internal_identifier
558
+ t.string :external_identifier
559
+ t.string :external_id_source
560
+
561
+ #polymorphic columns
562
+ t.string :fixed_asset_record_type
563
+ t.integer :fixed_asset_record_id
564
+
565
+ t.timestamps
566
+ end
567
+
568
+ add_index :fixed_assets, [:fixed_asset_record_type, :fixed_asset_record_id], :name => "fixed_assets_record_idx"
569
+ add_index :fixed_assets, :fixed_asset_type_id, :name => "fixed_assets_fixed_asset_type_idx"
570
+ end
571
+
572
+ unless table_exists?(:fixed_asset_types)
573
+ create_table :fixed_asset_types do |t|
574
+ #these columns are required to support the behavior of the plugin 'awesome_nested_set'
575
+ t.integer :parent_id
576
+ t.integer :lft
577
+ t.integer :rgt
578
+
579
+ #custom columns go here
580
+ t.string :description
581
+ t.string :comments
582
+ t.string :internal_identifier
583
+ t.string :external_identifier
584
+ t.string :external_id_source
585
+
586
+ t.timestamps
587
+ end
588
+
589
+ add_index :fixed_asset_types, [:parent_id, :lft, :rgt], :name => "fixed_asset_types_nested_set_idx"
590
+ end
591
+
592
+ unless table_exists?(:party_fixed_asset_assignments)
593
+ create_table :party_fixed_asset_assignments do |t|
594
+ #foreign key references
595
+ t.references :party
596
+ t.references :fixed_asset
597
+
598
+ t.datetime :assigned_from
599
+ t.datetime :assigned_thru
600
+ t.integer :allocated_cost_money_id
601
+
602
+ t.timestamps
603
+ end
604
+
605
+ add_index :party_fixed_asset_assignments, [:party_id, :fixed_asset_id], :name => "party_fixed_asset_assign_idx"
606
+ end
607
+
608
+ unless table_exists?(:fixed_asset_party_roles)
609
+ create_table :fixed_asset_party_roles do |t|
610
+
611
+ t.references :party
612
+ t.references :fixed_asset
613
+ t.references :role_type
614
+
615
+ t.timestamps
616
+ end
617
+ end
618
+
619
+ unless table_exists?(:unit_of_measurements)
620
+ create_table :unit_of_measurements do |t|
621
+ t.string :description
622
+ t.string :domain
623
+ t.string :internal_identifier
624
+ t.string :comments
625
+ t.string :external_identifier
626
+ t.string :external_id_source
627
+
628
+ t.integer :lft
629
+ t.integer :rgt
630
+ t.integer :parent_id
631
+
632
+ t.timestamps
633
+ end
634
+
635
+ add_index :unit_of_measurements, :lft
636
+ add_index :unit_of_measurements, :rgt
637
+ add_index :unit_of_measurements, :parent_id
638
+ end
639
+
640
+ unless table_exists?(:generated_items)
641
+ create_table :generated_items do |t|
642
+ t.references :generated_by, :polymorphic => true
643
+ t.references :generated_record, :polymorphic => true
644
+
645
+ t.timestamps
646
+ end
647
+
648
+ add_index :generated_items, [:generated_by_type, :generated_by_id], :name => 'generated_by_idx'
649
+ add_index :generated_items, [:generated_record_type, :generated_record_id], :name => 'generated_record_idx'
650
+ end
651
+
652
+ unless table_exists?(:entity_party_roles)
653
+ create_table :entity_party_roles do |t|
654
+ t.references :party
655
+ t.references :role_type
656
+ t.references :entity_record, :polymorphic => true
657
+ end
658
+
659
+ add_index :entity_party_roles, :party_id
660
+ add_index :entity_party_roles, :role_type_id
661
+ add_index :entity_party_roles, [:entity_record_id, :entity_record_type], name: 'entity_party_roles_entity_record_idx'
662
+ end
663
+
439
664
  end
440
665
 
441
666
  def self.down
@@ -446,7 +671,11 @@ class BaseErpServices < ActiveRecord::Migration
446
671
  :contacts, :individuals, :organizations,
447
672
  :party_relationships, :relationship_types, :role_types,
448
673
  :party_roles, :parties, :categories, :category_classifications,
449
- :descriptive_assets, :view_types, :notes, :note_types, :valid_note_types, :compass_ae_instances
674
+ :descriptive_assets, :view_types, :notes, :note_types,
675
+ :valid_note_types, :compass_ae_instances,
676
+ :facilities, :facility_types, :fixed_assets,
677
+ :fixed_asset_types, :party_fixed_asset_assignments,
678
+ :unit_of_measurements, :entity_party_roles
450
679
  ].each do |tbl|
451
680
  if table_exists?(tbl)
452
681
  drop_table tbl