erp_tech_svcs 3.1.8 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +6 -14
  2. data/README.md +15 -9
  3. data/app/controllers/erp_tech_svcs/session_controller.rb +21 -8
  4. data/app/controllers/erp_tech_svcs/user_controller.rb +15 -10
  5. data/app/mailers/user_mailer.rb +3 -0
  6. data/app/models/audit_log.rb +0 -2
  7. data/app/models/extensions/note.rb +1 -2
  8. data/app/models/extensions/party.rb +6 -1
  9. data/app/models/file_asset.rb +80 -38
  10. data/app/models/group.rb +1 -1
  11. data/app/models/notification.rb +49 -0
  12. data/app/models/notification_type.rb +5 -0
  13. data/app/models/user.rb +2 -2
  14. data/app/models/user_defined_data.rb +6 -0
  15. data/app/models/user_defined_field.rb +8 -0
  16. data/app/views/user_mailer/activation_needed_email.html.erb +17 -7
  17. data/config/initializers/file_support.rb +2 -2
  18. data/config/routes.rb +2 -1
  19. data/db/migrate/20130610163240_create_notifications.rb +37 -0
  20. data/db/migrate/20131113213843_add_audit_log_item_old_value.rb +13 -0
  21. data/db/migrate/20131113213844_add_erp_tech_svcs_missing_indexes.rb +31 -0
  22. data/db/migrate/20131129203603_add_user_defined_fields.rb +43 -0
  23. data/db/migrate/20141013060204_add_custom_fields_to_notifications.rb +12 -0
  24. data/db/migrate/20141108182427_add_scoped_by_to_file_assets.rb +14 -0
  25. data/lib/erp_tech_svcs.rb +4 -1
  26. data/lib/erp_tech_svcs/config.rb +5 -2
  27. data/lib/erp_tech_svcs/engine.rb +3 -1
  28. data/lib/erp_tech_svcs/extensions.rb +3 -1
  29. data/lib/erp_tech_svcs/extensions/active_record/has_user_defined_data.rb +147 -0
  30. data/lib/erp_tech_svcs/extensions/active_record/is_json.rb +55 -0
  31. data/lib/erp_tech_svcs/extensions/active_record/scoped_by.rb +64 -0
  32. data/lib/erp_tech_svcs/file_support/file_system_manager.rb +7 -0
  33. data/lib/erp_tech_svcs/file_support/manager.rb +1 -1
  34. data/lib/erp_tech_svcs/file_support/s3_manager.rb +13 -6
  35. data/lib/erp_tech_svcs/utils/default_nested_set_methods.rb +3 -5
  36. data/lib/erp_tech_svcs/version.rb +7 -3
  37. data/lib/tasks/erp_tech_svcs_tasks.rake +23 -4
  38. data/spec/lib/erp_tech_svcs/extensions/active_record/is_json_spec.rb +13 -0
  39. metadata +109 -78
  40. data/app/assets/javascripts/erp_tech_svcs/application.js +0 -9
  41. data/app/assets/stylesheets/erp_tech_svcs/application.css +0 -7
  42. data/app/helpers/erp_tech_svcs/application_helper.rb +0 -4
  43. data/app/views/layouts/application.html.erb +0 -14
  44. data/app/views/layouts/erp_tech_svcs/application.html.erb +0 -14
  45. data/config/initializers/erp_tech_svcs.rb +0 -16
  46. data/db/migrate/20111117183144_create_has_attribute_tables.rb +0 -38
  47. data/lib/erp_tech_svcs/extensions/active_record/has_relational_dynamic_attributes.rb +0 -128
  48. data/spec/dummy/db/data_migrations/20130220143304_add_usd_currency.erp_base_erp_svcs.rb +0 -12
  49. data/spec/dummy/db/data_migrations/20130220143305_add_iso_codes.erp_base_erp_svcs.rb +0 -19
  50. data/spec/dummy/db/data_migrations/20130220143306_setup_compass_ae_instance.erp_base_erp_svcs.rb +0 -21
  51. data/spec/dummy/db/data_migrations/20130220143307_upgrade_compass_ae_instances_data.erp_base_erp_svcs.rb +0 -19
  52. data/spec/dummy/db/data_migrations/20130220143308_create_capability_scope_types.erp_tech_svcs.rb +0 -15
  53. data/spec/dummy/db/data_migrations/20130220143309_schedule_delete_expired_sessions_job.erp_tech_svcs.rb +0 -16
  54. data/spec/dummy/db/data_migrations/20130220143310_setup_audit_log_types.erp_tech_svcs.rb +0 -22
  55. data/spec/dummy/db/data_migrations/20130220143311_create_group_relationship_and_role_types.erp_tech_svcs.rb +0 -20
  56. data/spec/dummy/db/data_migrations/20130220143312_note_capabilities.erp_tech_svcs.rb +0 -24
  57. data/spec/dummy/db/data_migrations/20130422151256_add_guid_to_instances.erp_base_erp_svcs.rb +0 -10
  58. data/spec/dummy/db/migrate/20130220143259_base_erp_services.erp_base_erp_svcs.rb +0 -486
  59. data/spec/dummy/db/migrate/20130220143260_add_txn_status.erp_base_erp_svcs.rb +0 -37
  60. data/spec/dummy/db/migrate/20130220143261_upgrade_compass_ae_instances.erp_base_erp_svcs.rb +0 -34
  61. data/spec/dummy/db/migrate/20130220143262_base_tech_services.erp_tech_svcs.rb +0 -271
  62. data/spec/dummy/db/migrate/20130220143263_create_has_attribute_tables.erp_tech_svcs.rb +0 -39
  63. data/spec/dummy/db/migrate/20130220143264_create_groups.erp_tech_svcs.rb +0 -19
  64. data/spec/dummy/db/migrate/20130220143265_upgrade_security.erp_tech_svcs.rb +0 -54
  65. data/spec/dummy/db/migrate/20130220143266_upgrade_security2.erp_tech_svcs.rb +0 -275
  66. data/spec/dummy/db/migrate/20130422151250_add_uuid_compass_ae_instance.erp_base_erp_svcs.rb +0 -17
  67. data/spec/dummy/db/migrate/20130422151251_add_long_lat_to_address.erp_base_erp_svcs.rb +0 -16
  68. data/spec/dummy/db/migrate/20130422151252_add_queue_to_delayed_jobs.erp_tech_svcs.rb +0 -14
  69. data/spec/dummy/db/schema.rb +0 -665
  70. data/spec/dummy/db/spec.sqlite3 +0 -0
@@ -1,9 +0,0 @@
1
- // This is a manifest file that'll be compiled into including all the files listed below.
2
- // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
- // be included in the compiled file accessible from http://example.com/assets/application.js
4
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
- // the compiled file.
6
- //
7
- //= require jquery
8
- //= require jquery_ujs
9
- //= require_tree .
@@ -1,7 +0,0 @@
1
- /*
2
- * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
- * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
- * the top of the compiled file, but it's generally better to create a new file per style scope.
5
- *= require_self
6
- *= require_tree .
7
- */
@@ -1,4 +0,0 @@
1
- module ErpTechSvcs
2
- module ApplicationHelper
3
- end
4
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>ErpTechSvcs</title>
5
- <%= stylesheet_link_tag "erp_tech_svcs/application" %>
6
- <%= javascript_include_tag "erp_tech_svcs/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>ErpTechSvcs</title>
5
- <%= stylesheet_link_tag "erp_tech_svcs/application" %>
6
- <%= javascript_include_tag "erp_tech_svcs/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,16 +0,0 @@
1
- Rails.application.config.erp_tech_svcs.configure do |config|
2
- config.installation_domain = 'localhost:3000'
3
- config.login_url = '/erp_app/login'
4
- config.email_notifications_from = 'notifications@noreply.com'
5
- config.email_regex = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$"
6
- config.max_file_size_in_mb = 5
7
- config.file_upload_types = 'txt,pdf,zip,tgz,gz,rar,jpg,jpeg,gif,png,tif,tiff,bmp,csv,xls,xlsx,doc,docx,ppt,pptx,psd,ai,css,js,mp3,mp4,m4a,m4v,mov,wav,wmv'
8
- config.file_assets_location = 'file_assets' # relative to Rails.root/
9
- config.s3_url_expires_in_seconds = 60
10
- config.s3_protocol = 'https' # Can be either 'http' or 'https'
11
- config.file_storage = :filesystem # Can be either :s3 or :filesystem
12
- config.s3_cache_expires_in_minutes = 60
13
- config.session_expires_in_hours = 12 # this is used by DeleteExpiredSessionsJob to purge inaactive sessions from database
14
- config.compass_logger_path = "#{Rails.root}/log"
15
- end
16
- Rails.application.config.erp_tech_svcs.configure!
@@ -1,38 +0,0 @@
1
- class CreateHasAttributeTables < ActiveRecord::Migration
2
- def up
3
- unless table_exists?(:attribute_types)
4
- create_table :attribute_types do |t|
5
- t.string :internal_identifier
6
- t.string :description
7
- t.string :data_type
8
-
9
- t.timestamps
10
- end
11
-
12
- add_index :attribute_types, :internal_identifier, :name => ':attribute_types_iid_idx'
13
- end
14
- unless table_exists?(:attribute_values)
15
- create_table :attribute_values do |t|
16
- t.integer :attributed_record_id
17
- t.string :attributed_record_type
18
- t.references :attribute_type
19
- t.string :value
20
-
21
- t.timestamps
22
- end
23
-
24
- add_index :attribute_values, [:attributed_record_id, :attributed_record_type], :name => 'attribute_values_attributed_record_idx'
25
- add_index :attribute_values, :attribute_type_id, :name => 'attribute_values_attributed_type_idx'
26
- add_index :attribute_values, :value, :name => 'attribute_values_value_idx'
27
- end
28
- end
29
-
30
- def down
31
- if table_exists?(:attribute_types)
32
- drop_table :attribute_types
33
- end
34
- if table_exists?(:attribute_values)
35
- drop_table :attribute_values
36
- end
37
- end
38
- end
@@ -1,128 +0,0 @@
1
- module ErpTechSvcs
2
- module Extensions
3
- module ActiveRecord
4
- module HasRelationalDynamicAttributes
5
- def self.included(base)
6
- base.extend(ClassMethods)
7
- end
8
-
9
- module ClassMethods
10
-
11
- def has_relational_dynamic_attributes
12
- has_many :attribute_values, :as => :attributed_record, :dependent => :destroy
13
-
14
- before_save :assign_dynamic_attribute_on_save
15
-
16
- extend HasRelationalDynamicAttributes::SingletonMethods
17
- include HasRelationalDynamicAttributes::InstanceMethods
18
- end
19
-
20
- end
21
-
22
- module SingletonMethods
23
- def find_by_dynamic_attribute(value, options={})
24
- arel_query = AttributeValue.where('attributed_record_type = ?', self.name)
25
- .where(AttributeValue.arel_table[:value].matches("%#{value}%"))
26
-
27
- #if included_type_iids then find where types is equal to given types
28
- or_clauses = nil
29
- options[:included_type_iids].each do |type_iid|
30
- type = AttributeType.where('description = ? or internal_identifier = ?', type_iid, type_iid).first
31
- raise "Attribute Type '#{type_iid}' does not exist" if type.nil?
32
- or_clauses = if or_clauses.nil?
33
- AttributeValue.arel_table[:attribute_type_id].eq(type.id)
34
- else
35
- or_clauses.or(AttributeValue.arel_table[:attribute_type_id].eq(type.id))
36
- end
37
- end if options[:included_type_iids]
38
-
39
- #if excluded_type_iids then find where types is not equal to
40
- or_clauses = nil
41
- options[:excluded_type_iids].each do |type_iid|
42
- type = AttributeType.where('description = ? or internal_identifier = ?', type_iid, type_iid).first
43
- raise "Attribute Type '#{type_iid}' does not exist" if type.nil?
44
- or_clauses = if or_clauses.nil?
45
- AttributeValue.arel_table[:attribute_type_id].eq(type.id).not
46
- else
47
- or_clauses.or(AttributeValue.arel_table[:attribute_type_id].eq(type.id).not)
48
- end
49
- end if options[:excluded_type_iids]
50
-
51
- arel_query = arel_query.where(or_clauses) if or_clauses
52
-
53
- #get total_count if we need to return it
54
- total_count = arel_query.count('attributed_record_id') if options[:return_total_count]
55
-
56
- arel_query = arel_query.limit(options[:limit]) if options[:limit]
57
- arel_query = arel_query.offset(options[:offset]) if options[:offset]
58
- records = arel_query.all.collect(&:attributed_record)
59
-
60
- #return total_count if option passed
61
- options[:return_total_count] ? (return records, total_count) : records
62
- end
63
- end
64
-
65
- module InstanceMethods
66
- def update_or_create_dynamic_attribute(value, type, data_type)
67
- if self.has_dynamic_attribute_of_type?(type)
68
- update_first_dynamic_attribute_value_of_type(value, type)
69
- else
70
- add_dynamic_attribute(value, type, data_type)
71
- end
72
- end
73
-
74
- def update_first_dynamic_attribute_value_of_type(value, type)
75
- attribute_type = AttributeType.where('description = ? or internal_identifier = ?', type, type).first
76
- attribute_value = self.attribute_values.where(:attribute_type_id => attribute_type.id).first
77
- attribute_value.value = value
78
- attribute_value.save!
79
- end
80
-
81
- def get_dynamic_attributes
82
- {}.tap do |hash|
83
- self.attribute_values.each do |value|
84
- hash[value.attribute_type.description] = value.value
85
- end
86
- end
87
- end
88
-
89
- def get_dynamic_value_of_type(attribute_type_iid)
90
- attribute_value = get_dynamic_attribute_of_type(attribute_type_iid)
91
- attribute_value.nil? ? nil : attribute_value.value
92
- end
93
-
94
- def get_dynamic_attribute_of_type(attribute_type_iid)
95
- attribute_value = self.attribute_values.includes(:attribute_type).where('attribute_types.internal_identifier = ? or attribute_types.description = ?', attribute_type_iid.to_s, attribute_type_iid.to_s).first
96
- attribute_value.nil? ? nil : attribute_value
97
- end
98
-
99
- def assign_dynamic_attribute_on_save
100
- #template method overridden in implementing class
101
- end
102
-
103
- def has_dynamic_attribute_of_type? (attribute_type_iid)
104
- !self.attribute_values.includes(:attribute_type).where('attribute_types.internal_identifier = ? or attribute_types.description = ?', attribute_type_iid.to_s, attribute_type_iid.to_s).first.nil?
105
- end
106
-
107
- def destroy_dynamic_attribute_of_type (attribute_type_iid)
108
- self.attribute_values.includes(:attribute_type).destroy_all("attribute_types.internal_identifier = #{attribute_type_iid.to_s} or attribute_types.description = #{attribute_type_iid.to_s}")
109
- end
110
-
111
- def add_dynamic_attribute(value, type, data_type)
112
- attribute_type = AttributeType.where('description = ? or internal_identifier = ?', type, type).first
113
- attribute_type = AttributeType.create(:description => type, :data_type => data_type) unless attribute_type
114
- attribute_value = AttributeValue.create(:value => value, :attribute_type => attribute_type)
115
- self.attribute_values << attribute_value
116
- end
117
-
118
- def method_missing(m, *args, &block)
119
- value = get_dynamic_value_of_type(m.to_s)
120
- (value.nil?) ? super : (return value)
121
- end
122
-
123
- end
124
-
125
- end #HasRelationalDynamicAttributes
126
- end #ActiveRecord
127
- end #Extensions
128
- end #ErpTechSvcs
@@ -1,12 +0,0 @@
1
- # This migration comes from erp_base_erp_svcs (originally 20110525001935)
2
- class AddUsdCurrency
3
-
4
- def self.up
5
- Currency.create(:name => 'US Dollar', :internal_identifier => 'USD', :major_unit_symbol => "$")
6
- end
7
-
8
- def self.down
9
- Currency.usd.destroy
10
- end
11
-
12
- end
@@ -1,19 +0,0 @@
1
- # This migration comes from erp_base_erp_svcs (originally 20110609150135)
2
- require 'yaml'
3
-
4
- class AddIsoCodes
5
-
6
- def self.up
7
- #find the erp_base_erp_svcs engine
8
- engine_path = Rails::Application::Railties.engines.find{|item| item.engine_name == 'erp_base_erp_svcs'}.config.root.to_s
9
-
10
- GeoCountry.load_from_file(File.join(engine_path,'db/data_sets/geo_countries.yml'))
11
- GeoZone.load_from_file(File.join(engine_path,'db/data_sets/geo_zones.yml'))
12
- end
13
-
14
- def self.down
15
- GeoCountry.delete_all
16
- GeoZone.delete_all
17
- end
18
-
19
- end
@@ -1,21 +0,0 @@
1
- # This migration comes from erp_base_erp_svcs (originally 20110913145838)
2
- class SetupCompassAeInstance
3
-
4
- def self.up
5
- c = CompassAeInstance.new
6
- c.description = 'Base CompassAE Instance'
7
- c.internal_identifier = 'base'
8
- c.version = '3.1'
9
- c.save
10
-
11
- rt = RoleType.new
12
- rt.description = 'CompassAE Instance Owner'
13
- rt.internal_identifier = 'compass_ae_instance_owner'
14
- rt.save
15
- end
16
-
17
- def self.down
18
- #remove data here
19
- end
20
-
21
- end
@@ -1,19 +0,0 @@
1
- # This migration comes from erp_base_erp_svcs (originally 20130211555555)
2
- class UpgradeCompassAeInstancesData < ActiveRecord::Migration
3
- def self.up
4
- if CompassAeInstance.find_by_internal_identifier('base').nil?
5
- c = CompassAeInstance.order('id ASC').first
6
- c.description = 'Base CompassAE Instance'
7
- c.internal_identifier = 'base'
8
- c.schema = 'public'
9
- c.save
10
- end
11
-
12
- if RoleType.find_by_internal_identifier('compass_ae_instance_owner').nil?
13
- rt = RoleType.new
14
- rt.description = 'CompassAE Instance Owner'
15
- rt.internal_identifier = 'compass_ae_instance_owner'
16
- rt.save
17
- end
18
- end
19
- end
@@ -1,15 +0,0 @@
1
- # This migration comes from erp_tech_svcs (originally 20110109173616)
2
- class CreateCapabilityScopeTypes
3
-
4
- def self.up
5
- CapabilityType.create(:internal_identifier => 'download', :description => 'Download') if CapabilityType.where("internal_identifier = 'download'").first.nil?
6
-
7
- ScopeType.create(:description => 'Instance', :internal_identifier => 'instance') if ScopeType.where("internal_identifier = 'instance'").first.nil?
8
- ScopeType.create(:description => 'Class', :internal_identifier => 'class') if ScopeType.where("internal_identifier = 'class'").first.nil?
9
- ScopeType.create(:description => 'Query', :internal_identifier => 'query') if ScopeType.where("internal_identifier = 'query'").first.nil?
10
- end
11
-
12
- def self.down
13
- end
14
-
15
- end
@@ -1,16 +0,0 @@
1
- # This migration comes from erp_tech_svcs (originally 20110802200222)
2
- class ScheduleDeleteExpiredSessionsJob
3
-
4
- def self.up
5
- #insert data here
6
- date = Date.tomorrow
7
- start_time = DateTime.civil(date.year, date.month, date.day, 2, 0, 1, -(5.0/24.0))
8
-
9
- ErpTechSvcs::Sessions::DeleteExpiredSessionsJob.schedule_job(start_time)
10
- end
11
-
12
- def self.down
13
- #remove data here
14
- end
15
-
16
- end
@@ -1,22 +0,0 @@
1
- # This migration comes from erp_tech_svcs (originally 20111111144706)
2
- class SetupAuditLogTypes
3
-
4
- def self.up
5
- application_alt = AuditLogType.create(:description => 'Application', :internal_identifier => 'application')
6
-
7
- [
8
- {:description => 'Custom Message', :internal_identifier => 'custom_message'},
9
- {:description => 'Successful Logout', :internal_identifier => 'successful_logout'},
10
- {:description => 'Successful Login', :internal_identifier => 'successful_login'},
11
- {:description => 'Accessed Area', :internal_identifier => 'accessed_area'},
12
- {:description => 'Session Timeout', :internal_identifier => 'session_timeout'}
13
- ].each do |alt_hash|
14
- AuditLogType.create(alt_hash).move_to_child_of(application_alt)
15
- end
16
- end
17
-
18
- def self.down
19
- AuditLogType.destroy_all
20
- end
21
-
22
- end
@@ -1,20 +0,0 @@
1
- # This migration comes from erp_tech_svcs (originally 20121116155018)
2
- class CreateGroupRelationshipAndRoleTypes
3
-
4
- def self.up
5
- #insert data here
6
- to_role = RoleType.create(:description => 'Security Group', :internal_identifier => 'group')
7
- from_role = RoleType.create(:description => 'Security Group Member', :internal_identifier => 'group_member')
8
- RelationshipType.create(:description => 'Security Group Membership',
9
- :name => 'Group Membership',
10
- :internal_identifier => 'group_membership',
11
- :valid_from_role => from_role,
12
- :valid_to_role => to_role
13
- )
14
- end
15
-
16
- def self.down
17
- #remove data here
18
- end
19
-
20
- end
@@ -1,24 +0,0 @@
1
- # This migration comes from erp_tech_svcs (originally 20121130212146)
2
- class NoteCapabilities
3
-
4
- def self.up
5
- #insert data here
6
- admin = SecurityRole.find_or_create_by_description_and_internal_identifier(:description => 'Admin', :internal_identifier => 'admin')
7
- employee = SecurityRole.find_or_create_by_description_and_internal_identifier(:description => 'Employee', :internal_identifier => 'employee')
8
-
9
- admin.add_capability('create', 'Note')
10
- admin.add_capability('delete', 'Note')
11
- admin.add_capability('edit', 'Note')
12
- admin.add_capability('view', 'Note')
13
-
14
- employee.add_capability('create', 'Note')
15
- employee.add_capability('delete', 'Note')
16
- employee.add_capability('edit', 'Note')
17
- employee.add_capability('view', 'Note')
18
- end
19
-
20
- def self.down
21
- #remove data here
22
- end
23
-
24
- end
@@ -1,10 +0,0 @@
1
- # This migration comes from erp_base_erp_svcs (originally 20130404201756)
2
- class AddGuidToInstances
3
-
4
- def self.up
5
- CompassAeInstance.all.each do |instance|
6
- instance.setup_guid
7
- end
8
- end
9
-
10
- end
@@ -1,486 +0,0 @@
1
- # This migration comes from erp_base_erp_svcs (originally 20080805000020)
2
- class BaseErpServices < ActiveRecord::Migration
3
- def self.up
4
-
5
- unless table_exists?(:compass_ae_instances)
6
- create_table :compass_ae_instances do |t|
7
- t.string :description
8
- t.string :internal_identifier
9
- t.decimal :version, :precision => 8, :scale => 3
10
- t.string :type
11
- t.string :schema, :default => 'public'
12
- t.integer :parent_id
13
-
14
- t.timestamps
15
- end
16
-
17
- add_index :compass_ae_instances, :internal_identifier, :name => "iid_idx"
18
- add_index :compass_ae_instances, :schema, :name => "schema_idx"
19
- add_index :compass_ae_instances, :type, :name => "type_idx"
20
- add_index :compass_ae_instances, :parent_id, :name => "parent_id_idx"
21
- end
22
-
23
- unless table_exists?(:compass_ae_instance_party_roles)
24
- create_table :compass_ae_instance_party_roles do |t|
25
- t.string :description
26
- t.integer :compass_ae_instance_id
27
- t.integer :party_id
28
- t.integer :role_type_id
29
-
30
- t.timestamps
31
- end
32
-
33
- add_index :compass_ae_instance_party_roles, :compass_ae_instance_id, :name => "compass_ae_instance_id_idx"
34
- add_index :compass_ae_instance_party_roles, :party_id, :name => "party_id_idx"
35
- add_index :compass_ae_instance_party_roles, :role_type_id, :name => "role_type_id_idx"
36
- end
37
-
38
- # Create parties table
39
- unless table_exists?(:parties)
40
- create_table :parties do |t|
41
- t.column :description, :string
42
- t.column :business_party_id, :integer
43
- t.column :business_party_type, :string
44
- t.column :list_view_image_id, :integer
45
-
46
- #This field is here to provide a direct way to map CompassAE
47
- #business parties to unified idenfiers in organizations if they
48
- #have been implemented in an enterprise.
49
- t.column :enterprise_identifier, :string
50
- t.timestamps
51
- end
52
- add_index :parties, [:business_party_id, :business_party_type], :name => "besi_1"
53
- end
54
-
55
- # Create party_roles table
56
- unless table_exists?(:party_roles)
57
- create_table :party_roles do |t|
58
- #this column holds the class name of the
59
- #subtype of party-to-role_type relatsionship
60
- t.column :type, :string
61
- #xref between party and role_type
62
- t.column :party_id, :integer
63
- t.column :role_type_id, :integer
64
- t.timestamps
65
- end
66
- add_index :party_roles, :party_id
67
- add_index :party_roles, :role_type_id
68
- end
69
-
70
-
71
- # Create role_types table
72
- unless table_exists?(:role_types)
73
- create_table :role_types do |t|
74
- #these columns are required to support the behavior of the plugin 'awesome_nested_set'
75
- t.column :parent_id, :integer
76
- t.column :lft, :integer
77
- t.column :rgt, :integer
78
-
79
- #custom columns go here
80
- t.column :description, :string
81
- t.column :comments, :string
82
- t.column :internal_identifier, :string
83
- t.column :external_identifier, :string
84
- t.column :external_id_source, :string
85
- t.timestamps
86
- end
87
- end
88
-
89
- # Create relationship_types table
90
- unless table_exists?(:relationship_types)
91
- create_table :relationship_types do |t|
92
- t.column :parent_id, :integer
93
- t.column :lft, :integer
94
- t.column :rgt, :integer
95
-
96
- #custom columns go here
97
- t.column :valid_from_role_type_id, :integer
98
- t.column :valid_to_role_type_id, :integer
99
- t.column :name, :string
100
- t.column :description, :string
101
-
102
- t.column :internal_identifier, :string
103
- t.column :external_identifier, :string
104
- t.column :external_id_source, :string
105
- t.timestamps
106
- end
107
- add_index :relationship_types, :valid_from_role_type_id
108
- add_index :relationship_types, :valid_to_role_type_id
109
- end
110
-
111
- # Create party_relationships table
112
- unless table_exists?(:party_relationships)
113
- create_table :party_relationships do |t|
114
- t.column :description, :string
115
- t.column :party_id_from, :integer
116
- t.column :party_id_to, :integer
117
- t.column :role_type_id_from, :integer
118
- t.column :role_type_id_to, :integer
119
- t.column :status_type_id, :integer
120
- t.column :priority_type_id, :integer
121
- t.column :relationship_type_id, :integer
122
- t.column :from_date, :date
123
- t.column :thru_date, :date
124
- t.column :external_identifier, :string
125
- t.column :external_id_source, :string
126
- t.timestamps
127
- end
128
- add_index :party_relationships, :status_type_id
129
- add_index :party_relationships, :priority_type_id
130
- add_index :party_relationships, :relationship_type_id
131
- end
132
-
133
- # Create organizations table
134
- unless table_exists?(:organizations)
135
- create_table :organizations do |t|
136
- t.column :description, :string
137
- t.column :tax_id_number, :string
138
- t.timestamps
139
- end
140
- end
141
-
142
- # Create individuals table
143
- unless table_exists?(:individuals)
144
- create_table :individuals do |t|
145
- t.column :party_id, :integer
146
- t.column :current_last_name, :string
147
- t.column :current_first_name, :string
148
- t.column :current_middle_name, :string
149
- t.column :current_personal_title, :string
150
- t.column :current_suffix, :string
151
- t.column :current_nickname, :string
152
- t.column :gender, :string, :limit => 1
153
- t.column :birth_date, :date
154
- t.column :height, :decimal, :precision => 5, :scale => 2
155
- t.column :weight, :integer
156
- t.column :mothers_maiden_name, :string
157
- t.column :marital_status, :string, :limit => 1
158
- t.column :social_security_number, :string
159
- t.column :current_passport_number, :integer
160
-
161
- t.column :current_passport_expire_date, :date
162
- t.column :total_years_work_experience, :integer
163
- t.column :comments, :string
164
- t.column :encrypted_ssn, :string
165
- t.column :temp_ssn, :string
166
- t.column :salt, :string
167
- t.column :ssn_last_four, :string
168
- t.timestamps
169
- end
170
- add_index :individuals, :party_id
171
- end
172
-
173
- # Create contacts table
174
- unless table_exists?(:contacts)
175
- create_table :contacts do |t|
176
- t.column :party_id, :integer
177
- t.column :contact_mechanism_id, :integer
178
- t.column :contact_mechanism_type, :string
179
-
180
- t.column :external_identifier, :string
181
- t.column :external_id_source, :string
182
-
183
- t.timestamps
184
- end
185
- add_index :contacts, :party_id
186
- add_index :contacts, [:contact_mechanism_id, :contact_mechanism_type], :name => "besi_2"
187
- end
188
-
189
- # Create contact_types
190
- unless table_exists?(:contact_types)
191
- create_table :contact_types do |t|
192
- t.column :parent_id, :integer
193
- t.column :lft, :integer
194
- t.column :rgt, :integer
195
-
196
- #custom columns go here
197
-
198
- t.column :description, :string
199
- t.column :comments, :string
200
-
201
- t.column :internal_identifier, :string
202
- t.column :external_identifier, :string
203
- t.column :external_id_source, :string
204
-
205
- t.timestamps
206
- end
207
- add_index :contact_types, :parent_id
208
- end
209
-
210
- # Create contact_purposes
211
- unless table_exists?(:contact_purposes)
212
- create_table :contact_purposes do |t|
213
-
214
- t.column :parent_id, :integer
215
- t.column :lft, :integer
216
- t.column :rgt, :integer
217
-
218
- #custom columns go here
219
-
220
- t.column :description, :string
221
- t.column :comments, :string
222
-
223
- t.column :internal_identifier, :string
224
- t.column :external_identifier, :string
225
- t.column :external_id_source, :string
226
-
227
- t.timestamps
228
- end
229
- add_index :contact_purposes, :parent_id
230
-
231
- end
232
-
233
- unless table_exists?(:contact_purposes_contacts)
234
- create_table :contact_purposes_contacts, {:id => false} do |t|
235
- t.column :contact_id, :integer
236
- t.column :contact_purpose_id, :integer
237
- end
238
- add_index :contact_purposes_contacts, [:contact_id, :contact_purpose_id], :name => "contact_purposes_contacts_index"
239
- end
240
-
241
- # Create postal_addresses (a contact_mechanism)
242
- unless table_exists?(:postal_addresses)
243
- create_table :postal_addresses do |t|
244
- t.column :address_line_1, :string
245
- t.column :address_line_2, :string
246
- t.column :city, :string
247
- t.column :state, :string
248
- t.column :zip, :string
249
- t.column :country, :string
250
- t.column :description, :string
251
- t.column :geo_country_id, :integer
252
- t.column :geo_zone_id, :integer
253
- t.timestamps
254
- end
255
- add_index :postal_addresses, :geo_country_id
256
- add_index :postal_addresses, :geo_zone_id
257
- end
258
-
259
- # Create email_addresses (a contact_mechanism)
260
- unless table_exists?(:email_addresses)
261
- create_table :email_addresses do |t|
262
- t.column :email_address, :string
263
- t.column :description, :string
264
-
265
- t.timestamps
266
- end
267
- end
268
-
269
- # Create phone_numbers table (A contact_mechanism)
270
- unless table_exists?(:phone_numbers)
271
- create_table :phone_numbers do |t|
272
- t.column :phone_number, :string
273
- t.column :description, :string
274
-
275
- t.timestamps
276
- end
277
- end
278
-
279
- unless table_exists?(:party_search_facts)
280
- create_table :party_search_facts do |t|
281
- t.column :party_id, :integer
282
- t.column :eid, :string
283
- t.column :type, :string
284
- t.column :roles, :text
285
- t.column :party_description, :string
286
- t.column :party_business_party_type, :string
287
- t.column :user_login, :string
288
- t.column :individual_current_last_name, :string
289
- t.column :individual_current_first_name, :string
290
- t.column :individual_current_middle_name, :string
291
- t.column :individual_birth_date, :string
292
- t.column :individual_ssn, :string
293
- t.column :party_phone_number, :string
294
- t.column :party_email_address, :string
295
- t.column :party_address_1, :string
296
- t.column :party_address_2, :string
297
- t.column :party_primary_address_city, :string
298
- t.column :party_primary_address_state, :string
299
- t.column :party_primary_address_zip, :string
300
- t.column :party_primary_address_country, :string
301
- t.column :user_enabled, :boolean
302
- t.column :user_type, :string
303
- t.column :reindex, :boolean
304
- t.timestamps
305
- end
306
- end
307
-
308
- unless table_exists?(:money)
309
- create_table :money do |t|
310
- t.string :description
311
- t.decimal :amount, :precision => 8, :scale => 2
312
- t.references :currency
313
- t.timestamps
314
- end
315
- add_index :money, :currency_id
316
- end
317
-
318
- unless table_exists?(:currencies)
319
- create_table :currencies do |t|
320
- t.string :name
321
- t.string :definition
322
- t.string :internal_identifier # aka alphabetic_code
323
- t.string :numeric_code
324
- t.string :major_unit_symbol
325
- t.string :minor_unit_symbol
326
- t.string :ratio_of_minor_unit_to_major_unit
327
- t.string :postfix_label
328
- t.datetime :introduction_date
329
- t.datetime :expiration_date
330
- t.timestamps
331
- end
332
- add_index :currencies, :internal_identifier
333
- end
334
-
335
- ## categories
336
- unless table_exists?(:categories)
337
- create_table :categories do |t|
338
- t.string :description
339
- t.string :external_identifier
340
- t.datetime :from_date
341
- t.datetime :to_date
342
- t.string :internal_identifier
343
-
344
- # polymorphic assns
345
- t.integer :category_record_id
346
- t.string :category_record_type
347
-
348
- # nested set cols
349
- t.integer :parent_id
350
- t.integer :lft
351
- t.integer :rgt
352
-
353
- t.timestamps
354
- end
355
- add_index :categories, [:category_record_id, :category_record_type], :name => "category_polymorphic"
356
- end
357
-
358
- ## category_classifications
359
- unless table_exists?(:category_classifications)
360
- create_table :category_classifications do |t|
361
- t.integer :category_id
362
- t.string :classification_type
363
- t.integer :classification_id
364
- t.datetime :from_date
365
- t.datetime :to_date
366
-
367
- t.timestamps
368
- end
369
- add_index :category_classifications, [:classification_id, :classification_type], :name => "classification_polymorphic"
370
- end
371
-
372
- ## descriptive_assets
373
- unless table_exists?(:descriptive_assets)
374
- create_table :descriptive_assets do |t|
375
- t.references :view_type
376
- t.string :internal_identifier
377
- t.text :description
378
- t.string :external_identifier
379
- t.string :external_id_source
380
- t.references :described_record, :polymorphic => true
381
-
382
- t.timestamps
383
- end
384
-
385
- add_index :descriptive_assets, :view_type_id
386
- add_index :descriptive_assets, [:described_record_id, :described_record_type], :name => 'described_record_idx'
387
- end
388
-
389
- unless table_exists?(:view_types)
390
- create_table :view_types do |t|
391
- t.string :internal_identifier
392
- t.string :description
393
-
394
- t.timestamps
395
- end
396
- end
397
-
398
- unless table_exists?(:geo_countries)
399
- create_table :geo_countries do |t|
400
- t.column :name, :string
401
- t.column :iso_code_2, :string, :length => 2
402
- t.column :iso_code_3, :string, :length => 3
403
- t.column :display, :boolean, :default => true
404
- t.column :external_id, :integer
405
- t.column :created_at, :datetime
406
- end
407
- add_index :geo_countries, :name
408
- add_index :geo_countries, :iso_code_2
409
- end
410
-
411
- unless table_exists?(:geo_zones)
412
- create_table :geo_zones do |t|
413
- t.column :geo_country_id, :integer
414
- t.column :zone_code, :string, :default => 2
415
- t.column :zone_name, :string
416
- t.column :created_at, :datetime
417
- end
418
- add_index :geo_zones, :geo_country_id
419
- add_index :geo_zones, :zone_name
420
- add_index :geo_zones, :zone_code
421
- end
422
-
423
- unless table_exists?(:notes)
424
- create_table :notes do |t|
425
- t.integer :created_by_id
426
- t.text :content
427
- t.references :noted_record, :polymorphic => true
428
- t.references :note_type
429
-
430
- t.timestamps
431
- end
432
-
433
- add_index :notes, [:noted_record_id, :noted_record_type]
434
- add_index :notes, :note_type_id
435
- add_index :notes, :created_by_id
436
- end
437
-
438
- unless table_exists?(:note_types)
439
- create_table :note_types do |t|
440
- #these columns are required to support the behavior of the plugin 'awesome_nested_set'
441
- t.integer :parent_id
442
- t.integer :lft
443
- t.integer :rgt
444
-
445
- t.string :description
446
- t.string :internal_identifier
447
- t.string :external_identifier
448
- t.references :note_type_record, :polymorphic => true
449
-
450
- t.timestamps
451
- end
452
-
453
- add_index :note_types, [:note_type_record_id, :note_type_record_type], :name => "note_type_record_idx"
454
- end
455
-
456
- unless table_exists?(:valid_note_types)
457
- create_table :valid_note_types do |t|
458
- t.references :valid_note_type_record, :polymorphic => true
459
- t.references :note_type
460
-
461
- t.timestamps
462
- end
463
-
464
- add_index :valid_note_types, [:valid_note_type_record_id, :valid_note_type_record_type], :name => "valid_note_type_record_idx"
465
- add_index :valid_note_types, :note_type_id
466
- end
467
-
468
- end
469
-
470
- def self.down
471
- [
472
- :currencies, :money, :compass_ae_instance_party_roles,
473
- :party_search_facts, :phone_numbers, :email_addresses,
474
- :postal_addresses, :contact_purposes, :contact_types,
475
- :contacts, :individuals, :organizations,
476
- :party_relationships, :relationship_types, :role_types,
477
- :party_roles, :parties, :categories, :category_classifications,
478
- :descriptive_assets, :view_types, :notes, :note_types, :valid_note_types, :compass_ae_instances
479
- ].each do |tbl|
480
- if table_exists?(tbl)
481
- drop_table tbl
482
- end
483
- end
484
-
485
- end
486
- end