cassie 1.0.0.beta.33 → 1.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cassie +8 -181
- data/lib/cassie/configuration/core.rb +26 -3
- data/lib/cassie/configuration/generator.rb +1 -0
- data/lib/cassie/configuration/loading.rb +5 -2
- data/lib/cassie/configuration.rb +1 -0
- data/lib/cassie/connection.rb +13 -7
- data/lib/cassie/connection_handler/README.md +13 -3
- data/lib/cassie/connection_handler/cluster.rb +11 -0
- data/lib/cassie/connection_handler/sessions.rb +9 -0
- data/lib/cassie/connection_handler.rb +8 -7
- data/lib/cassie/definition.rb +28 -0
- data/lib/cassie/extensions/object/color_methods.rb +21 -0
- data/lib/cassie/instrumentation.rb +4 -0
- data/lib/cassie/modification.rb +29 -0
- data/lib/cassie/query.rb +27 -0
- data/lib/cassie/schema/README.md +306 -0
- data/lib/cassie/schema/apply_command.rb +24 -0
- data/lib/cassie/schema/cassandra_migrations/importer.rb +91 -0
- data/lib/cassie/schema/cassandra_migrations/migration_file.rb +51 -0
- data/lib/cassie/schema/configuration.rb +35 -0
- data/lib/cassie/schema/migration/cassandra_support.rb +34 -0
- data/lib/cassie/schema/migration/dsl/announcing.rb +47 -0
- data/lib/cassie/schema/migration/dsl/column_operations.rb +42 -0
- data/lib/cassie/schema/migration/dsl/table_definition.rb +299 -0
- data/lib/cassie/schema/migration/dsl/table_operations.rb +64 -0
- data/lib/cassie/schema/migration/dsl.rb +17 -0
- data/lib/cassie/schema/migration.rb +12 -0
- data/lib/cassie/schema/migrator.rb +115 -0
- data/lib/cassie/schema/queries/create_keyspace_query.rb +26 -0
- data/lib/cassie/{migration → schema}/queries/create_versions_table_query.rb +6 -6
- data/lib/cassie/schema/queries/delete_version_query.rb +17 -0
- data/lib/cassie/schema/queries/drop_keyspace_query.rb +14 -0
- data/lib/cassie/schema/queries/insert_version_query.rb +22 -0
- data/lib/cassie/schema/queries/select_versions_query.rb +18 -0
- data/lib/cassie/{migration → schema}/queries.rb +4 -2
- data/lib/cassie/schema/rollback_command.rb +24 -0
- data/lib/cassie/schema/structure_dumper.rb +117 -0
- data/lib/cassie/{migration → schema}/structure_loader.rb +3 -3
- data/lib/cassie/schema/version.rb +143 -0
- data/lib/cassie/schema/version_file_loader.rb +34 -0
- data/lib/cassie/schema/version_loader.rb +31 -0
- data/lib/cassie/schema/version_object_loader.rb +19 -0
- data/lib/cassie/schema/version_writer.rb +108 -0
- data/lib/cassie/schema/versioning.rb +162 -0
- data/lib/cassie/schema.rb +24 -0
- data/lib/cassie/statements/README.md +61 -9
- data/lib/cassie/statements/core.rb +16 -5
- data/lib/cassie/statements/execution/results/core.rb +1 -1
- data/lib/cassie/statements/execution/results/modification_result.rb +1 -1
- data/lib/cassie/statements/execution/results/query_result.rb +1 -1
- data/lib/cassie/statements/execution.rb +40 -13
- data/lib/cassie/statements/statement/assignments.rb +33 -3
- data/lib/cassie/statements/statement/conditions.rb +3 -1
- data/lib/cassie/statements/statement/deleting.rb +27 -19
- data/lib/cassie/statements/statement/idempotency.rb +23 -4
- data/lib/cassie/statements/statement/inserting.rb +17 -10
- data/lib/cassie/statements/statement/limiting.rb +5 -2
- data/lib/cassie/statements/statement/mapping.rb +34 -6
- data/lib/cassie/statements/statement/preparation/cache.rb +1 -1
- data/lib/cassie/statements/statement/preparation.rb +37 -7
- data/lib/cassie/statements/statement/relations.rb +29 -8
- data/lib/cassie/statements/statement/selection.rb +51 -15
- data/lib/cassie/statements/statement/type_hinting.rb +12 -4
- data/lib/cassie/statements/statement/updating.rb +22 -8
- data/lib/cassie/statements/statement.rb +39 -14
- data/lib/cassie/statements.rb +12 -0
- data/lib/cassie/support/server_process.rb +117 -0
- data/lib/cassie/support/statement_parser.rb +3 -5
- data/lib/cassie/support/{command_runner.rb → system_command.rb} +22 -13
- data/lib/cassie/support.rb +3 -1
- data/lib/cassie/tasks/configuration/generate.rake +35 -0
- data/lib/cassie/tasks/io.rb +15 -0
- data/lib/cassie/tasks/migration/create.rake +49 -0
- data/lib/cassie/tasks/migration/import.rake +39 -0
- data/lib/cassie/tasks/migration/reset.rake +9 -0
- data/lib/cassie/tasks/restart.rake +5 -0
- data/lib/cassie/tasks/schema/drop.rake +28 -0
- data/lib/cassie/tasks/schema/dump.rake +21 -0
- data/lib/cassie/tasks/schema/history.rake +18 -0
- data/lib/cassie/tasks/schema/import.rake +40 -0
- data/lib/cassie/tasks/schema/init.rake +54 -0
- data/lib/cassie/tasks/schema/load.rake +19 -0
- data/lib/cassie/tasks/schema/migrate.rake +42 -0
- data/lib/cassie/tasks/schema/reset.rake +6 -0
- data/lib/cassie/tasks/schema/status.rake +19 -0
- data/lib/cassie/tasks/schema/version.rake +18 -0
- data/lib/cassie/tasks/schema/version_display.rb +50 -0
- data/lib/cassie/tasks/start.rake +17 -0
- data/lib/cassie/tasks/stop.rake +33 -0
- data/lib/cassie/tasks/tail.rake +14 -0
- data/lib/cassie/tasks/task_runner.rb +49 -0
- data/lib/cassie/tasks.rb +18 -0
- data/lib/cassie/testing/fake/execution_info.rb +1 -1
- data/lib/cassie/testing/fake/result.rb +3 -3
- data/lib/cassie/testing.rb +4 -0
- data/lib/cassie/version.rb +1 -1
- data/lib/cassie.rb +4 -1
- metadata +73 -17
- data/lib/cassie/migration/README.md +0 -141
- data/lib/cassie/migration/configuration.rb +0 -18
- data/lib/cassie/migration/initialization.rb +0 -70
- data/lib/cassie/migration/queries/create_schema_keyspace_query.rb +0 -17
- data/lib/cassie/migration/queries/insert_version_query.rb +0 -23
- data/lib/cassie/migration/queries/select_versions_query.rb +0 -14
- data/lib/cassie/migration/structure_dumper.rb +0 -94
- data/lib/cassie/migration/version.rb +0 -4
- data/lib/cassie/migration.rb +0 -30
@@ -0,0 +1,49 @@
|
|
1
|
+
module Cassie
|
2
|
+
module Tasks
|
3
|
+
class TaskRunner
|
4
|
+
|
5
|
+
def run_command(args)
|
6
|
+
cmd = args.delete_at(0) if args.first !~ /^-/
|
7
|
+
task = "cassie:#{cmd}"
|
8
|
+
|
9
|
+
Cassie.logger.level = ::Logger::WARN unless args.delete('--debug')
|
10
|
+
|
11
|
+
if Rake::Task.task_defined?(task)
|
12
|
+
Rake::Task[task].invoke
|
13
|
+
else
|
14
|
+
case args.delete_at(0)
|
15
|
+
when "--help"
|
16
|
+
print_documentation
|
17
|
+
when "-v"
|
18
|
+
puts Cassie::VERSION
|
19
|
+
else
|
20
|
+
puts "'#{cmd}' is not a supported command.\n\n"
|
21
|
+
print_documentation
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def print_documentation
|
27
|
+
docs = <<-EOS
|
28
|
+
Usage:
|
29
|
+
cassie <command> [options]
|
30
|
+
|
31
|
+
Commands:
|
32
|
+
EOS
|
33
|
+
Rake.application.tasks.each do |task|
|
34
|
+
docs += " #{task.name.sub('cassie:','').ljust(25)} # #{task.comment}\n"
|
35
|
+
end
|
36
|
+
docs += <<-EOS
|
37
|
+
|
38
|
+
Options:
|
39
|
+
-h, --help # Print this documentation
|
40
|
+
-v, --version # List the library version
|
41
|
+
<command> --help # List options for a given command
|
42
|
+
|
43
|
+
EOS
|
44
|
+
|
45
|
+
puts docs
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/cassie/tasks.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
require_relative "tasks/task_runner"
|
4
|
+
require_relative "tasks/io"
|
5
|
+
require_relative "extensions/object/color_methods"
|
6
|
+
|
7
|
+
module Cassie
|
8
|
+
# Various modules and classes for use with executables.
|
9
|
+
# These classes are not loaded by +require 'cassie'+.
|
10
|
+
# Execute +require 'cassie/tasks' if they are needed in an application.
|
11
|
+
module Tasks
|
12
|
+
Rake::TaskManager.record_task_metadata = true
|
13
|
+
# load all tasks, but only once
|
14
|
+
Dir.glob("#{__dir__}/tasks/**/*.rake").each do |file|
|
15
|
+
load file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -16,7 +16,7 @@ module Cassie::Testing::Fake
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def each
|
19
|
-
|
19
|
+
result_rows = if paging_enabled?
|
20
20
|
index = current_page - 1
|
21
21
|
offset = index * page_size
|
22
22
|
@data.slice(offset, page_size) || []
|
@@ -25,10 +25,10 @@ module Cassie::Testing::Fake
|
|
25
25
|
end
|
26
26
|
|
27
27
|
if block_given?
|
28
|
-
|
28
|
+
result_rows.each(&block)
|
29
29
|
self
|
30
30
|
else
|
31
|
-
|
31
|
+
result_rows.each
|
32
32
|
end
|
33
33
|
end
|
34
34
|
alias rows each
|
data/lib/cassie/testing.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
module Cassie
|
2
|
+
# Various modules and classes for use during application
|
3
|
+
# testing. These classes are not loaded by +require 'cassie'+.
|
4
|
+
# Execute +require 'cassie/testing'+ during test setup to include
|
5
|
+
# test harnessing features.
|
2
6
|
module Testing
|
3
7
|
require_relative 'testing/fake/definition'
|
4
8
|
require_relative 'testing/fake/query'
|
data/lib/cassie/version.rb
CHANGED
data/lib/cassie.rb
CHANGED
@@ -12,6 +12,7 @@ require 'active_support'
|
|
12
12
|
require 'cassandra'
|
13
13
|
|
14
14
|
module Cassie
|
15
|
+
require_relative 'cassie/version'
|
15
16
|
require_relative 'cassie/support'
|
16
17
|
require_relative 'cassie/logger'
|
17
18
|
require_relative 'cassie/instrumentation'
|
@@ -21,15 +22,17 @@ module Cassie
|
|
21
22
|
require_relative 'cassie/definition'
|
22
23
|
require_relative 'cassie/query'
|
23
24
|
require_relative 'cassie/modification'
|
24
|
-
require_relative 'cassie/
|
25
|
+
require_relative 'cassie/schema'
|
25
26
|
|
26
27
|
extend Configuration::Core
|
27
28
|
extend ConnectionHandler
|
28
29
|
|
30
|
+
# Logger used for logging by Cassandra instrumentation
|
29
31
|
def self.logger
|
30
32
|
Logger.logger
|
31
33
|
end
|
32
34
|
|
35
|
+
# Assigns a custom logger for use by Cassandra instrumentation
|
33
36
|
def self.logger=(logger)
|
34
37
|
Logger.logger = logger
|
35
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Prothro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cassandra-driver
|
@@ -64,6 +64,20 @@ dependencies:
|
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: 1.4.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 0.8.7
|
74
|
+
type: :runtime
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.8.7
|
67
81
|
- !ruby/object:Gem::Dependency
|
68
82
|
name: bundler
|
69
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,22 +123,41 @@ files:
|
|
109
123
|
- lib/cassie/connection_handler/sessions.rb
|
110
124
|
- lib/cassie/connection_handler/sessions/instrumentation.rb
|
111
125
|
- lib/cassie/definition.rb
|
126
|
+
- lib/cassie/extensions/object/color_methods.rb
|
112
127
|
- lib/cassie/instrumentation.rb
|
113
128
|
- lib/cassie/logger.rb
|
114
|
-
- lib/cassie/migration.rb
|
115
|
-
- lib/cassie/migration/README.md
|
116
|
-
- lib/cassie/migration/configuration.rb
|
117
|
-
- lib/cassie/migration/initialization.rb
|
118
|
-
- lib/cassie/migration/queries.rb
|
119
|
-
- lib/cassie/migration/queries/create_schema_keyspace_query.rb
|
120
|
-
- lib/cassie/migration/queries/create_versions_table_query.rb
|
121
|
-
- lib/cassie/migration/queries/insert_version_query.rb
|
122
|
-
- lib/cassie/migration/queries/select_versions_query.rb
|
123
|
-
- lib/cassie/migration/structure_dumper.rb
|
124
|
-
- lib/cassie/migration/structure_loader.rb
|
125
|
-
- lib/cassie/migration/version.rb
|
126
129
|
- lib/cassie/modification.rb
|
127
130
|
- lib/cassie/query.rb
|
131
|
+
- lib/cassie/schema.rb
|
132
|
+
- lib/cassie/schema/README.md
|
133
|
+
- lib/cassie/schema/apply_command.rb
|
134
|
+
- lib/cassie/schema/cassandra_migrations/importer.rb
|
135
|
+
- lib/cassie/schema/cassandra_migrations/migration_file.rb
|
136
|
+
- lib/cassie/schema/configuration.rb
|
137
|
+
- lib/cassie/schema/migration.rb
|
138
|
+
- lib/cassie/schema/migration/cassandra_support.rb
|
139
|
+
- lib/cassie/schema/migration/dsl.rb
|
140
|
+
- lib/cassie/schema/migration/dsl/announcing.rb
|
141
|
+
- lib/cassie/schema/migration/dsl/column_operations.rb
|
142
|
+
- lib/cassie/schema/migration/dsl/table_definition.rb
|
143
|
+
- lib/cassie/schema/migration/dsl/table_operations.rb
|
144
|
+
- lib/cassie/schema/migrator.rb
|
145
|
+
- lib/cassie/schema/queries.rb
|
146
|
+
- lib/cassie/schema/queries/create_keyspace_query.rb
|
147
|
+
- lib/cassie/schema/queries/create_versions_table_query.rb
|
148
|
+
- lib/cassie/schema/queries/delete_version_query.rb
|
149
|
+
- lib/cassie/schema/queries/drop_keyspace_query.rb
|
150
|
+
- lib/cassie/schema/queries/insert_version_query.rb
|
151
|
+
- lib/cassie/schema/queries/select_versions_query.rb
|
152
|
+
- lib/cassie/schema/rollback_command.rb
|
153
|
+
- lib/cassie/schema/structure_dumper.rb
|
154
|
+
- lib/cassie/schema/structure_loader.rb
|
155
|
+
- lib/cassie/schema/version.rb
|
156
|
+
- lib/cassie/schema/version_file_loader.rb
|
157
|
+
- lib/cassie/schema/version_loader.rb
|
158
|
+
- lib/cassie/schema/version_object_loader.rb
|
159
|
+
- lib/cassie/schema/version_writer.rb
|
160
|
+
- lib/cassie/schema/versioning.rb
|
128
161
|
- lib/cassie/statements.rb
|
129
162
|
- lib/cassie/statements/README.md
|
130
163
|
- lib/cassie/statements/core.rb
|
@@ -180,8 +213,31 @@ files:
|
|
180
213
|
- lib/cassie/statements/statement/type_hinting.rb
|
181
214
|
- lib/cassie/statements/statement/updating.rb
|
182
215
|
- lib/cassie/support.rb
|
183
|
-
- lib/cassie/support/
|
216
|
+
- lib/cassie/support/server_process.rb
|
184
217
|
- lib/cassie/support/statement_parser.rb
|
218
|
+
- lib/cassie/support/system_command.rb
|
219
|
+
- lib/cassie/tasks.rb
|
220
|
+
- lib/cassie/tasks/configuration/generate.rake
|
221
|
+
- lib/cassie/tasks/io.rb
|
222
|
+
- lib/cassie/tasks/migration/create.rake
|
223
|
+
- lib/cassie/tasks/migration/import.rake
|
224
|
+
- lib/cassie/tasks/migration/reset.rake
|
225
|
+
- lib/cassie/tasks/restart.rake
|
226
|
+
- lib/cassie/tasks/schema/drop.rake
|
227
|
+
- lib/cassie/tasks/schema/dump.rake
|
228
|
+
- lib/cassie/tasks/schema/history.rake
|
229
|
+
- lib/cassie/tasks/schema/import.rake
|
230
|
+
- lib/cassie/tasks/schema/init.rake
|
231
|
+
- lib/cassie/tasks/schema/load.rake
|
232
|
+
- lib/cassie/tasks/schema/migrate.rake
|
233
|
+
- lib/cassie/tasks/schema/reset.rake
|
234
|
+
- lib/cassie/tasks/schema/status.rake
|
235
|
+
- lib/cassie/tasks/schema/version.rake
|
236
|
+
- lib/cassie/tasks/schema/version_display.rb
|
237
|
+
- lib/cassie/tasks/start.rake
|
238
|
+
- lib/cassie/tasks/stop.rake
|
239
|
+
- lib/cassie/tasks/tail.rake
|
240
|
+
- lib/cassie/tasks/task_runner.rb
|
185
241
|
- lib/cassie/testing.rb
|
186
242
|
- lib/cassie/testing/README.md
|
187
243
|
- lib/cassie/testing/fake/definition.rb
|
@@ -208,9 +264,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
208
264
|
version: '0'
|
209
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
210
266
|
requirements:
|
211
|
-
- - "
|
267
|
+
- - ">="
|
212
268
|
- !ruby/object:Gem::Version
|
213
|
-
version:
|
269
|
+
version: '0'
|
214
270
|
requirements: []
|
215
271
|
rubyforge_project:
|
216
272
|
rubygems_version: 2.5.2
|
@@ -1,141 +0,0 @@
|
|
1
|
-
# Cassie Migrations
|
2
|
-
|
3
|
-
Cassie provides versioned migrations similar to many existing adapters and frameworks.
|
4
|
-
|
5
|
-
Practically speaking, this gives your cluster schmea its own "version" and simplifies upgrading or downgrading the schema.
|
6
|
-
|
7
|
-
As such, Cassie uses semantic versioning, where a defined version describes all non-system keyspaces.
|
8
|
-
|
9
|
-
Major, minor, and patch versions are used, without support for semantic extensions (prerelase or metadata, ex: 1.0.0.beta).
|
10
|
-
|
11
|
-
### Schema Migrations
|
12
|
-
#### Creating a migration
|
13
|
-
|
14
|
-
```
|
15
|
-
cassie migration:create that_killer_feature --bump minor
|
16
|
-
=> 0.2.0 - migrations/000_002_000_that_killer_feature.rb
|
17
|
-
```
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
# migrations/000_002_000_that_killer_feature.rb
|
21
|
-
|
22
|
-
Uses the excellend DSL from `cassandra_migrations`.
|
23
|
-
```
|
24
|
-
|
25
|
-
#### Executing migrations
|
26
|
-
|
27
|
-
```
|
28
|
-
cassie migrate
|
29
|
-
=> roll up to latest version
|
30
|
-
```
|
31
|
-
|
32
|
-
```
|
33
|
-
cassie migrate 0.2.0
|
34
|
-
=> roll up to 0.2.0 and stop
|
35
|
-
```
|
36
|
-
|
37
|
-
```
|
38
|
-
cassie migrate 0.1.9
|
39
|
-
=> roll back to 0.1.9 and stop
|
40
|
-
```
|
41
|
-
|
42
|
-
#### Rolling back
|
43
|
-
|
44
|
-
```
|
45
|
-
cassie rollback
|
46
|
-
=> roll back 1 version and stop
|
47
|
-
```
|
48
|
-
|
49
|
-
```
|
50
|
-
cassie rollback 3
|
51
|
-
=> roll back 3 versions and stop
|
52
|
-
```
|
53
|
-
|
54
|
-
#### Getting the current version
|
55
|
-
```
|
56
|
-
cassie schema:version
|
57
|
-
+---------+----------------+-------------+---------------------------+
|
58
|
-
| Version | Description | Migrated by | Migrated at |
|
59
|
-
+---------+----------------+-------------+---------------------------+
|
60
|
-
| * 0.1.0 | initial schema | eprothro | 2016-09-08 09:23:54 -0500 |
|
61
|
-
+---------+----------------+-------------+---------------------------+
|
62
|
-
```
|
63
|
-
|
64
|
-
#### Getting the version history
|
65
|
-
```
|
66
|
-
cassie schema:history
|
67
|
-
+---------+----------------+-------------+---------------------------+
|
68
|
-
| Version | Description | Migrated by | Migrated at |
|
69
|
-
+---------+----------------+-------------+---------------------------+
|
70
|
-
| * 0.2.0 | create users | serverbot | 2016-09-08 10:23:54 -0500 |
|
71
|
-
| * 0.1.0 | initial schema | eprothro | 2016-09-08 09:23:54 -0500 |
|
72
|
-
+---------+----------------+-------------+---------------------------+
|
73
|
-
```
|
74
|
-
|
75
|
-
### Data Migrations
|
76
|
-
|
77
|
-
####TODO:
|
78
|
-
|
79
|
-
Best practice is calling data massaging from the migration, implemented with nice OO elsewhere...
|
80
|
-
|
81
|
-
### Schema overrides per environment
|
82
|
-
|
83
|
-
####TODO:
|
84
|
-
|
85
|
-
Migrations define production use case. Development and/or testing use cases may have slightly different needs.
|
86
|
-
|
87
|
-
Configure keyspace and/or table properties per env that should override migrations.
|
88
|
-
|
89
|
-
Example of keyspace replication settings.
|
90
|
-
|
91
|
-
Make sure it is clear what the schema dump is (with or without overrides)
|
92
|
-
|
93
|
-
### Multiple Keyspaces
|
94
|
-
|
95
|
-
####TODO:
|
96
|
-
|
97
|
-
Don't agree with different ENVs for managing multiple keyspaces. That assumes keyspaces align with domains.
|
98
|
-
|
99
|
-
Example of counter tables in a separate keyspace for higher replication to make read pressure lower.
|
100
|
-
|
101
|
-
Manage multiple keyspaces in configruation.
|
102
|
-
|
103
|
-
Configuration defaults to simple replication with durable writes.
|
104
|
-
|
105
|
-
Example of changing replication for production and how overrides keep dev working.
|
106
|
-
|
107
|
-
### Application Growth
|
108
|
-
|
109
|
-
####TODO:
|
110
|
-
|
111
|
-
This works for starting out, single app, single dev.
|
112
|
-
|
113
|
-
This also scales well to multiple apps or microservices, and multiple teams (ops, etc.), managing and depending on a central repository of migrations with a semantically versioned database schema.
|
114
|
-
|
115
|
-
### Transitioning from Other Tools
|
116
|
-
|
117
|
-
####TODO:
|
118
|
-
|
119
|
-
Support for sucking in `cassandra_migrations` migration files and changing to semantic versioning.
|
120
|
-
|
121
|
-
```
|
122
|
-
cassie migration:import cassandra_migrate
|
123
|
-
=> 0.0.1 - cassandra_migrate/20160818213805_create_users.rb -> migrations/000_000_001_create_users.rb
|
124
|
-
=> 0.0.2 - cassandra_migrate/20160818213811_create_widgets.rb -> migrations/000_000_002_create_widgets.rb
|
125
|
-
=> 0.0.3 - cassandra_migrate/20160818213843_create_sprockets.rb -> migrations/000_000_003_create_sprockets.rb
|
126
|
-
3 migrations imported
|
127
|
-
```
|
128
|
-
|
129
|
-
Support for a .cdl migration file to act as initial migration (dump defining initial version).
|
130
|
-
|
131
|
-
```
|
132
|
-
cassie migration:initialize
|
133
|
-
=> 0.1.0 - migrations/000_001_000_initial_schema.cdl
|
134
|
-
schema initialized at v0.1.0 from current database structure
|
135
|
-
```
|
136
|
-
|
137
|
-
```
|
138
|
-
cassie migration:initialize 0.15.3
|
139
|
-
=> 0.1.0 - migrations/000_015_003_initial_schema.cdl
|
140
|
-
schema initialized at v0.15.3 from current database structure
|
141
|
-
```
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Cassie::Migration
|
2
|
-
# Extend a module/class with Configuration to enable migration management
|
3
|
-
module Configuration
|
4
|
-
|
5
|
-
attr_accessor :schema_keyspace,
|
6
|
-
:versions_table
|
7
|
-
|
8
|
-
def self.extended(extender)
|
9
|
-
extender.paths["schema_structure"] = "db/structure.cql"
|
10
|
-
extender.schema_keyspace = "cassie_schema"
|
11
|
-
extender.versions_table = "versions"
|
12
|
-
end
|
13
|
-
|
14
|
-
def paths
|
15
|
-
@paths ||= {}.with_indifferent_access
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module Cassie::Migration
|
2
|
-
|
3
|
-
class AlreadyInitiailizedError < StandardError; end
|
4
|
-
class UninitializedError < StandardError; end
|
5
|
-
|
6
|
-
module Initialization
|
7
|
-
require 'etc'
|
8
|
-
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
|
13
|
-
def initialize_versioning(version=default_version)
|
14
|
-
create_schema_keyspace unless keyspace_exists?
|
15
|
-
raise Cassie::Migration::AlreadyInitiailizedError if version_exists?
|
16
|
-
create_versions_table unless versions_table_exists?
|
17
|
-
insert_version(build_version(version, 'initial schema'))
|
18
|
-
end
|
19
|
-
|
20
|
-
def keyspace_exists?
|
21
|
-
Cassie.cluster.keyspaces.map(&:name).any?{|k| k == Cassie::Migration.schema_keyspace}
|
22
|
-
end
|
23
|
-
|
24
|
-
def version_exists?
|
25
|
-
!!Cassie::Migration.version
|
26
|
-
rescue Cassie::Migration::UninitializedError
|
27
|
-
false
|
28
|
-
end
|
29
|
-
|
30
|
-
def versions_table_exists?
|
31
|
-
!!SelectVersionsQuery.new(limit: 1).fetch
|
32
|
-
rescue Cassandra::Errors::InvalidError
|
33
|
-
false
|
34
|
-
end
|
35
|
-
|
36
|
-
def build_version(version_number, description)
|
37
|
-
id = Cassandra::TimeUuid::Generator.new.now
|
38
|
-
migrator = Etc.getlogin rescue '<unknown>'
|
39
|
-
migrated_at = Time.now
|
40
|
-
Version.new(id, version_number, description, migrator, migrated_at)
|
41
|
-
end
|
42
|
-
|
43
|
-
def insert_version(version)
|
44
|
-
InsertVersionQuery.new(version: version).execute
|
45
|
-
end
|
46
|
-
|
47
|
-
protected
|
48
|
-
|
49
|
-
def default_version
|
50
|
-
'0.1.0'
|
51
|
-
end
|
52
|
-
|
53
|
-
def create_schema_keyspace
|
54
|
-
CreateSchemaKeyspaceQuery.new.execute
|
55
|
-
end
|
56
|
-
|
57
|
-
def create_versions_table
|
58
|
-
CreateVersionsTableQuery.new.execute
|
59
|
-
end
|
60
|
-
|
61
|
-
def uninitialized_error
|
62
|
-
UninitializedError.new(uninitialized_message)
|
63
|
-
end
|
64
|
-
|
65
|
-
def uninitialized_message
|
66
|
-
"Cassie Schema Versions table not found at '#{schema_keyspace}.#{versions_table}'. Create a migration or initialize your schema to enable versioned migration support."
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Cassie::Migration
|
2
|
-
class CreateSchemaKeyspaceQuery < Cassie::Definition
|
3
|
-
self.prepare = false
|
4
|
-
|
5
|
-
def statement
|
6
|
-
cql = %(
|
7
|
-
CREATE KEYSPACE #{Cassie::Migration.schema_keyspace}
|
8
|
-
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}
|
9
|
-
AND durable_writes = true;
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
def keyspace
|
14
|
-
nil
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Cassie::Migration
|
2
|
-
class InsertVersionQuery < Cassie::Modification
|
3
|
-
|
4
|
-
insert_into Cassie::Migration.versions_table
|
5
|
-
|
6
|
-
set :bucket
|
7
|
-
set :id
|
8
|
-
set :version_number
|
9
|
-
set :description
|
10
|
-
set :migrator
|
11
|
-
set :migrated_at
|
12
|
-
|
13
|
-
map_from :version
|
14
|
-
|
15
|
-
def bucket
|
16
|
-
0
|
17
|
-
end
|
18
|
-
|
19
|
-
def keyspace
|
20
|
-
Cassie::Migration.schema_keyspace
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Cassie::Migration
|
2
|
-
class SelectVersionsQuery < Cassie::Query
|
3
|
-
|
4
|
-
select_from Cassie::Migration.versions_table
|
5
|
-
|
6
|
-
def build_result(row)
|
7
|
-
Version.new(*row.values_at(*Version.members.map(&:to_s)))
|
8
|
-
end
|
9
|
-
|
10
|
-
def keyspace
|
11
|
-
Cassie::Migration.schema_keyspace
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
module Cassie::Migration
|
2
|
-
require_relative 'queries'
|
3
|
-
|
4
|
-
class StructureDumper
|
5
|
-
attr_reader :destination_path
|
6
|
-
|
7
|
-
def initialize(opts={})
|
8
|
-
@destination_path = opts[:destination_path] || default_destination_path
|
9
|
-
end
|
10
|
-
|
11
|
-
def stream
|
12
|
-
@stream ||= begin
|
13
|
-
prepare_stream
|
14
|
-
File.open(destination_path, "w+")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def structure
|
19
|
-
@structure ||= begin
|
20
|
-
args = ["-e", "'DESCRIBE SCHEMA'"]
|
21
|
-
runner = Cassie::Support::CommandRunner.new("cqlsh", args)
|
22
|
-
runner.run
|
23
|
-
|
24
|
-
raise runner.failure_message unless runner.success?
|
25
|
-
|
26
|
-
runner.output
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def versions
|
31
|
-
@versions ||= begin
|
32
|
-
versions_query.fetch
|
33
|
-
rescue Cassandra::Errors::InvalidError => e
|
34
|
-
log_versions_not_found(e)
|
35
|
-
[]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def versions_insert_cql
|
40
|
-
inserts = versions.map do |v|
|
41
|
-
InsertVersionQuery.new(version: v).to_cql
|
42
|
-
end
|
43
|
-
inserts.join("\n")
|
44
|
-
end
|
45
|
-
|
46
|
-
def dump
|
47
|
-
stream << structure
|
48
|
-
stream << "\n\n"
|
49
|
-
stream << versions_insert_cql
|
50
|
-
stream << "\n"
|
51
|
-
|
52
|
-
close_stream
|
53
|
-
end
|
54
|
-
|
55
|
-
def versions_table_name
|
56
|
-
"cassie_schema.versions"
|
57
|
-
end
|
58
|
-
|
59
|
-
def destination_path
|
60
|
-
@destination_path || raise("Unconfigured schema structure path: `Cassie::Migration.paths[:schema_structure]` is empty")
|
61
|
-
end
|
62
|
-
|
63
|
-
protected
|
64
|
-
|
65
|
-
def versions_query
|
66
|
-
SelectVersionsQuery.new
|
67
|
-
end
|
68
|
-
|
69
|
-
def default_destination_path
|
70
|
-
Cassie::Migration.paths[:schema_structure]
|
71
|
-
end
|
72
|
-
|
73
|
-
def prepare_stream
|
74
|
-
dir = File.dirname(destination_path)
|
75
|
-
Dir.mkdir(dir) unless File.directory?(dir)
|
76
|
-
end
|
77
|
-
|
78
|
-
def close_stream
|
79
|
-
stream.close
|
80
|
-
@stream = nil
|
81
|
-
end
|
82
|
-
|
83
|
-
def log_versions_not_found(error)
|
84
|
-
msg = "WARNING: Cassie Schema Versions table not found at '#{versions_table_name}'. Create a migration, or initialize your schema for versioned migration support."
|
85
|
-
msg << "\n\t"
|
86
|
-
msg << error.message.split("\n").join("\n\t")
|
87
|
-
logger.warn(msg)
|
88
|
-
end
|
89
|
-
|
90
|
-
def logger
|
91
|
-
Cassie.logger
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|