bridge_cache 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/app/lib/bridge_cache/data/bridge_model.rb +9 -0
  3. data/app/models/bridge_cache/affiliated_sub_account.rb +3 -2
  4. data/app/models/bridge_cache/application_record.rb +1 -1
  5. data/app/models/bridge_cache/bridge_base_model.rb +22 -0
  6. data/app/models/bridge_cache/course_template.rb +8 -8
  7. data/app/models/bridge_cache/custom_field.rb +2 -2
  8. data/app/models/bridge_cache/domain.rb +1 -1
  9. data/app/models/bridge_cache/enrollment.rb +3 -3
  10. data/app/models/bridge_cache/grant.rb +3 -3
  11. data/app/models/bridge_cache/group.rb +6 -6
  12. data/app/models/bridge_cache/group_enrollment.rb +2 -2
  13. data/app/models/bridge_cache/learner_custom_field_value.rb +2 -2
  14. data/app/models/bridge_cache/live_course.rb +6 -6
  15. data/app/models/bridge_cache/live_course_enrollment.rb +4 -4
  16. data/app/models/bridge_cache/live_course_session.rb +5 -5
  17. data/app/models/bridge_cache/live_course_session_registration.rb +5 -5
  18. data/app/models/bridge_cache/membership.rb +2 -2
  19. data/app/models/bridge_cache/program.rb +7 -7
  20. data/app/models/bridge_cache/program_enrollment.rb +3 -3
  21. data/app/models/bridge_cache/program_group_enrollment.rb +3 -3
  22. data/app/models/bridge_cache/program_item.rb +2 -2
  23. data/app/models/bridge_cache/tag.rb +2 -2
  24. data/app/models/bridge_cache/tagging.rb +3 -3
  25. data/app/models/bridge_cache/user.rb +13 -13
  26. data/db/migrate/20170517203244_create_bridge_cache_domains.rb +3 -1
  27. data/db/migrate/20170517203328_create_bridge_cache_users.rb +1 -0
  28. data/db/migrate/20170517203421_create_bridge_cache_programs.rb +1 -0
  29. data/db/migrate/20170517204055_create_bridge_cache_custom_fields.rb +1 -0
  30. data/db/migrate/20170517204248_create_bridge_cache_grants.rb +1 -0
  31. data/db/migrate/20170518211404_create_bridge_cache_enrollments.rb +1 -0
  32. data/db/migrate/20170518211627_create_bridge_cache_groups.rb +1 -0
  33. data/db/migrate/20170518211703_create_bridge_cache_program_items.rb +1 -0
  34. data/db/migrate/20170518211714_create_bridge_cache_program_enrollments.rb +1 -0
  35. data/db/migrate/20170518211736_create_bridge_cache_program_group_enrollments.rb +1 -0
  36. data/db/migrate/20170518211748_create_bridge_cache_tags.rb +1 -0
  37. data/db/migrate/20170518211754_create_bridge_cache_taggings.rb +1 -0
  38. data/db/migrate/20170518211817_create_bridge_cache_course_templates.rb +1 -0
  39. data/db/migrate/20170523164248_create_bridge_cache_group_enrollments.rb +1 -0
  40. data/db/migrate/20170523165014_create_bridge_cache_memberships.rb +1 -0
  41. data/db/migrate/20170615145554_create_bridge_cache_learner_custom_field_values.rb +1 -0
  42. data/db/migrate/20171017211850_create_affiliated_sub_accounts.rb +1 -0
  43. data/db/migrate/20171019195443_create_live_courses.rb +1 -0
  44. data/db/migrate/20171019195503_create_live_course_enrollments.rb +1 -0
  45. data/db/migrate/20171019195512_create_live_course_session_registrations.rb +1 -0
  46. data/db/migrate/20171019195516_create_live_course_sessions.rb +1 -0
  47. data/db/migrate/20171031165231_add_indexes.rb +1 -0
  48. data/lib/bridge_cache.rb +21 -0
  49. data/lib/bridge_cache/version.rb +1 -1
  50. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12a709571d66b40c2d39368d3f4d9fa9f759467c
4
- data.tar.gz: dfbaea168af960c1ebe559b0159a3999ebbe4da0
3
+ metadata.gz: bcbcf635958dffd3ce2bf3434966ac404855cefd
4
+ data.tar.gz: d939dd4a949d0c9b48da19d5485337e8389d026a
5
5
  SHA512:
6
- metadata.gz: b4d141ef24a57517a61c330cec52f8e708e4ab9408e3a1126f432ebc6da872ea703159d23e1f4f90688b891755d85fd7dfedc645167ea81dc5b8c4796dfc9992
7
- data.tar.gz: 1f6543f447ace27377ad074aa24faa22525b6b08d05b8f86565f6ac31e0ccd3a3f108e4a3cbb25747046eb7a94d64902f290383ed6c6a70b3dc591936557d594
6
+ metadata.gz: 5955932e3fdc3eb63da5001c8b137d8bb3d6f1ec53a75994bc6f3d3946db4e6bfeca44ccb73d261df7f15ad94130c36f0c1b0579745808650fd1766e8ce08ff3
7
+ data.tar.gz: d094e6bac904d755590c98df015fd2ae4a16e9bb24f5a03fb0b4dde598183bbd069d729bd3162a2365abca17381a390dc16e268b210d0a7a53e107fd5714e002
@@ -1,10 +1,19 @@
1
1
  module BridgeCache::Data
2
2
  module BridgeModel
3
3
 
4
+ def adjusted_table_name
5
+ if BridgeCache.use_internal_database
6
+ table_name
7
+ else
8
+ self.to_s.demodulize.underscore.pluralize
9
+ end
10
+ end
11
+
4
12
  def self.extended(base)
5
13
  base.class_eval do
6
14
  scope :in_domain, -> (domain_id) {for_domain(domain_id)}
7
15
  scope :active, -> {is_active?}
16
+ self.table_name = self.adjusted_table_name
8
17
  end
9
18
  end
10
19
 
@@ -1,11 +1,11 @@
1
1
  module BridgeCache
2
- class AffiliatedSubAccount < ActiveRecord::Base
2
+ class AffiliatedSubAccount < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
5
  before_save :fix_item_type
6
6
 
7
7
  belongs_to :item, polymorphic: true, optional: true
8
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
8
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
9
9
 
10
10
  private
11
11
 
@@ -16,5 +16,6 @@ module BridgeCache
16
16
  def self.cleanup(current_row_ids)
17
17
  BridgeCache::AffiliatedSubAccount.where.not(bridge_id: current_row_ids).destroy_all
18
18
  end
19
+
19
20
  end
20
21
  end
@@ -1,5 +1,5 @@
1
1
  module BridgeCache
2
- class ApplicationRecord < ActiveRecord::Base
2
+ class ApplicationRecord < BridgeBaseModel
3
3
  self.abstract_class = true
4
4
  end
5
5
  end
@@ -0,0 +1,22 @@
1
+ module BridgeCache
2
+ class BridgeBaseModel < ActiveRecord::Base
3
+ self.abstract_class = true
4
+
5
+ def bridge_id
6
+ if self.class.column_names.include? "bridge_id"
7
+ self[:bridge_id]
8
+ else
9
+ id
10
+ end
11
+ end
12
+
13
+ def adjusted_table_name
14
+ if BridgeCache.use_internal_database
15
+ table_name
16
+ else
17
+ self.to_s.demodulize.underscore.pluralize
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -1,15 +1,15 @@
1
1
  module BridgeCache
2
- class CourseTemplate < ActiveRecord::Base
2
+ class CourseTemplate < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
6
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
8
- has_many :enrollments, foreign_key: :course_template_id, primary_key: :bridge_id, class_name: 'BridgeCache::Enrollment'
9
- has_many :group_enrollments, foreign_key: :course_template_id, primary_key: :bridge_id, class_name: 'BridgeCache::GroupEnrollment'
10
- has_many :affiliated_sub_accounts, primary_key: :bridge_id, class_name: 'BridgeCache::AffiliatedSubAccount', as: :item
5
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
6
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
7
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
8
+ has_many :enrollments, foreign_key: :course_template_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Enrollment'
9
+ has_many :group_enrollments, foreign_key: :course_template_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::GroupEnrollment'
10
+ has_many :affiliated_sub_accounts, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::AffiliatedSubAccount', as: :item
11
11
  has_many :domains, through: :affiliated_sub_accounts
12
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
12
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
13
13
 
14
14
  def self.for_domain(domain_id)
15
15
  includes(:domains)
@@ -1,8 +1,8 @@
1
1
  module BridgeCache
2
- class CustomField < ActiveRecord::Base
2
+ class CustomField < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
5
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
6
6
  has_many :learner_custom_field_values, primary_key: 'bridge_id', foreign_key: :custom_field_id, class_name: 'BridgeCache::LearnerCustomFieldValue'
7
7
 
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module BridgeCache
2
- class Domain < ActiveRecord::Base
2
+ class Domain < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
5
  has_many :domain_children, primary_key: 'bridge_id', foreign_key: 'parent_id', class_name: 'BridgeCache::Domain'
@@ -1,13 +1,13 @@
1
1
  module BridgeCache
2
- class Enrollment < ActiveRecord::Base
2
+ class Enrollment < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
5
  def self.for_domain(domain_id)
6
6
  joins(:course_template).merge(BridgeCache::CourseTemplate.for_domain(domain_id))
7
7
  end
8
8
 
9
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
10
- belongs_to :course_template, foreign_key: :course_template_id, primary_key: :bridge_id, class_name: 'BridgeCache::CourseTemplate', optional: true
9
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
10
+ belongs_to :course_template, foreign_key: :course_template_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::CourseTemplate', optional: true
11
11
 
12
12
  end
13
13
  end
@@ -1,9 +1,9 @@
1
1
  module BridgeCache
2
- class Grant < ActiveRecord::Base
2
+ class Grant < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
6
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
5
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
6
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
7
7
 
8
8
  end
9
9
  end
@@ -1,14 +1,14 @@
1
1
  module BridgeCache
2
- class Group < ActiveRecord::Base
2
+ class Group < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
5
  self.inheritance_column = nil
6
6
 
7
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
8
- has_many :program_group_enrollments, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramGroupEnrollment'
9
- has_many :group_enrollments, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::GroupEnrollment'
10
- has_many :memberships, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::Membership'
11
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
8
+ has_many :program_group_enrollments, foreign_key: :group_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::ProgramGroupEnrollment'
9
+ has_many :group_enrollments, foreign_key: :group_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::GroupEnrollment'
10
+ has_many :memberships, foreign_key: :group_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Membership'
11
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
12
12
 
13
13
  end
14
14
  end
@@ -6,8 +6,8 @@ module BridgeCache
6
6
  joins(:course_template).where(bridge_cache_course_templates: {domain_id: domain_id})
7
7
  end
8
8
 
9
- belongs_to :group, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::Group', optional: true
10
- belongs_to :course_template, foreign_key: :course_template_id, primary_key: :bridge_id, class_name: 'BridgeCache::CourseTemplate', optional: true
9
+ belongs_to :group, foreign_key: :group_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Group', optional: true
10
+ belongs_to :course_template, foreign_key: :course_template_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::CourseTemplate', optional: true
11
11
 
12
12
  end
13
13
  end
@@ -6,8 +6,8 @@ module BridgeCache
6
6
  joins(:user).where(bridge_cache_users: {domain_id: domain_id})
7
7
  end
8
8
 
9
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
10
- belongs_to :custom_field, foreign_key: :custom_field_id, primary_key: :bridge_id, class_name: 'BridgeCache::CustomField', optional: true
9
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
10
+ belongs_to :custom_field, foreign_key: :custom_field_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::CustomField', optional: true
11
11
 
12
12
  end
13
13
  end
@@ -1,12 +1,12 @@
1
1
  module BridgeCache
2
- class LiveCourse < ActiveRecord::Base
2
+ class LiveCourse < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
6
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
8
- has_many :live_course_enrollments, foreign_key: :live_course_id, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourseEnrollment'
9
- has_many :affiliated_sub_accounts, primary_key: :bridge_id, class_name: 'BridgeCache::AffiliatedSubAccount', as: :item
5
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
6
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
7
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
8
+ has_many :live_course_enrollments, foreign_key: :live_course_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourseEnrollment'
9
+ has_many :affiliated_sub_accounts, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::AffiliatedSubAccount', as: :item
10
10
  has_many :domains, through: :affiliated_sub_accounts
11
11
 
12
12
  def self.for_domain(domain_id)
@@ -1,14 +1,14 @@
1
1
  module BridgeCache
2
- class LiveCourseEnrollment < ActiveRecord::Base
2
+ class LiveCourseEnrollment < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
5
  def self.for_domain(domain_id)
6
6
  joins(:live_course).merge(BridgeCache::LiveCourse.for_domain(domain_id))
7
7
  end
8
8
 
9
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
10
- belongs_to :live_course, foreign_key: :live_course_id, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourse', optional: true
11
- has_many :live_course_session_registrations, foreign_key: :live_course_enrollment_id, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourseSessionRegistration'
9
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
10
+ belongs_to :live_course, foreign_key: :live_course_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourse', optional: true
11
+ has_many :live_course_session_registrations, foreign_key: :live_course_enrollment_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourseSessionRegistration'
12
12
 
13
13
  end
14
14
  end
@@ -1,15 +1,15 @@
1
1
  module BridgeCache
2
- class LiveCourseSession < ActiveRecord::Base
2
+ class LiveCourseSession < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
5
  def self.for_domain(domain_id)
6
6
  joins(:live_course).merge(BridgeCache::LiveCourse.for_domain(domain_id))
7
7
  end
8
8
 
9
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
10
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
11
- belongs_to :live_course, foreign_key: :live_course_id, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourse', optional: true
12
- has_many :live_course_session_registrations, foreign_key: :live_course_session_id, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourseSessionRegistration'
9
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
10
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
11
+ belongs_to :live_course, foreign_key: :live_course_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourse', optional: true
12
+ has_many :live_course_session_registrations, foreign_key: :live_course_session_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourseSessionRegistration'
13
13
 
14
14
  end
15
15
  end
@@ -1,15 +1,15 @@
1
1
  module BridgeCache
2
- class LiveCourseSessionRegistration < ActiveRecord::Base
2
+ class LiveCourseSessionRegistration < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
5
  def self.for_domain(domain_id)
6
6
  joins(:live_course_enrollment).merge(BridgeCache::LiveCourseEnrollment.for_domain(domain_id))
7
7
  end
8
8
 
9
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
10
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
11
- belongs_to :live_course_enrollment, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourseEnrollment', optional: true
12
- belongs_to :live_course_session, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourseSession', optional: true
9
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
10
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
11
+ belongs_to :live_course_enrollment, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourseEnrollment', optional: true
12
+ belongs_to :live_course_session, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourseSession', optional: true
13
13
 
14
14
  end
15
15
  end
@@ -2,8 +2,8 @@ module BridgeCache
2
2
  class Membership < ApplicationRecord
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :group, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::Group', optional: true
6
- belongs_to :user, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
5
+ belongs_to :group, foreign_key: :group_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Group', optional: true
6
+ belongs_to :user, foreign_key: :group_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
7
7
 
8
8
  def self.for_domain(domain_id)
9
9
  joins(:group).where(bridge_cache_groups: {domain_id: domain_id})
@@ -1,13 +1,13 @@
1
1
  module BridgeCache
2
- class Program < ActiveRecord::Base
2
+ class Program < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
6
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
- has_many :program_items, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramItem'
8
- has_many :program_enrollments, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramEnrollment'
9
- has_many :program_group_enrollments, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramGroupEnrollment'
10
- has_many :affiliated_sub_accounts, primary_key: :bridge_id, class_name: 'BridgeCache::AffiliatedSubAccount', as: :item
5
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
6
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
7
+ has_many :program_items, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::ProgramItem'
8
+ has_many :program_enrollments, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::ProgramEnrollment'
9
+ has_many :program_group_enrollments, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::ProgramGroupEnrollment'
10
+ has_many :affiliated_sub_accounts, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::AffiliatedSubAccount', as: :item
11
11
  has_many :domains, through: :affiliated_sub_accounts
12
12
 
13
13
  def self.for_domain(domain_id)
@@ -1,9 +1,9 @@
1
1
  module BridgeCache
2
- class ProgramEnrollment < ActiveRecord::Base
2
+ class ProgramEnrollment < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :user, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
6
- belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program', optional: true
5
+ belongs_to :user, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
6
+ belongs_to :program, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Program', optional: true
7
7
 
8
8
  def self.for_domain(domain_id)
9
9
  joins(:program).merge(BridgeCache::Program.for_domain(domain_id))
@@ -1,9 +1,9 @@
1
1
  module BridgeCache
2
- class ProgramGroupEnrollment < ActiveRecord::Base
2
+ class ProgramGroupEnrollment < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :group, foreign_key: :group_id, primary_key: :bridge_id, class_name: 'BridgeCache::Group', optional: true
6
- belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program', optional: true
5
+ belongs_to :group, foreign_key: :group_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Group', optional: true
6
+ belongs_to :program, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Program', optional: true
7
7
 
8
8
  end
9
9
  end
@@ -1,8 +1,8 @@
1
1
  module BridgeCache
2
- class ProgramItem < ActiveRecord::Base
2
+ class ProgramItem < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :program, foreign_key: :program_id, primary_key: :bridge_id, class_name: 'BridgeCache::Program', optional: true
5
+ belongs_to :program, foreign_key: :program_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Program', optional: true
6
6
 
7
7
  def self.for_domain(domain_id)
8
8
  joins(:program).merge(BridgeCache::Program.for_domain(domain_id))
@@ -1,8 +1,8 @@
1
1
  module BridgeCache
2
- class Tag < ActiveRecord::Base
2
+ class Tag < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- has_many :taggings, foreign_key: :tag_id, primary_key: :bridge_id, class_name: 'BridgeCache::Tagging'
5
+ has_many :taggings, foreign_key: :tag_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Tagging'
6
6
 
7
7
  end
8
8
  end
@@ -1,9 +1,9 @@
1
1
  module BridgeCache
2
- class Tagging < ActiveRecord::Base
2
+ class Tagging < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :tag, foreign_key: :tag_id, primary_key: :bridge_id, class_name: 'BridgeCache::Tag', optional: true
6
- belongs_to :user, foreign_key: :tagger_id, primary_key: :bridge_id, class_name: 'BridgeCache::User', optional: true
5
+ belongs_to :tag, foreign_key: :tag_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Tag', optional: true
6
+ belongs_to :user, foreign_key: :tagger_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::User', optional: true
7
7
 
8
8
  def self.cleanup(current_row_ids)
9
9
  BridgeCache::Tagging.where.not(bridge_id: current_row_ids).destroy_all
@@ -1,19 +1,19 @@
1
1
  module BridgeCache
2
- class User < ActiveRecord::Base
2
+ class User < BridgeBaseModel
3
3
  extend BridgeCache::Data::BridgeModel
4
4
 
5
- belongs_to :domain, foreign_key: :domain_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
6
- belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: :bridge_id, class_name: 'BridgeCache::Domain', optional: true
7
- has_many :enrollments, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::Enrollment'
8
- has_many :course_templates, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::CourseTemplate'
9
- has_many :taggings, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::Tagging'
10
- has_many :grants, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::Grant'
11
- has_many :groups, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::Group'
12
- has_many :program_enrollments, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::ProgramEnrollment'
13
- has_many :memberships, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::Membership'
14
- has_many :learner_custom_field_values, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::LearnerCustomFieldValue'
15
- has_many :live_course_enrollments, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourseEnrollment'
16
- has_many :live_course_session_registrations, foreign_key: :user_id, primary_key: :bridge_id, class_name: 'BridgeCache::LiveCourseSessionRegistration'
5
+ belongs_to :domain, foreign_key: :domain_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
6
+ belongs_to :sub_account, foreign_key: :sub_account_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Domain', optional: true
7
+ has_many :enrollments, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Enrollment'
8
+ has_many :course_templates, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::CourseTemplate'
9
+ has_many :taggings, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Tagging'
10
+ has_many :grants, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Grant'
11
+ has_many :groups, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Group'
12
+ has_many :program_enrollments, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::ProgramEnrollment'
13
+ has_many :memberships, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::Membership'
14
+ has_many :learner_custom_field_values, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LearnerCustomFieldValue'
15
+ has_many :live_course_enrollments, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourseEnrollment'
16
+ has_many :live_course_session_registrations, foreign_key: :user_id, primary_key: BridgeCache.primary_key, class_name: 'BridgeCache::LiveCourseSessionRegistration'
17
17
 
18
18
  serialize :config
19
19
 
@@ -1,6 +1,8 @@
1
1
  class CreateBridgeCacheDomains < ActiveRecord::Migration[5.0]
2
2
  def change
3
- create_table :bridge_cache_domains do |t|
3
+ return unless BridgeCache.use_internal_database
4
+ key = Rails.env == 'test' ? :bridge_cache_domains : :domains
5
+ create_table key do |t|
4
6
  t.integer :bridge_id, limit: 8
5
7
  t.string :name
6
8
  t.integer :parent_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheUsers < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_users do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.string :email
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCachePrograms < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_programs do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.string :title
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheCustomFields < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_custom_fields do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.string :name
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheGrants < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_grants do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :user_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheEnrollments < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_enrollments do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :user_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheGroups < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_groups do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.string :name
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheProgramItems < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_program_items do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :program_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheProgramEnrollments < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_program_enrollments do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :user_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheProgramGroupEnrollments < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_program_group_enrollments do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :group_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheTags < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_tags do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.string :name
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheTaggings < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_taggings do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :tag_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheCourseTemplates < ActiveRecord::Migration[5.0]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_course_templates do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.string :title
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheGroupEnrollments < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_group_enrollments do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :group_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheMemberships < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_memberships do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :group_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateBridgeCacheLearnerCustomFieldValues < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_learner_custom_field_values do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :custom_field_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateAffiliatedSubAccounts < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_affiliated_sub_accounts do |t|
4
5
  t.integer :bridge_id
5
6
  t.integer :item_id
@@ -1,5 +1,6 @@
1
1
  class CreateLiveCourses < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_live_courses do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.string :title
@@ -1,5 +1,6 @@
1
1
  class CreateLiveCourseEnrollments < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_live_course_enrollments do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :live_course_id,limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateLiveCourseSessionRegistrations < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_live_course_session_registrations do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.integer :live_course_session_id, limit: 8
@@ -1,5 +1,6 @@
1
1
  class CreateLiveCourseSessions < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  create_table :bridge_cache_live_course_sessions do |t|
4
5
  t.integer :bridge_id, limit: 8
5
6
  t.datetime :start_at
@@ -1,5 +1,6 @@
1
1
  class AddIndexes < ActiveRecord::Migration[5.1]
2
2
  def change
3
+ return unless BridgeCache.use_internal_database
3
4
  add_index :bridge_cache_domains, :bridge_id
4
5
  add_index :bridge_cache_domains, :parent_id
5
6
  add_index :bridge_cache_domains, :owner_id
data/lib/bridge_cache.rb CHANGED
@@ -2,4 +2,25 @@ require "bridge_cache/engine"
2
2
  require 'bridge_blueprint'
3
3
 
4
4
  module BridgeCache
5
+
6
+ class << self
7
+
8
+ WRITER_METHODS = [:use_internal_database]
9
+
10
+ attr_writer(*WRITER_METHODS)
11
+
12
+ def configure
13
+ yield self if block_given?
14
+ end
15
+
16
+ def use_internal_database
17
+ return @use_internal_database if defined?(@use_internal_database)
18
+
19
+ @use_internal_database = true
20
+ end
21
+
22
+ def primary_key
23
+ @use_internal_database ? :bridge_id : :id
24
+ end
25
+ end
5
26
  end
@@ -1,3 +1,3 @@
1
1
  module BridgeCache
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridge_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jshaffer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -205,6 +205,7 @@ files:
205
205
  - app/lib/bridge_cache/webhooks/request.rb
206
206
  - app/models/bridge_cache/affiliated_sub_account.rb
207
207
  - app/models/bridge_cache/application_record.rb
208
+ - app/models/bridge_cache/bridge_base_model.rb
208
209
  - app/models/bridge_cache/course_template.rb
209
210
  - app/models/bridge_cache/custom_field.rb
210
211
  - app/models/bridge_cache/domain.rb