mongration 0.0.3.pre.beta → 0.0.4.pre.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +11 -4
- data/README.md +9 -2
- data/Rakefile +5 -0
- data/lib/mongration.rb +81 -26
- data/lib/mongration/configuration.rb +27 -4
- data/lib/mongration/create_migration.rb +11 -16
- data/lib/mongration/create_migration/migration_file_writer.rb +43 -0
- data/lib/mongration/file.rb +52 -9
- data/lib/mongration/migrate_all_up.rb +20 -0
- data/lib/mongration/migrate_down.rb +20 -0
- data/lib/mongration/migrate_up.rb +20 -0
- data/lib/mongration/migration.rb +37 -0
- data/lib/mongration/null_output.rb +6 -0
- data/lib/mongration/rake_tasks.rb +40 -0
- data/lib/mongration/rollback.rb +5 -16
- data/lib/mongration/status.rb +27 -0
- data/lib/mongration/version.rb +1 -1
- data/lib/os_check.rb +7 -0
- data/spec/fixtures/integration.rb +23 -27
- data/spec/integration/{template_spec.rb → create_migration_spec.rb} +5 -1
- data/spec/integration/migrate_spec.rb +76 -0
- data/spec/integration/migrate_with_version_spec.rb +38 -0
- data/spec/integration/{mongration_spec.rb → rollback_spec.rb} +11 -36
- data/spec/integration/status_spec.rb +61 -0
- data/spec/integration/version_spec.rb +20 -0
- data/spec/spec_helper.rb +16 -4
- data/spec/unit/mongration/{data_store/mongoid/migration_spec.rb → migration_spec.rb} +9 -3
- data/spec/unit/mongration/rake_tasks_spec.rb +95 -0
- metadata +40 -35
- data/lib/mongration/data_store/in_memory/store.rb +0 -32
- data/lib/mongration/data_store/mongoid/migration.rb +0 -24
- data/lib/mongration/data_store/mongoid/store.rb +0 -53
- data/lib/mongration/migrate.rb +0 -52
- data/lib/mongration/migration_file_writer.rb +0 -40
- data/lib/mongration/null_migration.rb +0 -16
- data/lib/mongration/rake_task.rb +0 -18
- data/spec/support/store_interface.rb +0 -18
- data/spec/unit/mongration/data_store/in_memory/store_spec.rb +0 -10
- data/spec/unit/mongration/data_store/mongoid/store_spec.rb +0 -12
@@ -1,24 +0,0 @@
|
|
1
|
-
module Mongration
|
2
|
-
module DataStore
|
3
|
-
module Mongoid
|
4
|
-
|
5
|
-
# @private
|
6
|
-
class Migration
|
7
|
-
include ::Mongoid::Document
|
8
|
-
|
9
|
-
field :version, type: Integer
|
10
|
-
field :file_names, type: Array
|
11
|
-
|
12
|
-
field :created_at, type: Time, default: -> { Time.now }
|
13
|
-
field :deleted_at, type: Time
|
14
|
-
|
15
|
-
default_scope -> { where(deleted_at: nil) }
|
16
|
-
|
17
|
-
def destroy(*)
|
18
|
-
self.deleted_at = Time.now
|
19
|
-
save!
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'mongoid'
|
2
|
-
|
3
|
-
require 'mongration/data_store/mongoid/migration'
|
4
|
-
|
5
|
-
module Mongration
|
6
|
-
module DataStore
|
7
|
-
module Mongoid
|
8
|
-
class Store
|
9
|
-
|
10
|
-
class Mongration::DataStore::Mongoid::ConfigNotFound < ::Mongration::Errors
|
11
|
-
def initialize(path)
|
12
|
-
super("#{path} cannot be found.")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
DEFAULT_CONFIG_PATH = ::File.join('config', 'mongoid.yml')
|
17
|
-
|
18
|
-
# @params [Hash] options
|
19
|
-
#
|
20
|
-
def initialize(options = {})
|
21
|
-
@config_path = options[:config_path] || DEFAULT_CONFIG_PATH
|
22
|
-
|
23
|
-
load_configuration
|
24
|
-
end
|
25
|
-
|
26
|
-
# @private
|
27
|
-
def migrations
|
28
|
-
Migration.all
|
29
|
-
end
|
30
|
-
|
31
|
-
# @private
|
32
|
-
def build_migration(version, file_names)
|
33
|
-
Migration.new(version: version, file_names: file_names)
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def load_configuration
|
39
|
-
unless ::File.exists?(@config_path)
|
40
|
-
raise Mongration::DataStore::Mongoid::ConfigNotFound.new(@config_path)
|
41
|
-
end
|
42
|
-
|
43
|
-
env = if defined?(Rails)
|
44
|
-
Rails.env
|
45
|
-
else
|
46
|
-
:test
|
47
|
-
end
|
48
|
-
::Mongoid.load!(@config_path, env)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/mongration/migrate.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
module Mongration
|
2
|
-
|
3
|
-
# @private
|
4
|
-
class Migrate
|
5
|
-
|
6
|
-
def self.perform(version)
|
7
|
-
new(version, Mongration.configuration.data_store).perform
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(version, data_store)
|
11
|
-
@version = version
|
12
|
-
@data_store = data_store
|
13
|
-
end
|
14
|
-
|
15
|
-
def perform
|
16
|
-
files_to_migrate.sort.each(&:up)
|
17
|
-
migration.save
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def files_to_migrate
|
23
|
-
migration.file_names.map do |file_name|
|
24
|
-
Mongration::File.new(file_name)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def migration
|
29
|
-
@migration ||=
|
30
|
-
if file_names.present?
|
31
|
-
@data_store.build_migration(
|
32
|
-
@version,
|
33
|
-
file_names
|
34
|
-
)
|
35
|
-
else
|
36
|
-
NullMigration.new
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def file_names
|
41
|
-
all_file_names - migrated_file_names
|
42
|
-
end
|
43
|
-
|
44
|
-
def all_file_names
|
45
|
-
Mongration::File.all.map(&:file_name)
|
46
|
-
end
|
47
|
-
|
48
|
-
def migrated_file_names
|
49
|
-
@data_store.migrations.flat_map(&:file_names)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Mongration
|
2
|
-
|
3
|
-
# @private
|
4
|
-
class MigrationFileWriter
|
5
|
-
|
6
|
-
def self.write(file_name, options = {})
|
7
|
-
new(file_name, options).write
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(file_name, options = {})
|
11
|
-
@file_name = file_name
|
12
|
-
@dir = options[:dir]
|
13
|
-
@up = options[:up]
|
14
|
-
@down = options[:down]
|
15
|
-
end
|
16
|
-
|
17
|
-
def write
|
18
|
-
::File.open(::File.join(@dir, @file_name), 'w') do |file|
|
19
|
-
file.write(<<EOS
|
20
|
-
class #{class_name}
|
21
|
-
def self.up
|
22
|
-
#{@up}
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.down
|
26
|
-
#{@down}
|
27
|
-
end
|
28
|
-
end
|
29
|
-
EOS
|
30
|
-
)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def class_name
|
37
|
-
Mongration::File.new(@file_name).class_name
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/mongration/rake_task.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rake'
|
2
|
-
|
3
|
-
namespace :db do
|
4
|
-
task migrate: :environment do
|
5
|
-
Mongration.migrate
|
6
|
-
end
|
7
|
-
|
8
|
-
namespace :migrate do
|
9
|
-
task rollback: :environment do
|
10
|
-
Mongration.rollback
|
11
|
-
end
|
12
|
-
|
13
|
-
task :create, [:name] => [:environment] do |t, args|
|
14
|
-
name = args[:name]
|
15
|
-
Mongration.create_migration(name)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
shared_examples_for 'store interface' do
|
2
|
-
it 'adds a migration' do
|
3
|
-
migration = store.build_migration(1, ['001_foo.rb'])
|
4
|
-
migration.save
|
5
|
-
|
6
|
-
migration = store.migrations.first
|
7
|
-
expect(migration.version).to eq(1)
|
8
|
-
expect(migration.file_names).to eq(['001_foo.rb'])
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'destroys a migration' do
|
12
|
-
migration = store.build_migration(1, ['001_foo.rb'])
|
13
|
-
migration.save
|
14
|
-
migration.destroy
|
15
|
-
|
16
|
-
expect(store.migrations).to eq([])
|
17
|
-
end
|
18
|
-
end
|