squasher 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03bf510487b316ab7771766ef9605f8a8269bfed
4
- data.tar.gz: e01e6ba2390d5dabcc0a7fd24d7cbafb4c0f4549
3
+ metadata.gz: 8775b118d632b6d115055e0f8fcef4cfa9f0908c
4
+ data.tar.gz: c78d28c7863de87b9336487ebf6c60f9e7c5abab
5
5
  SHA512:
6
- metadata.gz: 399e73be169b440d181fd4ab2283bb11fd75226e5a8d3b3ecba6b4c4b1b3808b7908c993f5a5ec44d5e258920a70c568db8773823bff7aef49fe7979f250167c
7
- data.tar.gz: 092b138e42c74d278a97247e1fbf679ea5c2bba65e0379aaa1ac555205d2e9ac4937a53608f010764f47be788fbbff895acb1656e0b358822728d7d59ac827fa
6
+ metadata.gz: 4b6e4ca16a710cbc554f026c572cb18fdec3bbd605ca00bd288d15fa54cff6f4a32d6a7afba09f3209c1ba68a28cb60346c9ee1e5212d3f1a2b0afc6dd7620c0
7
+ data.tar.gz: 65f5605caa98b23b43796e6ccfeb0b4468b2830c6001923624ff9720f13e62622dfd8f9efd52191d856b681464dc280e14b1cf4eb2e650d967fc2f60cdfcbc6c
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby-19mode
7
+ - rbx
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in squasher.gemspec
4
4
  gemspec
5
+
6
+ platforms :rbx do
7
+ gem 'json'
8
+ gem 'racc'
9
+ gem 'rubysl', '~> 2.0'
10
+ gem 'psych'
11
+ end
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Squasher
2
2
 
3
- Squasher is a compressor of the old migrations in rails application. If you works on big project with lots of migrations
4
- every `rake db:migrate` takes a few seconds, creating of a new database might takes a few minutes. It's just because rails load
5
- all this files. Squasher instead remove all this migrations and create one single migration with a final state of a database.
3
+ [![Build Status](https://travis-ci.org/jalkoby/squasher.png?branch=master)](https://travis-ci.org/jalkoby/squasher)
4
+ [![Code Climate](https://codeclimate.com/github/jalkoby/squasher.png)](https://codeclimate.com/github/jalkoby/squasher)
5
+ [![Gem Version](https://badge.fury.io/rb/squasher.png)](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
- Once you install gem you will get `squasher` command.
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 2014 year
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.2+. Also it requires a valid configuration in `config/database.yml` and using Ruby format in `db/schema.rb`(default rails usecase).
29
- If some migration insert data(create a ActiveRecord model records) you will lost this code in a new created migration, but `squasher` will ask you to leave tmp database which will have all inserted information. Using this database you could again add this inserting into a new migration or create/update `config/seed.rb` file(expected place for this stuff).
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
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ desc "Run all specs"
7
+ task :default => :spec
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
- options.each { |key, value| message.gsub!(":#{ key }", value) }
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+)\{([^}]+)\}/) do |match|
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
@@ -1,19 +1,19 @@
1
1
  {
2
- "keep_database" : "Squasher created `:green{squasher}` database for it needs.\nIt might be useful if some deleted migration insert data into a database.\nLeft it(:green{yes} / :red{no})?",
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 from an old schema migrations records(:red{yes}/:green{no})?",
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{root of a rails} application?",
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{:date}",
8
+ "no_migrations" : "There are no migrations in the folder prior to :red<%{date}>",
9
9
 
10
- "dbconfig_invalid" : "Squasher could not find `:green{database.yml}` with working development environment",
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 appling a migrations on a tmp database",
14
+ "db_migrate": "Squasher is applying migrations on a tmp database",
15
15
 
16
- "db_cleaning": "Squasher is appling a clean migration",
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
  }
@@ -1,3 +1,3 @@
1
1
  module Squasher
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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('2013122900', :init_schema).and_return(new_migration_path)
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', '201312090000_first_migration.rb'))
37
- FileUtils.should_receive(:rm).with(File.join(fake_root, 'db', 'migrate', '2013122900_second_migration.rb'))
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.0
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-01-20 00:00:00.000000000 Z
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/201312090000_first_migration.rb
82
- - spec/fake_app/db/migrate/2013122900_second_migration.rb
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/20140110_third_migration.rb
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.14
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/201312090000_first_migration.rb
120
- - spec/fake_app/db/migrate/2013122900_second_migration.rb
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/20140110_third_migration.rb
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