cassie 1.0.6.pre2 → 1.1.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e87e9f31fbcda1c157ea0ab6ab1448979b4c4fdc
4
- data.tar.gz: 8d502e415d094a962000ef91d2d1b01a7372e6cd
3
+ metadata.gz: 16ae8e8e9728e84b78a102b1a42937d89ee9249f
4
+ data.tar.gz: 72e87ae44eab6a96c566af3c1835beaa35c194f3
5
5
  SHA512:
6
- metadata.gz: b4f85555049d4ee14ca32bd328f58be26ae9a8e65a076087818076f17c78700db94f2a52570f96a8d07465dc57336945825958c40e030cd09e47440afe03370d
7
- data.tar.gz: b9a2c4dd0851603c55f0e1aa7ebe083a13ab3d1d6f0f6b6172a92f3ac2fd4b68ad3ec3bd84f697327cc07bfdaae4058a377f30e8db7de88cdf8a954689c99240
6
+ metadata.gz: 994a3b26d1093f06a7004d74f75936e77a56fd34eba323891b6e5e6637a620fcd26bb50bfb128b1cd9e24fea61603b82d391a101b54118203ae4a47883034420
7
+ data.tar.gz: c4fa532a24ad9b1c9149c03394e66bc6e1fc1ef1738f57a6d43e6d13ebad5741e046bb4ebd197a5d81cbe8ce2090a16e4a23c084ff8481e03b779ac7af3abc52
@@ -65,7 +65,7 @@ cassie migrations:import
65
65
  - done
66
66
  -- done
67
67
  -- Dumping Cassandra schema (version 0.0.0.1)
68
- - Writing to db/cassandra/schema.cql
68
+ - Writing to db/cassandra/schema.rb
69
69
  - done
70
70
  -- done
71
71
  ```
@@ -93,11 +93,35 @@ cassie schema:import
93
93
  - done
94
94
  -- done
95
95
  -- Dumping Cassandra schema (version 0.0.1.0)
96
- - Writing to db/cassandra/schema.cql
96
+ - Writing to db/cassandra/schema.rb
97
97
  - done
98
98
  -- done
99
99
  ```
100
100
 
101
+ ##### Initializing versioning
102
+
103
+ Locally, these import tasks will also initialiaze the local version tracking to have all migration versions recorded.
104
+
105
+ However, another developer's or environment's database does not have this schema metadata. Syncronize version tracking by initializing cassie schema with the version of the current in-database schema.
106
+
107
+ ```
108
+ cassie schema:init -v 0.0.2.0
109
+ ```
110
+
111
+ ```
112
+ -- Initializing Cassie Versioning
113
+ -- done
114
+ -- Fast-forwarding to version 0.0.2.0
115
+ > Recorded version 0.0.0.1
116
+ > Recorded version 0.0.1.0
117
+ > Recorded version 0.0.2.0
118
+ -- done
119
+ -- Initializing 'cassie_development' Keyspace
120
+ -- done
121
+ ```
122
+
123
+ This does not run any migrations, but rather updates schema version metadata, so future migrations begin after the provided version.
124
+
101
125
  #### Creating a migration
102
126
 
103
127
  ```
@@ -180,36 +204,40 @@ cassie schema:history
180
204
  ```
181
205
 
182
206
  #### Reporting the version status
207
+
208
+ Display all applied and unapplied migrations.
209
+
183
210
  ```
184
211
  cassie schema:status
185
212
  ```
186
213
  ```
187
- +-----------+----------------+-------------+---------------------------+
188
- | Version | Description | Status | Migration File |
189
- +-----------+----------------+-------------+---------------------------+
190
- | * 0.2.0.0 | create users | serverbot | 2016-09-08 10:23:54 -0500 |
191
- | 0.1.0.0 | initial schema | eprothro | 2016-09-08 09:23:54 -0500 |
192
- +-----------+----------------+-------------+---------------------------+
214
+ +-----------+----------------+--------+---------------------------------------------------------------+
215
+ | Number | Description | Status | Migration File |
216
+ +-----------+----------------+--------+---------------------------------------------------------------+
217
+ | 0.0.3.0 | create friends | DOWN | db/cassandra/migrations/0000_0000_0003_0000_create_friends.rb |
218
+ | * 0.0.2.0 | create users | UP | db/cassandra/migrations/0000_0000_0002_0000_create_users.rb |
219
+ | 0.1.0.0 | initial schema | UP | db/cassandra/migrations/0000_0000_0001_0000_initial_schema.rb |
220
+ +-----------+----------------+--------+---------------------------------------------------------------+
193
221
  ```
194
222
 
195
223
  ### Schema Management
196
224
 
197
- The full schema is stored in `schema.cql`, this is recommended to be checked into source control.
225
+ The full schema is stored in `schema.rb`, this is recommended to be checked into source control.
198
226
  It is updated (with a full dump) after each migration, to maintain a truth-store for the schema when used with multiple developers.
199
227
 
200
- ### Dump the schema
228
+ #### Dump the schema
201
229
 
202
230
  ```
203
231
  cassie schema:dump
204
232
  ```
205
233
  ```
206
234
  -- Dumping Cassandra schema (version 0.2.0.0)
207
- - Writing to db/cassandra/schema.cql
235
+ - Writing to db/cassandra/schema.rb
208
236
  - done
209
237
  -- done
210
238
  ```
211
239
 
212
- ### Drop the schema
240
+ #### Drop the schema
213
241
  ```
214
242
  cassie schema:drop
215
243
  ```
@@ -222,17 +250,17 @@ cassie schema:drop
222
250
  -- done
223
251
  ```
224
252
 
225
- ### Load the schema
253
+ #### Load the schema
226
254
  ```
227
255
  cassie schema:load
228
256
  ```
229
257
  ```
230
- -- Loading Schema from db/cassandra/schema.cql
258
+ -- Loading Schema from db/cassandra/schema.rb
231
259
  > Schema is now at version 0.2.0.0
232
260
  -- done
233
261
  ```
234
262
 
235
- ### Reset the schema
263
+ #### Reset the schema
236
264
 
237
265
  ```
238
266
  cassie schema:reset
@@ -244,12 +272,12 @@ cassie schema:reset
244
272
  - Dropping 'cassie_schema'
245
273
  - done
246
274
  -- done
247
- -- Loading Schema from db/cassandra/schema.cql
275
+ -- Loading Schema from db/cassandra/schema.rb
248
276
  > Schema is now at version 0.2.0.0
249
277
  -- done
250
278
  ```
251
279
 
252
- ### Reset the schema and migrate
280
+ #### Reset the schema and migrate
253
281
 
254
282
  This task reload the schema from the schema file, and then proceeds with incremental migrations up to the latest migration.
255
283
 
@@ -263,7 +291,7 @@ cassie migrate:reset
263
291
  - Dropping 'cassie_schema'
264
292
  - done
265
293
  -- done
266
- -- Loading Schema from db/cassandra/schema.cql
294
+ -- Loading Schema from db/cassandra/schema.rb
267
295
  > Schema is now at version 0.2.0.0
268
296
  -- done
269
297
  -- Migrating to version 0.2.1.0
@@ -271,12 +299,25 @@ cassie migrate:reset
271
299
  - done (4.89 ms)
272
300
  -- done
273
301
  -- Dumping Cassandra schema (version 0.2.1.0)
274
- - Writing to db/cassandra/schema.cql
302
+ - Writing to db/cassandra/schema.rb
275
303
  - done
276
304
  -- done
277
305
  ```
278
306
 
279
- ### Architecture (`cassie` developers)
307
+ ### Multiple Envrionments
308
+
309
+ Set the environment with `RACK_ENV`, `CASSANDRA_ENV` or the `--env`(`-e`) switch for `cassie` commands:
310
+
311
+ ```
312
+ RACK_ENV=test cassie migrate:reset
313
+ ```
314
+ is equivalent to
315
+ ```
316
+ cassie migrate:reset -e test
317
+ ```
318
+
319
+
320
+ ### Version / Migration Architecture (`cassie` developers)
280
321
 
281
322
  #### Versions
282
323
 
@@ -11,7 +11,7 @@ module Cassie::Schema
11
11
 
12
12
  # @!visibility private
13
13
  def self.extended(extender)
14
- extender.paths["schema_file"] = "db/cassandra/schema.cql"
14
+ extender.paths[:schema_file] = "db/cassandra/schema.rb"
15
15
  extender.paths[:migrations_directory] = "db/cassandra/migrations"
16
16
  extender.schema_keyspace = "cassie_schema"
17
17
  extender.versions_table = "versions"
@@ -20,7 +20,7 @@ module Cassie::Schema
20
20
  # Paths used for configuration loading.
21
21
  #
22
22
  # @return [Hash]
23
- # * +:schema_file+ - The .cql file defining the current schema structure
23
+ # * +:schema_file+ - The .rb file defining the current schema structure
24
24
  # * +:migrations_directory+ - The directory containing the versioned schema migration .rb files
25
25
  def paths
26
26
  @paths ||= {}.with_indifferent_access
@@ -0,0 +1,43 @@
1
+ module Cassie::Schema
2
+ module Definition
3
+
4
+ # DSL for Cassie::Schema Defintion
5
+ # these methods can be called in a schema.rb
6
+ # file to define keyspace agnostic schema.
7
+ # When executed, they will then create that schema
8
+ # for the currently defined default keyspace found
9
+ # in +Cassie.configuration[:keyspace]+.
10
+ class DSL
11
+ class << self
12
+
13
+ # The default keyspace according to the
14
+ # cluster configuration in +Cassie.configuration[:keyspace]+
15
+ # @return [String] the keyspace name
16
+ def default_keyspace
17
+ Cassie.configuration[:keyspace]
18
+ end
19
+
20
+ # Execute the given CQL on the current cluster, using an
21
+ # unscoped session. CQL should be keyspace agnostic, where
22
+ # keyspace names are interpolated with the +#{default_keyspace}+.
23
+ # Table names must be fully qualified.
24
+ # @return [Cassandra::Result] the result of execution
25
+ def create_schema(cql)
26
+ cql.strip.split(";").each do |statement|
27
+ Cassie.session(nil).execute("#{statement.strip};")
28
+ end
29
+ end
30
+
31
+ def record_version(number, description, uuid, executor, executed_at_utc)
32
+ id = Cassandra::TimeUuid.new(uuid)
33
+ executed_at = DateTime.parse(executed_at_utc) rescue nil
34
+ version = Version.new(number, description, id, executor, executed_at)
35
+
36
+ Cassie::Schema.initialize_versioning
37
+
38
+ Cassie::Schema.record_version(version)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ module Cassie::Schema
2
+
3
+ # Extend Defintion to get the +define+ class method
4
+ # used to define schema for a cassandra cluster
5
+ module Definition
6
+ require_relative 'definition/dsl'
7
+
8
+ def define(&block)
9
+ raise "block required to define schema." unless block_given?
10
+
11
+ DSL.instance_eval(&block)
12
+ end
13
+ end
14
+ end
@@ -11,6 +11,7 @@ module Cassie::Schema
11
11
 
12
12
 
13
13
  def initialize(target)
14
+ puts target
14
15
  @target_version = build_target_version(target)
15
16
  @current_version = Cassie::Schema.version
16
17
  @direction = build_direction
@@ -60,6 +61,9 @@ module Cassie::Schema
60
61
  duration = Benchmark.realtime do
61
62
  yield(command)
62
63
  end
64
+ # Sleep for 50ms to ensure TimeUuid generation jitter
65
+ # doesn't cause out-of-order records
66
+ sleep(0.050)
63
67
  after_each.call(command.version, (duration*1000).round(2))
64
68
  end
65
69
  end
@@ -4,14 +4,15 @@ module Cassie::Schema
4
4
 
5
5
  def statement
6
6
  %(
7
- CREATE TABLE #{Cassie::Schema.versions_table} (
8
- bucket int,
7
+ CREATE TABLE IF NOT EXISTS #{Cassie::Schema.versions_table} (
8
+ application text,
9
+ env text,
9
10
  id timeuuid,
10
11
  number text,
11
12
  description text,
12
13
  executor text,
13
14
  executed_at timestamp,
14
- PRIMARY KEY (bucket, id)
15
+ PRIMARY KEY ((application, env), id)
15
16
  ) WITH CLUSTERING ORDER BY (id DESC);
16
17
  )
17
18
  end
@@ -1,13 +1,26 @@
1
1
  module Cassie::Schema
2
2
  class DeleteVersionQuery < Cassie::Modification
3
-
3
+ attr
4
4
  delete_from Cassie::Schema.versions_table
5
5
 
6
- where :id, :eq
7
- where :bucket, :eq
6
+ where :id, :eq, if: :id?
7
+ where :env, :eq
8
+ where :application, :eq
9
+
10
+ def id?
11
+ !!self.id
12
+ end
13
+
14
+ def env
15
+ #setting #env should win
16
+ return @env if defined?(@env)
17
+ Cassie.env
18
+ end
8
19
 
9
- def bucket
10
- 0
20
+ def application
21
+ #setting #env should win
22
+ return @application if defined?(@application)
23
+ Cassie::Schema.application
11
24
  end
12
25
 
13
26
  def keyspace
@@ -7,7 +7,8 @@ module Cassie::Schema
7
7
 
8
8
  insert_into "#{Cassie::Schema.schema_keyspace}.#{Cassie::Schema.versions_table}"
9
9
 
10
- set :bucket
10
+ set :application
11
+ set :env
11
12
  set :id
12
13
  set :number
13
14
  set :description
@@ -16,8 +17,12 @@ module Cassie::Schema
16
17
 
17
18
  map_from :version
18
19
 
19
- def bucket
20
- 0
20
+ def env
21
+ Cassie.env
22
+ end
23
+
24
+ def application
25
+ Cassie::Schema.application
21
26
  end
22
27
 
23
28
  def executed_at?
@@ -3,6 +3,17 @@ module Cassie::Schema
3
3
 
4
4
  select_from Cassie::Schema.versions_table
5
5
 
6
+ where :application, :eq
7
+ where :env, :eq
8
+
9
+ def env
10
+ Cassie.env
11
+ end
12
+
13
+ def application
14
+ Cassie::Schema.application
15
+ end
16
+
6
17
  def build_result(row)
7
18
  Version.new(row["number"],
8
19
  row["description"],
@@ -0,0 +1,125 @@
1
+ module Cassie::Schema
2
+ require_relative 'queries'
3
+
4
+ class SchemaDumper
5
+ # The location to dump the ruby file
6
+ attr_reader :destination_path
7
+
8
+ # The keyspace that will be extracted
9
+ # and replaced with +#{default_keyspace}+ upon dumping
10
+ attr_reader :keyspace
11
+
12
+ def initialize(opts={})
13
+ @destination_path = opts[:destination_path] || default_destination_path
14
+ @keyspace = Cassie.configuration[:keyspace]
15
+ end
16
+
17
+ # The stream to dump the source to
18
+ def stream
19
+ @stream ||= begin
20
+ prepare_stream
21
+ File.open(destination_path, "w+")
22
+ end
23
+ end
24
+
25
+ # Dump the CQL for the current environment's keyspace,
26
+ # the schema metadata keyspace, and the versions rows
27
+ # that are currently in the schema versions table.
28
+ def dump
29
+ stream << <<-EOS
30
+ # This file describes the keyspace-agnostic schema
31
+ # for this application's environments.
32
+ #
33
+ # It is the definitive source of the current state
34
+ # of the schema and should not be modified directly.
35
+ #
36
+ # It is strongly recommened that this schema file be checked into source control.
37
+ #
38
+ # Use `cassie` commands to apply this schema to a particular environment:
39
+ # * Load this schema with `cassie schema:load`
40
+ # * Reset the schema to this definition with `cassie schema:reset`
41
+ Cassie::Schema.define do
42
+
43
+ EOS
44
+ stream << " create_schema <<-EOS\n"
45
+ stream << "#{keyspace_agnostic_cql}\n"
46
+ stream << "EOS\n"
47
+ stream << "\n\n"
48
+ versions.each do |v|
49
+ stream << " record_version #{version_arg_str(v)}\n"
50
+ end
51
+ stream << "end\n"
52
+
53
+ close_stream
54
+ end
55
+
56
+ def versions_table_name
57
+ "#{Cassie::Schema.schema_keyspace}.#{Cassie::Schema.versions_table}"
58
+ end
59
+
60
+ def destination_path
61
+ @destination_path || raise("Unconfigured schema file path: `Cassie::Schema.paths[:schema_file]` is empty")
62
+ end
63
+
64
+ protected
65
+
66
+ # Fetch the keyspace agnostic CQL ruby string that can be used to
67
+ # recreate the keyspace. The keyspace value is replaced
68
+ # with +#{default_keyspace}+
69
+ # @return [String] A ruby string with keyspace interpolated CQL commands
70
+ # @raise [RuntimeError] if the {Cassie.configuration[:keyspace]} keyspace could not be described.
71
+ def keyspace_agnostic_cql
72
+ @keyspace_structure ||= begin
73
+ args = ["-e", "'DESCRIBE KEYSPACE #{keyspace}'"]
74
+ runner = Cassie::Support::SystemCommand.new("cqlsh", args)
75
+ runner.succeed
76
+
77
+ runner.output.gsub(keyspace, '#{default_keyspace}').strip
78
+ end
79
+ end
80
+
81
+ def versions
82
+ @versions ||= begin
83
+ versions_query.fetch
84
+ rescue Cassandra::Errors::InvalidError => e
85
+ log_versions_not_found(e)
86
+ []
87
+ end
88
+ end
89
+
90
+ def versions_query
91
+ SelectVersionsQuery.new
92
+ end
93
+
94
+ def default_destination_path
95
+ Cassie::Schema.paths[:schema_file]
96
+ end
97
+
98
+ def prepare_stream
99
+ dir = File.dirname(destination_path)
100
+ Dir.mkdir(dir) unless File.directory?(dir)
101
+ end
102
+
103
+ def close_stream
104
+ stream.close
105
+ @stream = nil
106
+ end
107
+
108
+ def log_versions_not_found(error)
109
+ msg = "WARNING: Cassie Schema Versions table not found at '#{versions_table_name}'. Initialize your schema with `cassie schema:init` or `cassie:migrations:import` for versioned migration support."
110
+ msg << "\n\t- "
111
+ msg << error.message.split("\n").join("\n\t- ")
112
+ logger.warn(msg)
113
+ end
114
+
115
+ def logger
116
+ Cassie.logger
117
+ end
118
+
119
+ def version_arg_str(version)
120
+ <<-EOS.strip
121
+ "#{version}", "#{version.description}", "#{version.id}", "#{version.executor}", "#{version.executed_at.try(:iso8601, 6)}"
122
+ EOS
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,20 @@
1
+ module Cassie::Schema
2
+ class SchemaLoader
3
+ attr_reader :source_path
4
+
5
+
6
+ def initialize(opts={})
7
+ @source_path = opts[:source_path] || default_source_path
8
+ end
9
+
10
+ def load
11
+ Kernel.load File.absolute_path(source_path)
12
+ end
13
+
14
+ protected
15
+
16
+ def default_source_path
17
+ Cassie::Schema.paths[:schema_file]
18
+ end
19
+ end
20
+ end
@@ -33,17 +33,7 @@ module Cassie::Schema
33
33
  # an empty string is returned.
34
34
  # @return [String] CQL commands
35
35
  def schema_meta_structure
36
- @schema_meta_structure ||= begin
37
- args = ["-e", "'DESCRIBE KEYSPACE #{Cassie::Schema.schema_keyspace}'"]
38
- runner = Cassie::Support::SystemCommand.new("cqlsh", args)
39
- runner.run
40
-
41
- if runner.success?
42
- runner.output
43
- else
44
- ""
45
- end
46
- end
36
+ CreateVersionsTableQuery.new.to_cql
47
37
  end
48
38
 
49
39
  def versions
@@ -30,11 +30,10 @@ module Cassie::Schema
30
30
  end
31
31
 
32
32
  # Create the keyspace and table for tracking schema versions
33
- # in the Cassandra database
33
+ # in the Cassandra database if they don't already exist
34
34
  # @return [void]
35
35
  def initialize_versioning
36
36
  create_schema_keyspace unless keyspace_exists?
37
- raise Cassie::Schema::AlreadyInitiailizedError if version_exists?
38
37
  create_versions_table unless versions_table_exists?
39
38
  end
40
39
 
@@ -119,7 +118,7 @@ module Cassie::Schema
119
118
  database_versions.tap do |versions|
120
119
  versions.each{|v| VersionObjectLoader.new(v).load }
121
120
  end
122
- rescue Cassandra::Errors::InvalidError
121
+ rescue Cassandra::Errors::InvalidError => e
123
122
  raise uninitialized_error
124
123
  end
125
124
 
data/lib/cassie/schema.rb CHANGED
@@ -14,11 +14,28 @@ module Cassie
14
14
  module Schema
15
15
  require_relative 'schema/configuration'
16
16
  require_relative 'schema/versioning'
17
+ require_relative 'schema/definition'
17
18
 
18
19
  extend Configuration
19
20
  extend Versioning
21
+ extend Definition
22
+
23
+ # The application namespace. Only applicaple
24
+ # When cassie manages multiple applicaiton
25
+ # schemas within the same cluster.
26
+ # @return [String] the application namespace
27
+ def self.application
28
+ return @application if defined?(@application)
29
+ "global"
30
+ end
31
+
32
+ def self.application=(app_name)
33
+ @application = app_name
34
+ end
20
35
  end
21
36
 
22
37
  require_relative 'schema/structure_dumper'
23
38
  require_relative 'schema/structure_loader'
39
+ require_relative 'schema/schema_loader'
40
+ require_relative 'schema/schema_dumper'
24
41
  end
@@ -5,19 +5,24 @@ namespace :cassie do
5
5
  include Cassie::Tasks::IO
6
6
  begin
7
7
  query = Cassie::Schema::DropKeyspaceQuery.new
8
- keyspaces = [Cassie.configuration[:keyspace], Cassie::Schema.schema_keyspace]
8
+ keyspaces = [Cassie.configuration[:keyspace]]
9
9
 
10
- puts "-- Dropping #{keyspaces.count} keyspaces"
10
+ puts "-- Dropping '#{Cassie.env}' schema"
11
11
  keyspaces.each do |keyspace|
12
12
  query.keyspace = keyspace
13
13
  puts " - Dropping '#{keyspace}'"
14
14
  if Cassie.keyspace_exists?(keyspace)
15
- query.execute
15
+ query.execute!
16
16
  else
17
17
  puts " > '#{keyspace}' does not exist"
18
18
  end
19
19
  puts " - done"
20
20
  end
21
+ puts " - Clearning schema version metadata"
22
+ count = Cassie::Schema.applied_versions.count
23
+ Cassie::Schema::DeleteVersionQuery.new.execute!
24
+ puts " > removed #{count} #{'version'.pluralize(count)}"
25
+ puts " - done"
21
26
  puts "-- done"
22
27
  rescue => e
23
28
  output_error(e)
@@ -1,12 +1,12 @@
1
1
  namespace :cassie do
2
2
  namespace :schema do
3
- desc "Dumps the schema for all non-system keyspaces in CQL format (`db/cassandra/schema.cql` by default)"
3
+ desc "Dumps the schema for configured keyspace into schema file (`db/cassandra/schema.rb` by default)"
4
4
  task :dump do
5
5
  include Cassie::Tasks::IO
6
6
 
7
7
  begin
8
- puts "-- Dumping Cassandra schema (version #{Cassie::Schema.version})"
9
- dumper = Cassie::Schema::StructureDumper.new
8
+ puts "-- Dumping '#{Cassie.env}' schema (version #{Cassie::Schema.version})"
9
+ dumper = Cassie::Schema::SchemaDumper.new
10
10
  puts " - Writing to #{dumper.destination_path}"
11
11
  dumper.dump
12
12
  puts " - done"
@@ -1,14 +1,14 @@
1
1
  namespace :cassie do
2
2
  namespace :schema do
3
- desc "Creates the schema by executing the CQL in the schema file (`db/cassandra/schema.cql` by default)"
3
+ desc "Creates the schema by executing the schema file (`db/cassandra/schema.rb` by default)"
4
4
  task :load do
5
5
  include Cassie::Tasks::IO
6
6
 
7
7
  begin
8
- loader = Cassie::Schema::StructureLoader.new
9
- puts "-- Loading Schema from #{loader.source_path}"
8
+ loader = Cassie::Schema::SchemaLoader.new
9
+ puts "-- Loading '#{Cassie.env}' Schema from #{loader.source_path}"
10
10
  loader.load
11
- puts " > Schema is now at version #{Cassie::Schema.version}"
11
+ puts " > '#{Cassie.env}' schema is now at version #{Cassie::Schema.version}"
12
12
  puts "-- done"
13
13
  rescue => e
14
14
  output_error(e)
@@ -8,7 +8,7 @@ namespace :cassie do
8
8
  version = argv[0]
9
9
 
10
10
  migrator = Cassie::Schema::Migrator.new(version)
11
- puts "-- Migrating to version #{migrator.target_version}"
11
+ puts "-- Migrating '#{Cassie.env}' schema to version #{migrator.target_version}"
12
12
 
13
13
  if migrator.commands.count == 0
14
14
  if migrator.target_version == migrator.current_version
@@ -1,6 +1,6 @@
1
1
  namespace :cassie do
2
2
  namespace :schema do
3
- desc "Creates the schema by executing the CQL in the schema file (`db/cassandra/schema.cql` by default)"
3
+ desc "Creates the schema by executing the schema file (`db/cassandra/schema.rb` by default)"
4
4
  task :reset => [:drop, :load]
5
5
  end
6
6
  end
@@ -9,8 +9,9 @@ module Cassie::Tasks
9
9
  # Note: if we end up using this elsewhere, move to Version::VersionList
10
10
  # or something simliar, and have version collection methods return that
11
11
  members = [:number, :description, :executor, :executed_at]
12
- titles = ['Number', 'Description', 'Migrated by', 'Migrated at']
13
- table = Terminal::Table.new(headings: titles)
12
+ headings = ['Number', 'Description', 'Migrated by', 'Migrated at']
13
+ title = "Environment: #{Cassie.env}"
14
+ table = Terminal::Table.new(headings: headings, title: title)
14
15
  current_version = Cassie::Schema.version
15
16
 
16
17
  versions.each.with_index do |v|
@@ -19,6 +20,7 @@ module Cassie::Tasks
19
20
  row[0] = "* #{row[0]}" if v == current_version
20
21
  row[1] = v.description
21
22
  row[2] = v.executor
23
+ row[3] = v.executed_at
22
24
  row[3] ||= "Unknown"
23
25
  table.add_row(row)
24
26
  end
@@ -30,8 +32,9 @@ module Cassie::Tasks
30
32
  def print_statuses(versions)
31
33
  # Note: if we end up using this elsewhere, move to Version::VersionList
32
34
  # or something simliar, and have version collection methods return that
33
- titles = ['Number', 'Description', 'Status', 'Migration File']
34
- table = Terminal::Table.new(headings: titles)
35
+ headings = ['Number', 'Description', 'Status', 'Migration File']
36
+ title = "Environment: #{Cassie.env}"
37
+ table = Terminal::Table.new(headings: headings, title: title)
35
38
  current_version = Cassie::Schema.version
36
39
 
37
40
  versions.each.with_index do |v|
data/lib/cassie/tasks.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rake'
2
+ require 'active_support/core_ext/string'
2
3
 
3
4
  require_relative "tasks/task_runner"
4
5
  require_relative "tasks/io"
@@ -1,3 +1,3 @@
1
1
  module Cassie
2
- VERSION = "1.0.6.pre2"
2
+ VERSION = "1.1.0.pre2"
3
3
  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.6.pre2
4
+ version: 1.1.0.pre2
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-02-17 00:00:00.000000000 Z
11
+ date: 2017-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cassandra-driver
@@ -133,6 +133,8 @@ files:
133
133
  - lib/cassie/schema/cassandra_migrations/importer.rb
134
134
  - lib/cassie/schema/cassandra_migrations/migration_file.rb
135
135
  - lib/cassie/schema/configuration.rb
136
+ - lib/cassie/schema/definition.rb
137
+ - lib/cassie/schema/definition/dsl.rb
136
138
  - lib/cassie/schema/migration.rb
137
139
  - lib/cassie/schema/migration/cassandra_support.rb
138
140
  - lib/cassie/schema/migration/dsl.rb
@@ -149,6 +151,8 @@ files:
149
151
  - lib/cassie/schema/queries/insert_version_query.rb
150
152
  - lib/cassie/schema/queries/select_versions_query.rb
151
153
  - lib/cassie/schema/rollback_command.rb
154
+ - lib/cassie/schema/schema_dumper.rb
155
+ - lib/cassie/schema/schema_loader.rb
152
156
  - lib/cassie/schema/structure_dumper.rb
153
157
  - lib/cassie/schema/structure_loader.rb
154
158
  - lib/cassie/schema/version.rb