squasher 0.6.1 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 58e6842c01fedd8c3d14952de14c3cdfe58dcbeb
4
- data.tar.gz: c2ec95df798554cc3af0d238ffd5178cf980e789
2
+ SHA256:
3
+ metadata.gz: b1881315f750432477c45c63915b6118af4f165ba9c00fcf2b253d34d14bf49d
4
+ data.tar.gz: 22a3270dafb3aafae0b4eabe0720cb069a2aef9718f30150953295bdcd36084b
5
5
  SHA512:
6
- metadata.gz: 63bd6a06a4b0e3c241d097ce3b96d84d908f3d0ee5ca84aaa8a06139b6b81864b4bb167f8aca9a8134707da98e9bb6ee8cc27d8c8b30be9225192764ae38fb78
7
- data.tar.gz: b398fc389ccb9b873e11f75ce94512ae7678c1d94ac47d2bae63ae0415e3d2b3075403eee9cafcb987757d2669f83c95677aeef9278d242e68c6bc4aafd0da4e
6
+ metadata.gz: 54a095db328fdbf39dac24d7d509271a14e7765d313b36fccdfefc43d6a20d5eb36659884ed90b6fec0fcc901f10182c8ded4bb33bcc37835674107e28a81a93
7
+ data.tar.gz: 722b7b612648974304e842405b980f628d2939aa8816d918fda4bc0c2ea27209e9ed5dab769d909bbfcc9f825cdae276527c9db90593a33bc742715daca57229
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ - 0.7.0
2
+ - Support the presence of multiverse ([@mlohbihler](https://github.com/mlohbihler))
1
3
  - 0.6.1
2
4
  - Escape regexp in sql mode ([@mpospelov](https://github.com/mpospelov))
3
5
  - 0.6.0
data/README.md CHANGED
@@ -6,6 +6,9 @@
6
6
 
7
7
  Squasher compresses old ActiveRecord migrations. 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 ActiveRecord loads all those migration files. Squasher removes all the migrations and creates a single migration with the final database state of the specified date (the new migration will look like a schema).
8
8
 
9
+ ## Attention
10
+ Prior to 0.6.2 squasher could damage your real data as generate "force" tables. Please upgrade to 0.6.2+ & manually clean "force" tag from the init migration
11
+
9
12
  ## Installation
10
13
 
11
14
  You don't have to add it into your Gemfile. Just a standalone installation:
data/bin/squasher CHANGED
@@ -32,6 +32,10 @@ parser = OptionParser.new do |config|
32
32
  options[:engine] = value
33
33
  end
34
34
 
35
+ config.on('--databases=DB_KEY,...', 'alternate database configuration keys to be included dbconfig (for multiverse)') do |value|
36
+ options[:databases] = value&.split(",")
37
+ end
38
+
35
39
  config.on('-v', '--version', '-h', '--help', 'show this message')
36
40
  end
37
41
  parser.parse!
@@ -36,7 +36,7 @@ module Squasher
36
36
  end
37
37
 
38
38
  def now_timestamp
39
- Time.now.strftime("%Y%m%d%H%M%S")
39
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
40
40
  end
41
41
  end
42
42
  end
@@ -39,6 +39,7 @@ module Squasher
39
39
  @root_path = Dir.pwd.freeze
40
40
  @migrations_folder = File.join(@root_path, 'db', 'migrate')
41
41
  @flags = []
42
+ @databases = []
42
43
  set_app_path(@root_path)
43
44
  end
44
45
 
@@ -60,6 +61,8 @@ module Squasher
60
61
  elsif key == :sql
61
62
  @schema_file = File.join(@app_path, 'db', 'structure.sql')
62
63
  @flags << key
64
+ elsif key == :databases
65
+ @databases = value
63
66
  else
64
67
  @flags << key
65
68
  end
@@ -123,6 +126,7 @@ module Squasher
123
126
  content, soft_error = Render.process(dbconfig_file)
124
127
  if content.has_key?('development')
125
128
  @dbconfig = { 'development' => content['development'].merge('database' => 'squasher') }
129
+ @databases&.each { |database| @dbconfig[database] = content[database] }
126
130
  end
127
131
  rescue
128
132
  end
@@ -49,13 +49,17 @@ module Squasher
49
49
  def stream_schema(stream)
50
50
  inside_schema = false
51
51
 
52
- stream.each_line do |line|
52
+ stream.each_line do |raw_line|
53
53
  if inside_schema
54
54
  # reach the end of schema
55
- break if line.index("end") == 0
56
- yield line.gsub(/\A\s{,2}(.*)\s+\z/, '\1')
55
+ break if raw_line.index("end") == 0
56
+ line = raw_line.gsub(/\A\s{,2}(.*)\s+\z/, '\1')
57
+ if line.include?('create_table')
58
+ line.gsub!(/(create_table.*),.* do/, '\1 do')
59
+ end
60
+ yield line
57
61
  else
58
- inside_schema = true if line.include?("ActiveRecord::Schema")
62
+ inside_schema = true if raw_line.include?("ActiveRecord::Schema")
59
63
  end
60
64
  end
61
65
  end
@@ -1,3 +1,3 @@
1
1
  module Squasher
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/squasher.rb CHANGED
@@ -46,7 +46,7 @@ module Squasher
46
46
  end
47
47
 
48
48
  def print(message, options = {})
49
- puts message % options
49
+ puts options.empty? ? message : message % options
50
50
  end
51
51
 
52
52
  def error(*args)
@@ -16,3 +16,7 @@ another_test:
16
16
  database: another_test
17
17
  user: root
18
18
  password: password
19
+ multiverse-database:
20
+ database: multiverse-database
21
+ user: multiverse-user
22
+ password: multiverse-password
@@ -5,7 +5,7 @@ describe Squasher::Cleaner do
5
5
  let(:expected_file) { File.join(fake_root, 'db', 'migrate', '20140102030405_squasher_clean.rb') }
6
6
 
7
7
  before do
8
- allow(Time).to receive(:now).and_return(Time.new(2014, 1, 2, 3, 4, 5))
8
+ allow(Time).to receive(:now).and_return(Time.utc(2014, 1, 2, 3, 4, 5))
9
9
  allow(Squasher).to receive(:rake).with("db:migrate", :db_cleaning)
10
10
  end
11
11
 
@@ -49,6 +49,20 @@ describe Squasher::Config do
49
49
  end
50
50
  end
51
51
 
52
+ it 'includes other database definitions provided in the command line' do
53
+ config.set(:databases, ["multiverse-database"])
54
+ config.stub_dbconfig do
55
+ File.open(File.join(fake_root, 'config', 'database.yml')) do |stream|
56
+ content = YAML.load(stream.read)
57
+ expect(content["development"]["database"]).to eq("squasher")
58
+ expect(content["development"]["encoding"]).to eq("utf-8")
59
+ expect(content["multiverse-database"]["database"]).to eq("multiverse-database")
60
+ expect(content["multiverse-database"]["user"]).to eq("multiverse-user")
61
+ expect(content).not_to have_key("another_development")
62
+ end
63
+ end
64
+ end
65
+
52
66
  def file_exists?(*parts)
53
67
  File.exists?(File.join(fake_root, *parts))
54
68
  end
@@ -46,4 +46,12 @@ describe Squasher do
46
46
  Squasher.rake('db:migrate')
47
47
  end
48
48
  end
49
+
50
+ context '.print' do
51
+ context 'when options are empty' do
52
+ it 'prints the message without error' do
53
+ Squasher.print('asdf % asdf', {})
54
+ end
55
+ end
56
+ end
49
57
  end
@@ -46,7 +46,7 @@ describe Squasher::Worker do
46
46
  File.open(new_migration_path) do |stream|
47
47
  content = stream.read
48
48
  expect(content).to include("InitSchema")
49
- expect(content).to include('create_table "managers", :force => true do |t|')
49
+ expect(content).to include('create_table "managers" do |t|')
50
50
  end
51
51
  end
52
52
 
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.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pchelintsev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-27 00:00:00.000000000 Z
11
+ date: 2022-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ homepage: https://github.com/jalkoby/squasher
96
96
  licenses:
97
97
  - MIT
98
98
  metadata: {}
99
- post_install_message:
99
+ post_install_message:
100
100
  rdoc_options: []
101
101
  require_paths:
102
102
  - lib
@@ -111,9 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubyforge_project:
115
- rubygems_version: 2.6.13
116
- signing_key:
114
+ rubygems_version: 3.2.32
115
+ signing_key:
117
116
  specification_version: 4
118
117
  summary: Squash your old migrations
119
118
  test_files: