squasher 0.1.0 → 0.1.1
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 +7 -0
- data/Gemfile +7 -0
- data/README.md +23 -10
- data/Rakefile +6 -0
- data/lib/squasher.rb +2 -2
- data/lib/squasher/messages.json +7 -7
- data/lib/squasher/version.rb +1 -1
- data/spec/fake_app/db/migrate/{201312090000_first_migration.rb → 20131205160936_first_migration.rb} +0 -0
- data/spec/fake_app/db/migrate/{2013122900_second_migration.rb → 20131213090719_second_migration.rb} +0 -0
- data/spec/fake_app/db/migrate/{20140110_third_migration.rb → 20140103124257_third_migration.rb} +0 -0
- data/spec/lib/squasher/worker_spec.rb +3 -3
- metadata +20 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8775b118d632b6d115055e0f8fcef4cfa9f0908c
|
|
4
|
+
data.tar.gz: c78d28c7863de87b9336487ebf6c60f9e7c5abab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b6e4ca16a710cbc554f026c572cb18fdec3bbd605ca00bd288d15fa54cff6f4a32d6a7afba09f3209c1ba68a28cb60346c9ee1e5212d3f1a2b0afc6dd7620c0
|
|
7
|
+
data.tar.gz: 65f5605caa98b23b43796e6ccfeb0b4468b2830c6001923624ff9720f13e62622dfd8f9efd52191d856b681464dc280e14b1cf4eb2e650d967fc2f60cdfcbc6c
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# Squasher
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
[](https://travis-ci.org/jalkoby/squasher)
|
|
4
|
+
[](https://codeclimate.com/github/jalkoby/squasher)
|
|
5
|
+
[](http://badge.fury.io/rb/squasher)
|
|
6
|
+
|
|
7
|
+
Squasher compresses old migrations in a Rails application. If you work on a big project with lots of migrations, every `rake db:migrate` might take a few seconds, or creating of a new database might take a few minutes. That's because Rails loads all those migration files. Squasher removes all the migrations and creates a single migration with the final database state of the specified date (a new migration will look like a schema).
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
9
|
-
You should not add this to Gemfile. Just standalone installation:
|
|
11
|
+
You should not add this to your Gemfile. Just standalone installation:
|
|
10
12
|
|
|
11
13
|
$ gem install squasher
|
|
12
14
|
|
|
@@ -14,19 +16,30 @@ You should not add this to Gemfile. Just standalone installation:
|
|
|
14
16
|
|
|
15
17
|
## Usage
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
Suppose your application was created a few years ago. `%app_root%/db/migrate` folder looks like this:
|
|
20
|
+
```bash
|
|
21
|
+
2009...._first_migration.rb
|
|
22
|
+
2009...._another_migration.rb
|
|
23
|
+
# and a lot of other files
|
|
24
|
+
2011...._adding_model_foo.rb
|
|
25
|
+
# few years later
|
|
26
|
+
2013...._removing_model_foo.rb
|
|
27
|
+
# and so on
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Storing these atomic changes over time is painful and useless. It's time to archive all this stuff. Once you install the gem you can run the `squasher` command.
|
|
18
31
|
|
|
19
|
-
$ squasher 2014 #compress all migrations which were created prior to
|
|
32
|
+
$ squasher 2014 #compress all migrations which were created prior to the year 2014
|
|
20
33
|
|
|
21
34
|
You can tell `squasher` a more detailed date, for example:
|
|
22
35
|
|
|
23
|
-
$ squasher 2013/12 #prior December 2013
|
|
24
|
-
$ squasher 2013/12/19 #prior 19 December 2013
|
|
36
|
+
$ squasher 2013/12 #prior to December 2013
|
|
37
|
+
$ squasher 2013/12/19 #prior to 19 December 2013
|
|
25
38
|
|
|
26
39
|
## Requirements
|
|
27
40
|
|
|
28
|
-
It works and was tested on Ruby 1.9.3+ and Rails 3.
|
|
29
|
-
If
|
|
41
|
+
It works and was tested on Ruby 1.9.3+ and Rails 3.1+. It also requires a valid configuration in `config/database.yml` and using Ruby format in `db/schema.rb` (default Rails use-case).
|
|
42
|
+
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 all the 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).
|
|
30
43
|
|
|
31
44
|
## Contributing
|
|
32
45
|
|
data/Rakefile
CHANGED
data/lib/squasher.rb
CHANGED
|
@@ -29,7 +29,7 @@ module Squasher
|
|
|
29
29
|
def tell(key, options = {})
|
|
30
30
|
message = messages.fetch(key.to_s)
|
|
31
31
|
message = colorize(message)
|
|
32
|
-
|
|
32
|
+
message = message % options
|
|
33
33
|
puts message
|
|
34
34
|
end
|
|
35
35
|
|
|
@@ -49,7 +49,7 @@ module Squasher
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def colorize(message)
|
|
52
|
-
message.gsub(/\:(\w+)
|
|
52
|
+
message.gsub(/\:(\w+)\<([^>]+)\>/) do |match|
|
|
53
53
|
color_code = { "red" => "031", "green" => "032", "yellow" => "033" }[$1]
|
|
54
54
|
"\033[#{ color_code }m#{ $2 }\033[039m"
|
|
55
55
|
end
|
data/lib/squasher/messages.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
"keep_database" : "Squasher created `:green
|
|
2
|
+
"keep_database" : "Squasher created the `:green<squasher>` database for its needs.\nIt might be useful if to keep it if any of your deleted migrations inserted data into database.\nKeep it (:green<yes> / :red<no>)?",
|
|
3
3
|
|
|
4
|
-
"apply_clean": "Do you want to clean your database
|
|
4
|
+
"apply_clean": "Do you want to clean your database of old schema migration records(:red<yes>/:green<no>)?",
|
|
5
5
|
|
|
6
|
-
"migration_folder_missing" : "The folder with migrations is missing.\nAre you sure in the :red
|
|
6
|
+
"migration_folder_missing" : "The folder with migrations is missing.\nAre you sure you're in the :red<root of a rails> application?",
|
|
7
7
|
|
|
8
|
-
"no_migrations" : "There are no migrations in the folder prior :red{
|
|
8
|
+
"no_migrations" : "There are no migrations in the folder prior to :red<%{date}>",
|
|
9
9
|
|
|
10
|
-
"dbconfig_invalid" : "Squasher could not find `:green
|
|
10
|
+
"dbconfig_invalid" : "Squasher could not find `:green<database.yml>` with working development environment",
|
|
11
11
|
|
|
12
12
|
"db_create": "Squasher is creating a tmp database",
|
|
13
13
|
|
|
14
|
-
"db_migrate": "Squasher is
|
|
14
|
+
"db_migrate": "Squasher is applying migrations on a tmp database",
|
|
15
15
|
|
|
16
|
-
"db_cleaning": "Squasher is
|
|
16
|
+
"db_cleaning": "Squasher is applying a clean migration",
|
|
17
17
|
|
|
18
18
|
"usage": "Example usage:\n :green{squasher} :yellow{year[/month][/day]} #squash migrations prior to a specified date\n :green{squasher} :yellow{clean} #generate or update a cleaning migration and apply it\n :green{squasher} :yellow{info} #show this message"
|
|
19
19
|
}
|
data/lib/squasher/version.rb
CHANGED
data/spec/fake_app/db/migrate/{201312090000_first_migration.rb → 20131205160936_first_migration.rb}
RENAMED
|
File without changes
|
data/spec/fake_app/db/migrate/{2013122900_second_migration.rb → 20131213090719_second_migration.rb}
RENAMED
|
File without changes
|
data/spec/fake_app/db/migrate/{20140110_third_migration.rb → 20140103124257_third_migration.rb}
RENAMED
|
File without changes
|
|
@@ -31,10 +31,10 @@ describe Squasher::Worker do
|
|
|
31
31
|
worker = described_class.new(Time.new(2014))
|
|
32
32
|
worker.stub(:under_squash_env).and_yield.and_return(true)
|
|
33
33
|
new_migration_path = File.join(Dir.tmpdir, 'init_schema.rb')
|
|
34
|
-
Squasher::Config.any_instance.stub(:migration_file).with('
|
|
34
|
+
Squasher::Config.any_instance.stub(:migration_file).with('20131213090719', :init_schema).and_return(new_migration_path)
|
|
35
35
|
|
|
36
|
-
FileUtils.should_receive(:rm).with(File.join(fake_root, 'db', 'migrate', '
|
|
37
|
-
FileUtils.should_receive(:rm).with(File.join(fake_root, 'db', 'migrate', '
|
|
36
|
+
FileUtils.should_receive(:rm).with(File.join(fake_root, 'db', 'migrate', '20131205160936_first_migration.rb'))
|
|
37
|
+
FileUtils.should_receive(:rm).with(File.join(fake_root, 'db', 'migrate', '20131213090719_second_migration.rb'))
|
|
38
38
|
Squasher.should_receive(:ask).with(:keep_database).and_return(false)
|
|
39
39
|
Squasher.should_receive(:rake).with("db:drop")
|
|
40
40
|
Squasher.should_receive(:ask).with(:apply_clean).and_return(true)
|
metadata
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: squasher
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergey Pchelincev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- -
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '1.3'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- -
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.3'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rspec
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- -
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '2.14'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- -
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '2.14'
|
|
55
55
|
description: Squash your old migrations
|
|
@@ -60,8 +60,9 @@ executables:
|
|
|
60
60
|
extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
|
62
62
|
files:
|
|
63
|
-
- .gitignore
|
|
64
|
-
- .rspec
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- ".rspec"
|
|
65
|
+
- ".travis.yml"
|
|
65
66
|
- Gemfile
|
|
66
67
|
- LICENSE.txt
|
|
67
68
|
- README.md
|
|
@@ -78,10 +79,10 @@ files:
|
|
|
78
79
|
- lib/squasher/worker.rb
|
|
79
80
|
- spec/fake_app/config/database.yml
|
|
80
81
|
- spec/fake_app/config/invalid_database.yml
|
|
81
|
-
- spec/fake_app/db/migrate/
|
|
82
|
-
- spec/fake_app/db/migrate/
|
|
82
|
+
- spec/fake_app/db/migrate/20131205160936_first_migration.rb
|
|
83
|
+
- spec/fake_app/db/migrate/20131213090719_second_migration.rb
|
|
83
84
|
- spec/fake_app/db/migrate/20140101010101_squasher_clean.rb
|
|
84
|
-
- spec/fake_app/db/migrate/
|
|
85
|
+
- spec/fake_app/db/migrate/20140103124257_third_migration.rb
|
|
85
86
|
- spec/fake_app/db/schema.rb
|
|
86
87
|
- spec/lib/squasher/cleaner_spec.rb
|
|
87
88
|
- spec/lib/squasher/config_spec.rb
|
|
@@ -99,27 +100,27 @@ require_paths:
|
|
|
99
100
|
- lib
|
|
100
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
102
|
requirements:
|
|
102
|
-
- -
|
|
103
|
+
- - ">="
|
|
103
104
|
- !ruby/object:Gem::Version
|
|
104
105
|
version: '0'
|
|
105
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
107
|
requirements:
|
|
107
|
-
- -
|
|
108
|
+
- - ">="
|
|
108
109
|
- !ruby/object:Gem::Version
|
|
109
110
|
version: '0'
|
|
110
111
|
requirements: []
|
|
111
112
|
rubyforge_project:
|
|
112
|
-
rubygems_version: 2.0
|
|
113
|
+
rubygems_version: 2.2.0
|
|
113
114
|
signing_key:
|
|
114
115
|
specification_version: 4
|
|
115
116
|
summary: Squash your old migrations
|
|
116
117
|
test_files:
|
|
117
118
|
- spec/fake_app/config/database.yml
|
|
118
119
|
- spec/fake_app/config/invalid_database.yml
|
|
119
|
-
- spec/fake_app/db/migrate/
|
|
120
|
-
- spec/fake_app/db/migrate/
|
|
120
|
+
- spec/fake_app/db/migrate/20131205160936_first_migration.rb
|
|
121
|
+
- spec/fake_app/db/migrate/20131213090719_second_migration.rb
|
|
121
122
|
- spec/fake_app/db/migrate/20140101010101_squasher_clean.rb
|
|
122
|
-
- spec/fake_app/db/migrate/
|
|
123
|
+
- spec/fake_app/db/migrate/20140103124257_third_migration.rb
|
|
123
124
|
- spec/fake_app/db/schema.rb
|
|
124
125
|
- spec/lib/squasher/cleaner_spec.rb
|
|
125
126
|
- spec/lib/squasher/config_spec.rb
|