Class: CouchbaseOrm::IndexMigration
- Inherits:
-
Object
- Object
- CouchbaseOrm::IndexMigration
show all
- Defined in:
- lib/couchbase-orm/index_migration.rb,
lib/couchbase-orm/index_migration/operations.rb,
lib/couchbase-orm/index_migration/query_builder.rb,
lib/couchbase-orm/index_migration/command_recorder.rb,
lib/couchbase-orm/index_migration/index_introspector.rb,
lib/couchbase-orm/index_migration/index_state_fetcher.rb,
lib/couchbase-orm/index_migration/migration_generator.rb
Defined Under Namespace
Modules: Operations
Classes: CommandRecorder, IndexIntrospector, IndexStateFetcher, IrreversibleMigration, MigrationGenerator, QueryBuilder
Instance Method Summary
collapse
Instance Method Details
#add_index(name, keys:, where: nil, num_replica: nil, defer_build: false) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/couchbase-orm/index_migration.rb', line 28
def add_index(name, keys:, where: nil, num_replica: nil, defer_build: false)
index_definition = CouchbaseOrm::IndexDefinition.new(
name: name,
keys: keys,
where: where,
defer_build: defer_build,
num_replica: num_replica
)
execute_operation(Operations::CreateIndex.new(index_definition))
end
|
#build_indexes(*index_names) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/couchbase-orm/index_migration.rb', line 43
def build_indexes(*index_names)
options = index_names.last.is_a?(Hash) ? index_names.pop : {}
unknown_keys = options.keys - [:wait]
raise ArgumentError.new("Unknown option(s): #{unknown_keys.join(', ')}") if unknown_keys.any?
execute_operation(Operations::BuildIndexes.new(index_names, wait: options.fetch(:wait, false)))
end
|
#execute_query(query) ⇒ Object
51
52
53
|
# File 'lib/couchbase-orm/index_migration.rb', line 51
def execute_query(query)
CouchbaseOrm::Connection.cluster.query(query, Couchbase::Options::Query.new)
end
|
#index_bucket ⇒ Object
59
60
61
62
63
64
|
# File 'lib/couchbase-orm/index_migration.rb', line 59
def index_bucket
bucket = CouchbaseOrm.config.index.effective_bucket
raise ArgumentError.new('Missing index bucket configuration') if bucket.to_s.strip.empty?
bucket
end
|
#migrate(direction) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/couchbase-orm/index_migration.rb', line 17
def migrate(direction)
direction = direction.to_sym
raise ArgumentError.new('direction must be :up or :down') unless %i[up down].include?(direction)
if direction == :up
run_up
else
run_down
end
end
|
#remove_index(name) ⇒ Object
39
40
41
|
# File 'lib/couchbase-orm/index_migration.rb', line 39
def remove_index(name)
execute_operation(Operations::RemoveIndex.new(name))
end
|
#wait_for_indexes_online(index_names) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/couchbase-orm/index_migration.rb', line 66
def wait_for_indexes_online(index_names)
names = Array(index_names).map(&:to_s)
loop do
return if IndexStateFetcher.new.online?(self, index_bucket, names)
sleep(1)
end
end
|