squasher 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -0
- data/README.md +8 -39
- data/bin/squasher +16 -8
- data/lib/squasher/config.rb +3 -0
- data/lib/squasher/messages.yml +3 -8
- data/lib/squasher/render.rb +36 -10
- data/lib/squasher/templates/init_schema.rb.erb +2 -1
- data/lib/squasher/version.rb +1 -1
- data/spec/fake_app/db/structure.sql +48 -0
- data/spec/lib/worker_spec.rb +58 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70564980ec4cb7bc4cad405cd0d173c46bc99f2f
|
4
|
+
data.tar.gz: '051554966cd007618ab03295579a2a1669c449b5'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34ebbe7ee512b65417099403b27085cb9ea5c8e329f674fec89dfe644edcce9cd82b915a2cacbef6ff516afb368e26b957abe4a9a59dd66aee5c1ce4c52cad30
|
7
|
+
data.tar.gz: 1a1ce4239174e3b871d45a1a5ad7d3997bfa48da3e540418bdcce852208f8f099711a0ecbb586a22beb18dba2c7b58e5dcc48efb02547015f62d21c05e7af54c
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
- 0.6.0
|
2
|
+
- Support apps with sql schema ([@mpospelov](https://github.com/mpospelov))
|
3
|
+
- 0.5.1
|
4
|
+
- Fix work on Windows machines ([@tobmatth](https://github.com/tobmatth))
|
5
|
+
- 0.5.0
|
6
|
+
- Rework command line integration. Fix clean process with Rails 5
|
7
|
+
- 0.4.0
|
8
|
+
- Support rails versioned migrations which were introduced in Rails 5
|
9
|
+
- 0.3.1
|
10
|
+
- fix init migration generation
|
11
|
+
- 0.3.0
|
12
|
+
- **rails engines support** ([@JakeTheSnake3p0](https://github.com/JakeTheSnake3p0))
|
13
|
+
- move messages from JSON file to YAML
|
14
|
+
- allow to use a db config with a "soft" parsing errors
|
15
|
+
- 0.2.2
|
16
|
+
- strip white spaces in init migrations
|
17
|
+
- 0.2.1
|
18
|
+
- support rails 5
|
19
|
+
- 0.2.0
|
20
|
+
- add **dry** mode and ability to reuse the previous squasher database
|
21
|
+
- improve database config processing
|
22
|
+
- raise the minimum supported version of Ruby
|
23
|
+
- 0.1.7
|
24
|
+
- a regression fix of the log output ([@lime](https://github.com/lime))
|
25
|
+
- improve a multi-platform support ([@johncarney](https://github.com/johncarney))
|
26
|
+
- 0.1.6
|
27
|
+
- support multiple database settings ([@ppworks](https://github.com/ppworks))
|
data/README.md
CHANGED
@@ -59,51 +59,20 @@ You can tell `squasher` a more detailed date, for example:
|
|
59
59
|
|
60
60
|
### Options
|
61
61
|
|
62
|
-
|
63
|
-
printed in the console.
|
62
|
+
Run `squasher -h` or just `squasher` to see how you can use squasher:
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
squasher will not need to create the db schema and all data from the previous migrations will be there.
|
71
|
-
|
72
|
-
`-e/--engine` - tell squasher that you are squashing a Rails engine. To squash migrations you need to configure a dummy app. If your dummy app located outside the engine's folder provide path to it as the next argument `squasher --engine ../my-engine-app 2016`
|
73
|
-
|
74
|
-
`-m/--migration` - for correct work with Rails 5 specify a migration version like `squasher -m 5.0 ...`
|
64
|
+
- in sql schema rails app
|
65
|
+
- in rails 5+ app
|
66
|
+
- inside an engine
|
67
|
+
- in "dry" mode
|
68
|
+
- in "reuse" mode
|
75
69
|
|
76
70
|
## Requirements
|
77
71
|
|
78
|
-
It works and was tested on Ruby 2.0+ and Rails 3.1+. It also requires a valid development configuration in `config/database.yml
|
72
|
+
It works and was tested on Ruby 2.0+ and Rails 3.1+. It also requires a valid development configuration in `config/database.yml`.
|
79
73
|
If an old migration inserted data (created ActiveRecord model records) you will lose this code in the squashed migration, **BUT** `squasher` will ask you to leave a tmp database which will have all data that was inserted while migrating. Using this database you could add that data as another migration, or into `config/seed.rb` (the expected place for this stuff).
|
80
74
|
|
81
|
-
## Changelog
|
82
|
-
- 0.5.1
|
83
|
-
- Fix work on Windows machines ([@tobmatth](https://github.com/tobmatth))
|
84
|
-
- 0.5.0
|
85
|
-
- Rework command line integration. Fix clean process with Rails 5
|
86
|
-
- 0.4.0
|
87
|
-
- Support rails versioned migrations which were introduced in Rails 5
|
88
|
-
- 0.3.1
|
89
|
-
- fix init migration generation
|
90
|
-
- 0.3.0
|
91
|
-
- **rails engines support** ([@JakeTheSnake3p0](https://github.com/JakeTheSnake3p0))
|
92
|
-
- move messages from JSON file to YAML
|
93
|
-
- allow to use a db config with a "soft" parsing errors
|
94
|
-
- 0.2.2
|
95
|
-
- strip white spaces in init migrations
|
96
|
-
- 0.2.1
|
97
|
-
- support rails 5
|
98
|
-
- 0.2.0
|
99
|
-
- add **dry** mode and ability to reuse the previous squasher database
|
100
|
-
- improve database config processing
|
101
|
-
- raise the minimum supported version of Ruby
|
102
|
-
- 0.1.7
|
103
|
-
- a regression fix of the log output ([@lime](https://github.com/lime))
|
104
|
-
- improve a multi-platform support ([@johncarney](https://github.com/johncarney))
|
105
|
-
- 0.1.6
|
106
|
-
- support multiple database settings ([@ppworks](https://github.com/ppworks))
|
75
|
+
## (Changelog)[CHANGELOG.md]
|
107
76
|
|
108
77
|
## Contributing
|
109
78
|
|
data/bin/squasher
CHANGED
@@ -6,27 +6,33 @@ require 'squasher'
|
|
6
6
|
|
7
7
|
options = {}
|
8
8
|
parser = OptionParser.new do |config|
|
9
|
-
config.
|
9
|
+
config.banner = 'Supported options:'
|
10
10
|
|
11
|
-
config.on('-d', '--dry') do
|
11
|
+
config.on('-d', '--dry', 'execute in "dry" mode(a test squashing without removing old migrations)') do
|
12
12
|
options[:dry] = true
|
13
13
|
end
|
14
14
|
|
15
|
-
config.on('-
|
15
|
+
config.on('-s', '--sql', 'run squasher in the app with sql schema') do
|
16
|
+
options[:sql] = true
|
17
|
+
end
|
18
|
+
|
19
|
+
config.on('-m', '--migration', '=VERSION', 'define the rails migration version(since Rails 5)') do |value|
|
20
|
+
options[:migration] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
config.on('-r', '--reuse', 'reuse the database from a previous squashing') do
|
16
24
|
options[:reuse] = true
|
17
25
|
end
|
18
26
|
|
19
|
-
config.on('-e') do
|
27
|
+
config.on('-e', 'run squasher in the engine(requires the dummy app inside)') do
|
20
28
|
options[:engine] = nil
|
21
29
|
end
|
22
30
|
|
23
|
-
config.on('--engine=PATH') do |value|
|
31
|
+
config.on('--engine=PATH', 'run squasher in the engine with a custom path to the dummy app') do |value|
|
24
32
|
options[:engine] = value
|
25
33
|
end
|
26
34
|
|
27
|
-
config.on('-
|
28
|
-
options[:migration] = value
|
29
|
-
end
|
35
|
+
config.on('-v', '--version', '-h', '--help', 'show this message')
|
30
36
|
end
|
31
37
|
parser.parse!
|
32
38
|
|
@@ -36,4 +42,6 @@ when /\A\d{4}/ then Squasher.squash(ARGV.first)
|
|
36
42
|
when 'clean' then Squasher.clean
|
37
43
|
else
|
38
44
|
Squasher.tell(:usage, version: Squasher::VERSION)
|
45
|
+
puts ''
|
46
|
+
puts parser
|
39
47
|
end
|
data/lib/squasher/config.rb
CHANGED
@@ -57,6 +57,9 @@ module Squasher
|
|
57
57
|
elsif key == :migration
|
58
58
|
Squasher.error(:invalid_migration_version, value: value) unless value.to_s =~ /\A\d.\d\z/
|
59
59
|
@migration_version = "[#{value}]"
|
60
|
+
elsif key == :sql
|
61
|
+
@schema_file = File.join(@app_path, 'db', 'structure.sql')
|
62
|
+
@flags << key
|
60
63
|
else
|
61
64
|
@flags << key
|
62
65
|
end
|
data/lib/squasher/messages.yml
CHANGED
@@ -18,14 +18,9 @@ usage:
|
|
18
18
|
- "Squasher %{version}"
|
19
19
|
- ""
|
20
20
|
- "Examples of usage:"
|
21
|
-
- " :green<squasher> [options] :yellow<year[/month][/day]>
|
22
|
-
- " :green<squasher> :yellow<clean>
|
23
|
-
|
24
|
-
- "Options:"
|
25
|
-
- " :yellow<-d> => execute in :blue<`dry`> mode - test a squashing process without removing old migrations"
|
26
|
-
- " :yellow<-r> => reuse a database from the previous squashing"
|
27
|
-
- " :yellow<-e> [dummy-root] => execute in :blue<`engine`> mode - requires a dummy app"
|
28
|
-
- " :yellow<-m> 5.0 => specify the rails migration version (added in Rails 5)"
|
21
|
+
- " :green<squasher> [options] :yellow<year[/month][/day]> squash migrations prior to a specified date"
|
22
|
+
- " :green<squasher> [options] :yellow<clean> generate or update a cleaning migration and apply it"
|
23
|
+
|
29
24
|
wrong_option: "You provided a wrong option :red<%{arg}>\n\n"
|
30
25
|
invalid_param: "You provided a wrong param :red<%{arg}>\n\n"
|
31
26
|
dry_mode_finished: "The `dry` mode is finished. Below the init schema's content:"
|
data/lib/squasher/render.rb
CHANGED
@@ -17,23 +17,49 @@ module Squasher
|
|
17
17
|
ERB.new(template("#{ name }.rb"), nil, '-').result(binding)
|
18
18
|
end
|
19
19
|
|
20
|
-
def each_schema_line
|
20
|
+
def each_schema_line(&block)
|
21
21
|
File.open(config.schema_file, 'r') do |stream|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
break if line.index("end") == 0
|
27
|
-
yield line.gsub(/\A\s{,2}(.*)\s+\z/, '\1')
|
28
|
-
else
|
29
|
-
inside_schema = true if line.include?("ActiveRecord::Schema")
|
30
|
-
end
|
22
|
+
if @config.set?(:sql)
|
23
|
+
stream_structure(stream, &block)
|
24
|
+
else
|
25
|
+
stream_schema(stream, &block)
|
31
26
|
end
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
35
30
|
private
|
36
31
|
|
32
|
+
def stream_structure(stream)
|
33
|
+
yield 'execute <<-SQL'
|
34
|
+
skip_mode = false
|
35
|
+
ignored_table = ['ar_internal_metadata', 'schema_migrations']
|
36
|
+
stream.each_line do |line|
|
37
|
+
skip_mode = true if ignored_table.any? { |t| line.include?(t) }
|
38
|
+
|
39
|
+
if skip_mode
|
40
|
+
skip_mode = false if line.include?(';')
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
yield line.gsub(/\A\s{,2}(.*)\s+\z/, '\1')
|
45
|
+
end
|
46
|
+
yield 'SQL'
|
47
|
+
end
|
48
|
+
|
49
|
+
def stream_schema(stream)
|
50
|
+
inside_schema = false
|
51
|
+
|
52
|
+
stream.each_line do |line|
|
53
|
+
if inside_schema
|
54
|
+
# reach the end of schema
|
55
|
+
break if line.index("end") == 0
|
56
|
+
yield line.gsub(/\A\s{,2}(.*)\s+\z/, '\1')
|
57
|
+
else
|
58
|
+
inside_schema = true if line.include?("ActiveRecord::Schema")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
37
63
|
def template(name)
|
38
64
|
path = File.join(File.dirname(__FILE__), "templates/#{ name }.erb")
|
39
65
|
template = File.open(path, "rb")
|
data/lib/squasher/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
CREATE TABLE cities (
|
2
|
+
id integer NOT NULL,
|
3
|
+
name character varying,
|
4
|
+
created_at timestamp without time zone NOT NULL,
|
5
|
+
updated_at timestamp without time zone NOT NULL,
|
6
|
+
);
|
7
|
+
|
8
|
+
CREATE TABLE managers (
|
9
|
+
id integer NOT NULL,
|
10
|
+
email character varying,
|
11
|
+
password_digest character varying,
|
12
|
+
created_at timestamp without time zone NOT NULL,
|
13
|
+
updated_at timestamp without time zone NOT NULL
|
14
|
+
);
|
15
|
+
|
16
|
+
CREATE TABLE offices (
|
17
|
+
id integer NOT NULL,
|
18
|
+
name character varying,
|
19
|
+
address character varying,
|
20
|
+
phone character varying,
|
21
|
+
description text,
|
22
|
+
capacity integer,
|
23
|
+
manager_id integer,
|
24
|
+
city_id integer,
|
25
|
+
created_at timestamp without time zone NOT NULL,
|
26
|
+
updated_at timestamp without time zone NOT NULL
|
27
|
+
);
|
28
|
+
|
29
|
+
CREATE TABLE ar_internal_metadata (
|
30
|
+
key character varying NOT NULL,
|
31
|
+
value character varying,
|
32
|
+
created_at timestamp without time zone NOT NULL,
|
33
|
+
updated_at timestamp without time zone NOT NULL
|
34
|
+
);
|
35
|
+
|
36
|
+
CREATE TABLE schema_migrations (
|
37
|
+
version character varying NOT NULL
|
38
|
+
);
|
39
|
+
|
40
|
+
ALTER TABLE ONLY ar_internal_metadata
|
41
|
+
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
|
42
|
+
|
43
|
+
ALTER TABLE ONLY schema_migrations
|
44
|
+
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
|
45
|
+
|
46
|
+
INSERT INTO "schema_migrations" (version) VALUES
|
47
|
+
('20170831152134'),
|
48
|
+
('20170907145259');
|
data/spec/lib/worker_spec.rb
CHANGED
@@ -55,6 +55,64 @@ describe Squasher::Worker do
|
|
55
55
|
Squasher.instance_variable_set(:@config, Squasher::Config.new)
|
56
56
|
end
|
57
57
|
|
58
|
+
specify 'the sql mode' do
|
59
|
+
Squasher.config.set(:sql, true)
|
60
|
+
worker = described_class.new(Time.new(2014))
|
61
|
+
allow(worker).to receive(:under_squash_env).and_yield.and_return(true)
|
62
|
+
new_migration_path = File.join(Dir.tmpdir, 'init_schema.rb')
|
63
|
+
allow_any_instance_of(Squasher::Config).to receive(:migration_file).with('20131213090719', :init_schema).and_return(new_migration_path)
|
64
|
+
expect(FileUtils).to receive(:rm).with(File.join(fake_root, 'db', 'migrate', '20131205160936_first_migration.rb'))
|
65
|
+
expect(FileUtils).to receive(:rm).with(File.join(fake_root, 'db', 'migrate', '20131213090719_second_migration.rb'))
|
66
|
+
|
67
|
+
expect(Squasher).to receive(:ask).with(:keep_database).and_return(false)
|
68
|
+
expect(Squasher).to receive(:rake).with("db:drop")
|
69
|
+
expect(Squasher).to receive(:ask).with(:apply_clean).and_return(false)
|
70
|
+
worker.process
|
71
|
+
|
72
|
+
expect(File.exists?(new_migration_path)).to be_truthy
|
73
|
+
File.open(new_migration_path) do |stream|
|
74
|
+
content = stream.read
|
75
|
+
expect(content).to eq(<<-RUBY
|
76
|
+
class InitSchema < ActiveRecord::Migration
|
77
|
+
def up
|
78
|
+
execute <<-SQL
|
79
|
+
CREATE TABLE cities (
|
80
|
+
id integer NOT NULL,
|
81
|
+
name character varying,
|
82
|
+
created_at timestamp without time zone NOT NULL,
|
83
|
+
updated_at timestamp without time zone NOT NULL,
|
84
|
+
);
|
85
|
+
CREATE TABLE managers (
|
86
|
+
id integer NOT NULL,
|
87
|
+
email character varying,
|
88
|
+
password_digest character varying,
|
89
|
+
created_at timestamp without time zone NOT NULL,
|
90
|
+
updated_at timestamp without time zone NOT NULL
|
91
|
+
);
|
92
|
+
CREATE TABLE offices (
|
93
|
+
id integer NOT NULL,
|
94
|
+
name character varying,
|
95
|
+
address character varying,
|
96
|
+
phone character varying,
|
97
|
+
description text,
|
98
|
+
capacity integer,
|
99
|
+
manager_id integer,
|
100
|
+
city_id integer,
|
101
|
+
created_at timestamp without time zone NOT NULL,
|
102
|
+
updated_at timestamp without time zone NOT NULL
|
103
|
+
);
|
104
|
+
SQL
|
105
|
+
end
|
106
|
+
|
107
|
+
def down
|
108
|
+
raise ActiveRecord::IrreversibleMigration, "The initial migration is not revertable"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
RUBY
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
58
116
|
specify 'the dry mode' do
|
59
117
|
Squasher.config.set(:dry, nil)
|
60
118
|
worker = described_class.new(Time.new(2014))
|
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.6.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-09-
|
11
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,6 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- spec/fake_app/db/migrate/20140101010101_squasher_clean.rb
|
85
86
|
- spec/fake_app/db/migrate/20140103124257_third_migration.rb
|
86
87
|
- spec/fake_app/db/schema.rb
|
88
|
+
- spec/fake_app/db/structure.sql
|
87
89
|
- spec/lib/cleaner_spec.rb
|
88
90
|
- spec/lib/config_spec.rb
|
89
91
|
- spec/lib/squasher_spec.rb
|
@@ -123,6 +125,7 @@ test_files:
|
|
123
125
|
- spec/fake_app/db/migrate/20140101010101_squasher_clean.rb
|
124
126
|
- spec/fake_app/db/migrate/20140103124257_third_migration.rb
|
125
127
|
- spec/fake_app/db/schema.rb
|
128
|
+
- spec/fake_app/db/structure.sql
|
126
129
|
- spec/lib/cleaner_spec.rb
|
127
130
|
- spec/lib/config_spec.rb
|
128
131
|
- spec/lib/squasher_spec.rb
|