nobrainer 0.27.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/no_brainer/config.rb +36 -8
  3. data/lib/no_brainer/connection.rb +16 -19
  4. data/lib/no_brainer/connection_manager.rb +10 -10
  5. data/lib/no_brainer/criteria.rb +1 -1
  6. data/lib/no_brainer/criteria/eager_load.rb +1 -1
  7. data/lib/no_brainer/criteria/find.rb +1 -1
  8. data/lib/no_brainer/criteria/first.rb +2 -2
  9. data/lib/no_brainer/criteria/first_or_create.rb +32 -19
  10. data/lib/no_brainer/criteria/join.rb +62 -0
  11. data/lib/no_brainer/criteria/where.rb +25 -14
  12. data/lib/no_brainer/document.rb +1 -1
  13. data/lib/no_brainer/document/association/belongs_to.rb +4 -3
  14. data/lib/no_brainer/document/association/eager_loader.rb +26 -25
  15. data/lib/no_brainer/document/association/has_many.rb +3 -2
  16. data/lib/no_brainer/document/association/has_many_through.rb +1 -2
  17. data/lib/no_brainer/document/association/has_one.rb +4 -0
  18. data/lib/no_brainer/document/atomic_ops.rb +31 -4
  19. data/lib/no_brainer/document/attributes.rb +12 -9
  20. data/lib/no_brainer/document/core.rb +18 -18
  21. data/lib/no_brainer/document/criteria.rb +3 -2
  22. data/lib/no_brainer/document/dirty.rb +3 -3
  23. data/lib/no_brainer/document/index.rb +3 -3
  24. data/lib/no_brainer/document/index/index.rb +5 -5
  25. data/lib/no_brainer/document/index/meta_store.rb +1 -1
  26. data/lib/no_brainer/document/index/synchronizer.rb +5 -17
  27. data/lib/no_brainer/document/missing_attributes.rb +7 -2
  28. data/lib/no_brainer/document/primary_key.rb +14 -8
  29. data/lib/no_brainer/document/table_config.rb +118 -0
  30. data/lib/no_brainer/document/table_config/synchronizer.rb +21 -0
  31. data/lib/no_brainer/document/timestamps.rb +4 -0
  32. data/lib/no_brainer/document/validation/core.rb +1 -1
  33. data/lib/no_brainer/document/validation/uniqueness.rb +1 -1
  34. data/lib/no_brainer/lock.rb +4 -4
  35. data/lib/no_brainer/profiler/logger.rb +1 -1
  36. data/lib/no_brainer/query_runner/database_on_demand.rb +1 -1
  37. data/lib/no_brainer/query_runner/reconnect.rb +37 -21
  38. data/lib/no_brainer/query_runner/table_on_demand.rb +12 -5
  39. data/lib/no_brainer/railtie/database.rake +14 -4
  40. data/lib/no_brainer/rql.rb +3 -2
  41. data/lib/no_brainer/symbol_decoration.rb +1 -1
  42. data/lib/no_brainer/system.rb +17 -0
  43. data/lib/no_brainer/system/cluster_config.rb +5 -0
  44. data/lib/no_brainer/system/db_config.rb +5 -0
  45. data/lib/no_brainer/system/document.rb +24 -0
  46. data/lib/no_brainer/system/issue.rb +10 -0
  47. data/lib/no_brainer/system/job.rb +10 -0
  48. data/lib/no_brainer/system/log.rb +11 -0
  49. data/lib/no_brainer/system/server_config.rb +7 -0
  50. data/lib/no_brainer/system/server_status.rb +9 -0
  51. data/lib/no_brainer/system/stat.rb +11 -0
  52. data/lib/no_brainer/system/table_config.rb +10 -0
  53. data/lib/no_brainer/system/table_status.rb +8 -0
  54. data/lib/nobrainer.rb +7 -6
  55. data/lib/rails/generators/templates/nobrainer.rb +11 -2
  56. metadata +17 -3
  57. data/lib/no_brainer/document/store_in.rb +0 -33
@@ -1,5 +1,5 @@
1
1
  module NoBrainer::SymbolDecoration
2
- NON_CHAINABLE_OPERATORS = %w(in eq gt ge gte lt le lte defined near intersects).map(&:to_sym)
2
+ NON_CHAINABLE_OPERATORS = %w(in eq gt ge gte lt le lte defined undefined near intersects include).map(&:to_sym)
3
3
  CHAINABLE_OPERATORS = %w(not any all).map(&:to_sym)
4
4
  OPERATORS = CHAINABLE_OPERATORS + NON_CHAINABLE_OPERATORS
5
5
 
@@ -0,0 +1,17 @@
1
+ module NoBrainer::System
2
+ extend NoBrainer::Autoload
3
+ autoload :Document, :ClusterConfig, :DBConfig,
4
+ :Issue, :Job, :Log, :ServerConfig, :ServerStatus,
5
+ :Stat, :TableConfig, :TableStatus
6
+
7
+ # A few shortcuts to make user's life easier
8
+ def self.const_missing(const_name)
9
+ mapping = {:CurrentIssues => :Issue,
10
+ :CurrentIssue => :Issue,
11
+ :Issues => :Issue,
12
+ :Jobs => :Job,
13
+ :Logs => :Log,
14
+ :Stats => :Stat}
15
+ const_get(mapping[const_name] || const_name)
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ class NoBrainer::System::ClusterConfig
2
+ include NoBrainer::System::Document
3
+
4
+ field :auth_key
5
+ end
@@ -0,0 +1,5 @@
1
+ class NoBrainer::System::DBConfig
2
+ include NoBrainer::System::Document
3
+
4
+ field :name
5
+ end
@@ -0,0 +1,24 @@
1
+ module NoBrainer::System::Document
2
+ extend ActiveSupport::Concern
3
+
4
+ include NoBrainer::Document
5
+ include NoBrainer::Document::DynamicAttributes
6
+
7
+ included do
8
+ disable_perf_warnings
9
+
10
+ field :id, :type => Object, :default => nil, :primary_key => true
11
+
12
+ default_scope { without_ordering }
13
+ end
14
+
15
+ module ClassMethods
16
+ def table_name
17
+ table_config_options[:name] || name.split('::').last.underscore
18
+ end
19
+
20
+ def rql_table
21
+ RethinkDB::RQL.new.db('rethinkdb').table(table_name)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ class NoBrainer::System::Issue
2
+ include NoBrainer::System::Document
3
+
4
+ table_config :name => 'current_issues'
5
+
6
+ field :type
7
+ field :critical
8
+ field :info
9
+ field :description
10
+ end
@@ -0,0 +1,10 @@
1
+ class NoBrainer::System::Job
2
+ include NoBrainer::System::Document
3
+
4
+ table_config :name => 'jobs'
5
+
6
+ field :duration_sec
7
+ field :info
8
+ field :servers
9
+ field :type
10
+ end
@@ -0,0 +1,11 @@
1
+ class NoBrainer::System::Log
2
+ include NoBrainer::System::Document
3
+
4
+ table_config :name => 'logs'
5
+
6
+ field :level
7
+ field :message
8
+ field :server
9
+ field :timestamp
10
+ field :uptime
11
+ end
@@ -0,0 +1,7 @@
1
+ class NoBrainer::System::ServerConfig
2
+ include NoBrainer::System::Document
3
+
4
+ field :name
5
+ field :cache_size_mb
6
+ field :tags
7
+ end
@@ -0,0 +1,9 @@
1
+ class NoBrainer::System::ServerStatus
2
+ include NoBrainer::System::Document
3
+
4
+ field :name
5
+ field :status
6
+ field :connection
7
+ field :network
8
+ field :process
9
+ end
@@ -0,0 +1,11 @@
1
+ class NoBrainer::System::Stat
2
+ include NoBrainer::System::Document
3
+
4
+ table_config :name => 'stats'
5
+
6
+ field :server
7
+ field :db
8
+ field :table
9
+ field :query_engine
10
+ field :storage_engine
11
+ end
@@ -0,0 +1,10 @@
1
+ class NoBrainer::System::TableConfig
2
+ include NoBrainer::System::Document
3
+
4
+ field :db
5
+ field :name
6
+ field :durability
7
+ field :primary_key
8
+ field :shards
9
+ field :write_acks
10
+ end
@@ -0,0 +1,8 @@
1
+ class NoBrainer::System::TableStatus
2
+ include NoBrainer::System::Document
3
+
4
+ field :db
5
+ field :name
6
+ field :status
7
+ field :shards
8
+ end
data/lib/nobrainer.rb CHANGED
@@ -5,7 +5,7 @@ require 'thread'
5
5
  %w(module/delegation module/attribute_accessors module/introspection
6
6
  class/attribute object/blank object/inclusion object/deep_dup
7
7
  object/try hash/keys hash/indifferent_access hash/reverse_merge
8
- hash/deep_merge array/extract_options)
8
+ hash/deep_merge hash/slice array/extract_options)
9
9
  .each { |dep| require "active_support/core_ext/#{dep}" }
10
10
 
11
11
  module NoBrainer
@@ -16,22 +16,23 @@ module NoBrainer
16
16
  # Code that is loaded through the DSL of NoBrainer should not be eager loaded.
17
17
  autoload :Document, :IndexManager, :Loader, :Fork, :Geo, :SymbolDecoration
18
18
  eager_autoload :Config, :Connection, :ConnectionManager, :Error,
19
- :QueryRunner, :Criteria, :RQL, :Lock, :Profiler
19
+ :QueryRunner, :Criteria, :RQL, :Lock, :Profiler, :System
20
20
 
21
21
  class << self
22
22
  delegate :connection, :disconnect, :to => 'NoBrainer::ConnectionManager'
23
23
 
24
- delegate :db_create, :db_drop, :db_list,
25
- :table_create, :table_drop, :table_list,
26
- :drop!, :purge!, :default_db, :current_db, :to => :connection
24
+ delegate :drop!, :purge!, :default_db, :current_db, :to => :connection
27
25
 
28
26
  delegate :configure, :logger, :to => 'NoBrainer::Config'
29
27
  delegate :run, :to => 'NoBrainer::QueryRunner'
30
- delegate :sync_indexes, :to => 'NoBrainer::Document::Index::Synchronizer'
31
28
  delegate :current_run_options, :run_with, :to => 'NoBrainer::QueryRunner::RunOptions'
32
29
 
33
30
  delegate :with, :with_database, :to => 'NoBrainer::QueryRunner::RunOptions' # deprecated
34
31
 
32
+ delegate :sync_indexes, :sync_table_config, :sync_schema, :rebalance, :to => 'NoBrainer::Document::TableConfig'
33
+
34
+ delegate :eager_load, :to => 'NoBrainer::Document::Association::EagerLoader'
35
+
35
36
  def jruby?
36
37
  RUBY_PLATFORM == 'java'
37
38
  end
@@ -7,7 +7,8 @@ NoBrainer.configure do |config|
7
7
  # variables RUBY_ENV, RAILS_ENV, RACK_ENV, or :production.
8
8
  # config.environment = config.default_environment
9
9
 
10
- # The rethinkdb_url specifies the RethinkDB database connection url.
10
+ # rethinkdb_urls specifies the RethinkDB database connection urls.
11
+ # You may specify multiple urls to provide fault tolerance capabilities.
11
12
  # When left unspecified, NoBrainer picks a database connection by default.
12
13
  # The default is to use localhost, with a database name matching the
13
14
  # application name and the environment.
@@ -15,7 +16,11 @@ NoBrainer.configure do |config|
15
16
  # * RETHINKDB_URL, RDB_URL
16
17
  # * RETHINKDB_HOST, RETHINKDB_PORT, RETHINKDB_DB, RETHINKDB_AUTH
17
18
  # * RDB_HOST, RDB_PORT, RDB_DB, RDB_AUTH
18
- # config.rethinkdb_url = config.default_rethinkdb_url
19
+ # config.rethinkdb_urls = [config.default_rethinkdb_url]
20
+
21
+ # ssl_options may be set to {:ca_certs => '/path/to/ca.crt'} to establish
22
+ # an SSL connection to the RethinkDB servers.
23
+ # config.ssl_options = nil
19
24
 
20
25
  # NoBrainer uses logger to emit debugging information.
21
26
  # The default logger is the Rails logger if run with Rails,
@@ -46,6 +51,10 @@ NoBrainer.configure do |config|
46
51
  # The default is :soft for development or test environment, otherwise :hard.
47
52
  # config.durability = config.default_durability
48
53
 
54
+ # Configures the default table configuration options. These values are
55
+ # reflected to the database when running `rake nobrainer:sync_schema'.
56
+ # config.table_options = { :shards => 1, :replicas => 1, :write_acks => :majority }
57
+
49
58
  # Persisted Strings have a configurable maximum length. To get rid of the
50
59
  # length validation, you may use the Text type instead.
51
60
  # config.max_string_length = 255
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nobrainer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Viennot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-12 00:00:00.000000000 Z
11
+ date: 2015-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rethinkdb
@@ -108,6 +108,7 @@ files:
108
108
  - lib/no_brainer/criteria/first.rb
109
109
  - lib/no_brainer/criteria/first_or_create.rb
110
110
  - lib/no_brainer/criteria/index.rb
111
+ - lib/no_brainer/criteria/join.rb
111
112
  - lib/no_brainer/criteria/limit.rb
112
113
  - lib/no_brainer/criteria/order_by.rb
113
114
  - lib/no_brainer/criteria/pluck.rb
@@ -146,7 +147,8 @@ files:
146
147
  - lib/no_brainer/document/primary_key/generator.rb
147
148
  - lib/no_brainer/document/readonly.rb
148
149
  - lib/no_brainer/document/serialization.rb
149
- - lib/no_brainer/document/store_in.rb
150
+ - lib/no_brainer/document/table_config.rb
151
+ - lib/no_brainer/document/table_config/synchronizer.rb
150
152
  - lib/no_brainer/document/timestamps.rb
151
153
  - lib/no_brainer/document/types.rb
152
154
  - lib/no_brainer/document/types/binary.rb
@@ -192,6 +194,18 @@ files:
192
194
  - lib/no_brainer/railtie/database.rake
193
195
  - lib/no_brainer/rql.rb
194
196
  - lib/no_brainer/symbol_decoration.rb
197
+ - lib/no_brainer/system.rb
198
+ - lib/no_brainer/system/cluster_config.rb
199
+ - lib/no_brainer/system/db_config.rb
200
+ - lib/no_brainer/system/document.rb
201
+ - lib/no_brainer/system/issue.rb
202
+ - lib/no_brainer/system/job.rb
203
+ - lib/no_brainer/system/log.rb
204
+ - lib/no_brainer/system/server_config.rb
205
+ - lib/no_brainer/system/server_status.rb
206
+ - lib/no_brainer/system/stat.rb
207
+ - lib/no_brainer/system/table_config.rb
208
+ - lib/no_brainer/system/table_status.rb
195
209
  - lib/nobrainer.rb
196
210
  - lib/rails/generators/nobrainer/install_generator.rb
197
211
  - lib/rails/generators/nobrainer/model_generator.rb
@@ -1,33 +0,0 @@
1
- require 'rethinkdb'
2
-
3
- module NoBrainer::Document::StoreIn
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- cattr_accessor :store_in_options, :instance_accessor => false
8
- self.store_in_options = {}
9
- end
10
-
11
- module ClassMethods
12
- def store_in(options)
13
- raise "store_in() must be called on the parent class" unless is_root_class?
14
-
15
- if options[:database] || options[:db]
16
- STDERR.puts "[NoBrainer] `store_in(db: ...)' has been removed. Use `run_with(db: ...)' instead. Sorry."
17
- end
18
-
19
- options.assert_valid_keys(:table)
20
- self.store_in_options.merge!(options)
21
- end
22
-
23
- def table_name
24
- table = store_in_options[:table]
25
- table_name = table.is_a?(Proc) ? table.call : table
26
- table_name.try(:to_s) || root_class.name.tableize.gsub('/', '__')
27
- end
28
-
29
- def rql_table
30
- RethinkDB::RQL.new.table(table_name)
31
- end
32
- end
33
- end