Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc71cc5
commit d845293
Showing
10 changed files
with
145 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module Pragma | ||
module Migration | ||
class Bind | ||
attr_reader :repository, :request | ||
|
||
def initialize(repository:, request:) | ||
@repository = repository | ||
@request = request | ||
end | ||
|
||
def pending_migrations | ||
allocate_migrations unless @pending_migrations | ||
@pending_migrations | ||
end | ||
|
||
def rolled_migrations | ||
allocate_migrations unless @rolled_migrations | ||
@rolled_migrations | ||
end | ||
|
||
def applying_migrations | ||
compute_applying_migrations unless @applying_migrations | ||
@applying_migrations | ||
end | ||
|
||
def migration_pending?(migration) | ||
pending_migrations.include?(migration) | ||
end | ||
|
||
def migration_rolled?(migration) | ||
rolled_migrations.include?(migration) | ||
end | ||
|
||
def migration_applies?(migration) | ||
applying_migrations.include?(migration) | ||
end | ||
|
||
def user_version | ||
@user_version ||= repository.user_version_from(request) | ||
end | ||
|
||
private | ||
|
||
def allocate_migrations | ||
@pending_migrations = [] | ||
@rolled_migrations = [] | ||
|
||
repository.sorted_versions.each do |version| | ||
if version > user_version | ||
@pending_migrations += version.migrations | ||
else | ||
@rolled_migrations += version.migrations | ||
end | ||
end | ||
end | ||
|
||
def compute_applying_migrations | ||
@applying_migrations = [] | ||
|
||
pending_migrations.each do |migration| | ||
@applying_migrations << migration if migration.applies_to?(request) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
RSpec.describe Pragma::Migration::Bind do | ||
subject { described_class.new(repository: repository, request: request) } | ||
|
||
let(:migration1) { Class.new(Pragma::Migration::Base) } | ||
let(:migration2) { Class.new(Pragma::Migration::Base) } | ||
let(:migration3) { Class.new(Pragma::Migration::Base) } | ||
|
||
let(:repository) do | ||
Class.new(Pragma::Migration::Repository).tap do |repo| | ||
repo.send :version, '2017-12-24' | ||
repo.send :version, '2017-12-25', [migration1] | ||
repo.send :version, '2017-12-26', [migration2] | ||
repo.send :version, '2017-12-27', [migration3] | ||
end | ||
end | ||
|
||
describe '.pending_migrations' do | ||
it 'returns the migrations that must be executed' | ||
end | ||
|
||
describe '.rolled_migrations' do | ||
it 'returns the migrations that have been executed' | ||
end | ||
|
||
describe '.applying_migrations' do | ||
it 'returns the pending migrations that apply to this request' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters