Class: Code0::ZeroTrack::Database::SchemaMigrations::Migrations
- Inherits:
-
Object
- Object
- Code0::ZeroTrack::Database::SchemaMigrations::Migrations
- Defined in:
- lib/code0/zero_track/database/schema_migrations/migrations.rb
Constant Summary collapse
- MIGRATION_VERSION_GLOB =
'20[0-9][0-9]*'
Instance Method Summary collapse
-
#initialize(context) ⇒ Migrations
constructor
A new instance of Migrations.
- #load_all ⇒ Object
- #touch_all ⇒ Object
Constructor Details
#initialize(context) ⇒ Migrations
Returns a new instance of Migrations.
17 18 19 |
# File 'lib/code0/zero_track/database/schema_migrations/migrations.rb', line 17 def initialize(context) @context = context end |
Instance Method Details
#load_all ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/code0/zero_track/database/schema_migrations/migrations.rb', line 36 def load_all return if version_filenames.empty? return unless @context.connection.pool.schema_migration.table_exists? values = version_filenames.map { |vf| "('#{@context.connection.quote_string(vf)}')" } @context.connection.execute(<<~SQL.squish) INSERT INTO schema_migrations (version) VALUES #{values.join(',')} ON CONFLICT DO NOTHING SQL end |
#touch_all ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/code0/zero_track/database/schema_migrations/migrations.rb', line 21 def touch_all return unless @context.versions_to_create.any? version_filepaths = version_filenames.map { |f| File.join(schema_directory, f) } FileUtils.rm(version_filepaths) @context.versions_to_create.each do |version| version_filepath = File.join(schema_directory, version) File.open(version_filepath, 'w') do |file| file << Digest::SHA256.hexdigest(version) end end end |