erp_tech_svcs 3.1.7 → 3.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +15 -0
  2. data/lib/erp_tech_svcs/extensions/active_record/has_security_roles.rb +1 -5
  3. data/lib/erp_tech_svcs/version.rb +1 -1
  4. data/spec/dummy/db/data_migrations/20130220143304_add_usd_currency.erp_base_erp_svcs.rb +12 -0
  5. data/spec/dummy/db/data_migrations/20130220143305_add_iso_codes.erp_base_erp_svcs.rb +19 -0
  6. data/spec/dummy/db/data_migrations/20130220143306_setup_compass_ae_instance.erp_base_erp_svcs.rb +21 -0
  7. data/spec/dummy/db/data_migrations/20130220143307_upgrade_compass_ae_instances_data.erp_base_erp_svcs.rb +19 -0
  8. data/spec/dummy/db/data_migrations/20130220143308_create_capability_scope_types.erp_tech_svcs.rb +15 -0
  9. data/spec/dummy/db/data_migrations/20130220143309_schedule_delete_expired_sessions_job.erp_tech_svcs.rb +16 -0
  10. data/spec/dummy/db/data_migrations/20130220143310_setup_audit_log_types.erp_tech_svcs.rb +22 -0
  11. data/spec/dummy/db/data_migrations/20130220143311_create_group_relationship_and_role_types.erp_tech_svcs.rb +20 -0
  12. data/spec/dummy/db/data_migrations/20130220143312_note_capabilities.erp_tech_svcs.rb +24 -0
  13. data/spec/dummy/db/data_migrations/20130422151256_add_guid_to_instances.erp_base_erp_svcs.rb +10 -0
  14. data/spec/dummy/db/migrate/20130220143259_base_erp_services.erp_base_erp_svcs.rb +486 -0
  15. data/spec/dummy/db/migrate/20130220143260_add_txn_status.erp_base_erp_svcs.rb +37 -0
  16. data/spec/dummy/db/migrate/20130220143261_upgrade_compass_ae_instances.erp_base_erp_svcs.rb +34 -0
  17. data/spec/dummy/db/migrate/20130220143262_base_tech_services.erp_tech_svcs.rb +271 -0
  18. data/spec/dummy/db/migrate/20130220143263_create_has_attribute_tables.erp_tech_svcs.rb +39 -0
  19. data/spec/dummy/db/migrate/20130220143264_create_groups.erp_tech_svcs.rb +19 -0
  20. data/spec/dummy/db/migrate/20130220143265_upgrade_security.erp_tech_svcs.rb +54 -0
  21. data/spec/dummy/db/migrate/20130220143266_upgrade_security2.erp_tech_svcs.rb +275 -0
  22. data/spec/dummy/db/migrate/20130422151250_add_uuid_compass_ae_instance.erp_base_erp_svcs.rb +17 -0
  23. data/spec/dummy/db/migrate/20130422151251_add_long_lat_to_address.erp_base_erp_svcs.rb +16 -0
  24. data/spec/dummy/db/migrate/20130422151252_add_queue_to_delayed_jobs.erp_tech_svcs.rb +14 -0
  25. data/spec/dummy/db/schema.rb +665 -0
  26. data/spec/dummy/db/spec.sqlite3 +0 -0
  27. metadata +51 -23
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzA2YjkzOTY3NTA1ZjU4NjdmZDc5Mjk1YmVkMTJkNTZiYTkzNzQzNQ==
5
+ data.tar.gz: !binary |-
6
+ NTE3NWRlNjZlZTg2ODRiMDlmMzExOTZmZWZiYTAwN2Y2YjQ5ZTRhZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YTE0MDZhZjFhNjM0YjcwOTFjZGVjMmI5YzE3N2YxNzk4MmZmNzZiNDFmZTEw
10
+ MzZiMjE3Y2I0OTBhYzU1MzNlYTU1MmJlZmQ4M2YxNTQ2MDEzYmI2MTczZGJj
11
+ NGI5Zjk2OTYwZjczNjdmMGMwZGE3M2JjZTFmZjZhNTMxYjE1ZTU=
12
+ data.tar.gz: !binary |-
13
+ Y2I3MjlkZTMwYTJjYTAwYTg1NDZkMDIxZDkyZmJhMmUyNzY0NTA1NTJmODJl
14
+ NTE3YzljNWY1YmM2MWUyMzc4ODNlNWM4YzI0ZjZlZjJkZjAzYThiM2UzODI2
15
+ NTNhYjE4NTdkMWVlOGI2ODlmMmZlNmM2NWM2NDgwMGU4MGQzYWM=
@@ -26,12 +26,8 @@ module ErpTechSvcs
26
26
 
27
27
  module InstanceMethods
28
28
 
29
- def join_parties_security_roles
30
- "parties_security_roles ON parties_security_roles.security_role_id=security_roles.id"
31
- end
32
-
33
29
  def roles_not
34
- SecurityRole.joins("LEFT JOIN #{join_parties_security_roles}").where("parties_security_roles.party_id IS NULL")
30
+ SecurityRole.where("id NOT IN (#{self.security_roles.select(:id).to_sql})")
35
31
  end
36
32
 
37
33
  def roles
@@ -2,7 +2,7 @@ module ErpTechSvcs
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,486 @@
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