squasher 0.4.0 → 0.5.0
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/.travis.yml +2 -0
- data/bin/squasher +29 -5
- data/lib/squasher.rb +4 -19
- data/lib/squasher/cleaner.rb +4 -5
- data/lib/squasher/config.rb +3 -5
- data/lib/squasher/messages.yml +3 -1
- data/lib/squasher/version.rb +3 -0
- data/lib/squasher/worker.rb +2 -2
- data/spec/lib/cleaner_spec.rb +2 -2
- data/spec/lib/config_spec.rb +1 -1
- data/spec/lib/worker_spec.rb +2 -2
- data/squasher.gemspec +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60335f7e6ad04a4db267dd1ad99152aa02d79242
|
4
|
+
data.tar.gz: 4c17e356d84255ae3177094facf40904845e8223
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74cd4d6ba164431b5ab92d2a57af1ac197a3cf66b790332386d29c0e305c448b4063e9119f7d22b9623a7d4145d387de7ac77ef38dfeaa216baafe86b716c20f
|
7
|
+
data.tar.gz: f6b728c61110d26e8fa647b58b8e37a02ceac6ac32f74fb6111eec377f475d983faa59d74be91ce633447e82c40fd2a2625b19fba1fd48c1d229c355c4baa735
|
data/.travis.yml
CHANGED
data/bin/squasher
CHANGED
@@ -1,10 +1,34 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
lib = File.expand_path('../../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'optparse'
|
2
5
|
require 'squasher'
|
3
6
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
options = {}
|
8
|
+
parser = OptionParser.new do |config|
|
9
|
+
config.on('-v', '--version', '-h', '--help')
|
10
|
+
|
11
|
+
config.on('-d', '--dry') do
|
12
|
+
options[:dry] = true
|
13
|
+
end
|
14
|
+
|
15
|
+
config.on('-r', '--reuse') do
|
16
|
+
options[:reuse] = true
|
17
|
+
end
|
18
|
+
|
19
|
+
config.on('-e', '--engine=PATH') do |value|
|
20
|
+
options[:engine] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
config.on('-m', '--migration', '=VERSION') do |value|
|
24
|
+
options[:migration] = value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
parser.parse!
|
28
|
+
|
29
|
+
case ARGV.first
|
30
|
+
when /\A\d{4}/ then Squasher.squash(ARGV.first, options)
|
31
|
+
when 'clean' then Squasher.clean(options)
|
8
32
|
else
|
9
|
-
Squasher.tell(:usage)
|
33
|
+
Squasher.tell(:usage, version: Squasher::VERSION)
|
10
34
|
end
|
data/lib/squasher.rb
CHANGED
@@ -4,6 +4,7 @@ module Squasher
|
|
4
4
|
autoload :Cleaner, 'squasher/cleaner'
|
5
5
|
autoload :Config, 'squasher/config'
|
6
6
|
autoload :Render, 'squasher/render'
|
7
|
+
autoload :VERSION, 'squasher/version'
|
7
8
|
autoload :Worker, 'squasher/worker'
|
8
9
|
|
9
10
|
attr_reader :config
|
@@ -13,28 +14,12 @@ module Squasher
|
|
13
14
|
def squash(raw_date, options)
|
14
15
|
parts = raw_date.to_s.split('/').map(&:to_i)
|
15
16
|
date = Time.new(*parts)
|
16
|
-
|
17
|
-
options.reduce([]) do |acc, arg|
|
18
|
-
if arg.index('-') == 0
|
19
|
-
arg = arg.gsub('-', '').to_sym
|
20
|
-
unless Config::OPTIONS.include?(arg)
|
21
|
-
tell(:wrong_option, arg: arg)
|
22
|
-
error(:usage)
|
23
|
-
end
|
24
|
-
acc.push([arg])
|
25
|
-
elsif acc.empty?
|
26
|
-
tell(:invalid_param, arg: arg)
|
27
|
-
error(:usage)
|
28
|
-
else
|
29
|
-
acc.last[1] = arg
|
30
|
-
end
|
31
|
-
acc
|
32
|
-
end.each { |(k, v)| config.set(k, v) }
|
33
|
-
|
17
|
+
options.each { |(k, v)| config.set(k, v) }
|
34
18
|
Worker.process(date)
|
35
19
|
end
|
36
20
|
|
37
|
-
def clean
|
21
|
+
def clean(options)
|
22
|
+
options.each { |(k, v)| config.set(k, v) }
|
38
23
|
Cleaner.process
|
39
24
|
end
|
40
25
|
|
data/lib/squasher/cleaner.rb
CHANGED
@@ -13,11 +13,10 @@ module Squasher
|
|
13
13
|
|
14
14
|
migration_file = config.migration_file(now_timestamp, MIGRATION_NAME)
|
15
15
|
if prev_migration
|
16
|
-
FileUtils.
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
FileUtils.rm(prev_migration)
|
17
|
+
end
|
18
|
+
File.open(migration_file, 'wb') do |stream|
|
19
|
+
stream << ::Squasher::Render.render(MIGRATION_NAME, config)
|
21
20
|
end
|
22
21
|
Squasher.rake("db:migrate", :db_cleaning)
|
23
22
|
end
|
data/lib/squasher/config.rb
CHANGED
@@ -4,8 +4,6 @@ require 'erb'
|
|
4
4
|
|
5
5
|
module Squasher
|
6
6
|
class Config
|
7
|
-
OPTIONS = [:d, :r, :e, :m].freeze
|
8
|
-
|
9
7
|
module Render
|
10
8
|
extend self
|
11
9
|
|
@@ -45,7 +43,7 @@ module Squasher
|
|
45
43
|
end
|
46
44
|
|
47
45
|
def set(key, value)
|
48
|
-
if key == :
|
46
|
+
if key == :engine
|
49
47
|
base = value.nil? ? @root_path : File.expand_path(value, @root_path)
|
50
48
|
list = Dir.glob(File.join(base, '**', '*', 'config', 'application.rb'))
|
51
49
|
case list.size
|
@@ -56,7 +54,7 @@ module Squasher
|
|
56
54
|
else
|
57
55
|
Squasher.error(:multi_dummy_case, base: base)
|
58
56
|
end
|
59
|
-
elsif key == :
|
57
|
+
elsif key == :migration
|
60
58
|
Squasher.error(:invalid_migration_version, value: value) unless value.to_s =~ /\A\d.\d\z/
|
61
59
|
@migration_version = "[#{value}]"
|
62
60
|
else
|
@@ -64,7 +62,7 @@ module Squasher
|
|
64
62
|
end
|
65
63
|
end
|
66
64
|
|
67
|
-
def
|
65
|
+
def set?(k)
|
68
66
|
@flags.include?(k)
|
69
67
|
end
|
70
68
|
|
data/lib/squasher/messages.yml
CHANGED
@@ -15,7 +15,9 @@ db_migrate: Squasher is applying migrations on a tmp database
|
|
15
15
|
db_cleaning: Squasher is applying the clean migration
|
16
16
|
db_reuse: Squasher is reusing the database from the previous squashing
|
17
17
|
usage:
|
18
|
-
- "
|
18
|
+
- "Squasher %{version}"
|
19
|
+
- ""
|
20
|
+
- "Examples of usage:"
|
19
21
|
- " :green<squasher> [options] :yellow<year[/month][/day]> => squash migrations prior to a specified date"
|
20
22
|
- " :green<squasher> :yellow<clean> => generate or update a cleaning migration and apply it"
|
21
23
|
- " :green<squasher> :yellow<info> => show the message\n"
|
data/lib/squasher/worker.rb
CHANGED
@@ -16,7 +16,7 @@ module Squasher
|
|
16
16
|
check!
|
17
17
|
|
18
18
|
result = under_squash_env do
|
19
|
-
if Squasher.config.
|
19
|
+
if Squasher.config.set?(:dry)
|
20
20
|
Squasher.tell(:dry_mode_finished)
|
21
21
|
puts Render.render(:init_schema, config)
|
22
22
|
else
|
@@ -66,7 +66,7 @@ module Squasher
|
|
66
66
|
|
67
67
|
def under_squash_env
|
68
68
|
config.stub_dbconfig do
|
69
|
-
if Squasher.config.
|
69
|
+
if Squasher.config.set?(:reuse)
|
70
70
|
Squasher.tell(:db_reuse)
|
71
71
|
else
|
72
72
|
return unless Squasher.rake("db:drop db:create", :db_create)
|
data/spec/lib/cleaner_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Squasher::Cleaner do
|
|
15
15
|
|
16
16
|
it 'create a new migration' do
|
17
17
|
allow_any_instance_of(Squasher::Cleaner).to receive(:prev_migration).and_return(nil)
|
18
|
-
Squasher.clean
|
18
|
+
Squasher.clean({})
|
19
19
|
|
20
20
|
expect(clean_migrations).to include(expected_file)
|
21
21
|
File.open(expected_file) do |stream|
|
@@ -25,7 +25,7 @@ describe Squasher::Cleaner do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'update an existing migration' do
|
28
|
-
Squasher.clean
|
28
|
+
Squasher.clean({})
|
29
29
|
|
30
30
|
expect(clean_migrations.size).to be(1)
|
31
31
|
expect(clean_migrations.first).to eq(expected_file)
|
data/spec/lib/config_spec.rb
CHANGED
@@ -58,7 +58,7 @@ describe Squasher::Config do
|
|
58
58
|
|
59
59
|
specify "generate versioned migrations" do
|
60
60
|
config = Squasher::Config.new
|
61
|
-
config.set(:
|
61
|
+
config.set(:migration, '5.1')
|
62
62
|
content = Squasher::Render.render(:init_schema, config)
|
63
63
|
expect(content).to include('ActiveRecord::Migration[5.1]')
|
64
64
|
end
|
data/spec/lib/worker_spec.rb
CHANGED
@@ -56,7 +56,7 @@ describe Squasher::Worker do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
specify 'the dry mode' do
|
59
|
-
Squasher.config.set(:
|
59
|
+
Squasher.config.set(:dry, nil)
|
60
60
|
worker = described_class.new(Time.new(2014))
|
61
61
|
allow(worker).to receive(:under_squash_env).and_yield.and_return(true)
|
62
62
|
expect(Squasher).to receive(:tell).with(:dry_mode_finished).and_call_original
|
@@ -67,7 +67,7 @@ describe Squasher::Worker do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
specify 'reuse of an existing database' do
|
70
|
-
Squasher.config.set(:
|
70
|
+
Squasher.config.set(:reuse, nil)
|
71
71
|
worker = described_class.new(Time.new(2014))
|
72
72
|
expect(Squasher).to receive(:tell).with(:db_reuse).and_call_original
|
73
73
|
expect(Squasher).not_to receive(:rake).with("db:drop db:create", :db_create)
|
data/squasher.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
2
|
lib = File.expand_path('../lib', __FILE__)
|
4
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'squasher/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "squasher"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Squasher::VERSION
|
9
9
|
spec.authors = ["Sergey Pchelintsev"]
|
10
10
|
spec.email = ["linz.sergey@gmail.com"]
|
11
11
|
spec.description = %q{Squash your old migrations}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squasher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pchelintsev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/squasher/render.rb
|
75
75
|
- lib/squasher/templates/init_schema.rb.erb
|
76
76
|
- lib/squasher/templates/squasher_clean.rb.erb
|
77
|
+
- lib/squasher/version.rb
|
77
78
|
- lib/squasher/worker.rb
|
78
79
|
- spec/fake_app/config/database.yml
|
79
80
|
- spec/fake_app/config/invalid_database.yml
|