Module: Cassie::Schema::Versioning
- Included in:
- Cassie::Schema
- Defined in:
- lib/cassie/schema/versioning.rb
Instance Method Summary collapse
-
#applied_versions ⇒ Enumerable<Version>
The versions that have been migrated up for the Cassandra database This lists the versions stored in the persistence layer, in reverse chronological order (newest first).
-
#forget_version(version) ⇒ Boolean
Remove the version from the schema version store.
-
#initialize_versioning ⇒ void
Create the keyspace and table for tracking schema versions in the Cassandra database if they don’t already exist.
-
#local_versions ⇒ Enumeration<Version>
Versions for the #migration_files If a migration is applied versions, the object for that version will be the applied version, containing the full information about the applied version.
-
#migration_files ⇒ Array<String>
Absolute paths to the migration files in the migration directory.
-
#next_version(bump_type = nil) ⇒ Version
A version with an incremented version number that would be applied after the latest (local or applied) migration.
-
#record_version(version, set_execution_metadata = true) ⇒ Boolean
Record a version in the schema version store.
-
#version ⇒ Version
The current schema version.
Instance Method Details
#applied_versions ⇒ Enumerable<Version>
The versions that have been migrated up for the Cassandra database This lists the versions stored in the persistence layer, in reverse chronological order (newest first).
28 29 30 |
# File 'lib/cassie/schema/versioning.rb', line 28 def applied_versions @applied_versions ||= load_applied_versions end |
#forget_version(version) ⇒ Boolean
Remove the version from the schema version store. This should only be done if the version has been sucesfully reverted
70 71 72 73 |
# File 'lib/cassie/schema/versioning.rb', line 70 def forget_version(version) DeleteVersionQuery.new(id: version.id).execute @applied_versions = nil end |
#initialize_versioning ⇒ void
This method returns an undefined value.
Create the keyspace and table for tracking schema versions in the Cassandra database if they don’t already exist
35 36 37 38 |
# File 'lib/cassie/schema/versioning.rb', line 35 def initialize_versioning create_schema_keyspace unless schema_keyspace_exists? create_versions_table unless versions_table_exists? end |
#local_versions ⇒ Enumeration<Version>
Versions for the #migration_files If a migration is applied versions, the object for that version will be the applied version, containing the full information about the applied version
86 87 88 |
# File 'lib/cassie/schema/versioning.rb', line 86 def local_versions @local_versions ||= load_local_versions end |
#migration_files ⇒ Array<String>
Absolute paths to the migration files in the migration directory
77 78 79 |
# File 'lib/cassie/schema/versioning.rb', line 77 def migration_files Dir[root.join(paths[:migrations_directory], "[0-9]*_*.rb")] end |
#next_version(bump_type = nil) ⇒ Version
A version with an incremented version number that would be applied after the latest (local or applied) migration.
99 100 101 102 103 104 |
# File 'lib/cassie/schema/versioning.rb', line 99 def next_version(bump_type=nil) local_max = local_versions.max || Version.new('0') applied_max = applied_versions.max || Version.new('0') max_version = [local_max, applied_max].max max_version.next(bump_type) end |
#record_version(version, set_execution_metadata = true) ⇒ Boolean
Record a version in the schema version store. This should only be done if the version has been sucesfully migrated
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cassie/schema/versioning.rb', line 48 def record_version(version, =true) time = Time.now version.id ||= Cassandra::TimeUuid::Generator.new.at(time) if version.executed_at = time version.executor = Etc.getlogin rescue '<unknown>' end InsertVersionQuery.new(version: version).execute! @applied_versions = nil rescue StandardError => e version.id = nil version.executed_at = nil version.executor = nil raise e end |
#version ⇒ Version
The current schema version
18 19 20 21 22 |
# File 'lib/cassie/schema/versioning.rb', line 18 def version SelectVersionsQuery.new.fetch_first || Version.new('0') rescue Cassandra::Errors::InvalidError raise uninitialized_error end |