unschema 0.1.0 → 0.2.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
2
  SHA1:
3
- metadata.gz: 2686bd6b60b612e83c1fe9cb918cdf590b9dcfe2
4
- data.tar.gz: 62b58128cf9cf22570d5d9b3ed06b06577289cf7
3
+ metadata.gz: 6079ec9ea6b09cea0e74b39fc2262f5264e61756
4
+ data.tar.gz: 0a6eea8e41166d81329df0ec90357af672610501
5
5
  SHA512:
6
- metadata.gz: ce6fa5ae2759ba765ca70bc7d215581031bb7db0177ce7bb29266dc17251923d42c3f2e1f9f434be844bf2a24fcab2dd5cede14f0bf7a594ffb4e231e93c60b9
7
- data.tar.gz: b23aeb38e84fe1681ad5cc533ede0e7a4154b30632a4f89a8480f295f6402b901aaa36011d5fccd751002f739918275c91afe6b56486d8654c2befeaa8211b76
6
+ metadata.gz: 130a249227fabfbf050c564baba11e2bdc9038e07c0af09490dc2649ddce5f2fbd8b2044a709a2d9a9c398ac8a3704e3090e331ab5765fb6fe848d77ad437ade
7
+ data.tar.gz: 1628153b476be4385b55ec9d5f8c91e3743bceb17ccf344be3cfd05f91f2365a5ba7630c2498c2dc7ae7e8fc9739b5ff4eecd5f60e08b1d4b3245edaec7b948a
@@ -1,24 +1,18 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
+ after_success:
5
+ - '[ "${TRAVIS_JOB_NUMBER#*.}" = "1" ] && bundle exec codeclimate-test-reporter'
4
6
  rvm:
5
7
  - ruby-head
8
+ - 2.4.3
9
+ - 2.3.6
6
10
  - 2.2
7
11
  - 2.1
8
- - 2.0
9
- - 1.9.3
10
12
  env:
11
13
  global:
12
14
  - CODECLIMATE_REPO_TOKEN=5149a81a58ceefa61850827c29b5fecc303d15c038b7ad4fb12e8279d2be47ab
13
15
  matrix:
14
16
  fast_finish: true
15
17
  allow_failures:
16
- - ruby-head
17
-
18
- notifications:
19
- webhooks:
20
- urls:
21
- - https://webhooks.gitter.im/e/d347d6c0296c3caf01ad
22
- on_success: change # options: [always|never|change] default: always
23
- on_failure: always # options: [always|never|change] default: always
24
- on_start: false # default: false
18
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in unschema.gemspec
4
4
  gemspec
5
5
 
6
- if ENV['CODECLIMATE_REPO_TOKEN']
7
- gem "codeclimate-test-reporter", :group => :test, :require => nil
6
+ group :test do
7
+ gem 'simplecov'
8
+ gem 'codeclimate-test-reporter', '~> 1.0.0'
8
9
  end
data/README.md CHANGED
@@ -27,7 +27,7 @@ We use it to cleanup older projects, that gets reused as codebase for new projec
27
27
 
28
28
  Add this line to your application's Gemfile:
29
29
 
30
- gem 'unschema'
30
+ gem 'unschema', '~> 0.2.0'
31
31
 
32
32
  And then execute:
33
33
 
@@ -39,7 +39,7 @@ Or install it yourself as:
39
39
 
40
40
  ## Usage
41
41
 
42
- usage: unschema [SCHEMA_FILE] [MIGRATIONS_DIR]
42
+ usage: unschema [SCHEMA_FILE] [MIGRATIONS_DIR] [RAILS_VERSION]
43
43
 
44
44
  ## TODO
45
45
 
@@ -53,3 +53,15 @@ Or install it yourself as:
53
53
  3. Commit your changes (`git commit -am 'Add some feature'`)
54
54
  4. Push to the branch (`git push origin my-new-feature`)
55
55
  5. Create new Pull Request
56
+
57
+ ## Release
58
+
59
+ Follow these steps to release this gem:
60
+
61
+ # Bump version in
62
+ edit lib/unschema/version.rb
63
+ edit README.md
64
+
65
+ git commit -m "Release X.Y.Z"
66
+
67
+ rake release
@@ -7,12 +7,13 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
7
7
 
8
8
  require 'unschema'
9
9
 
10
- if ARGV.size != 2
11
- puts "usage: unschema [SCHEMA_FILE] [MIGRATIONS_DIR]"
10
+ if ARGV.size != 3
11
+ puts "usage: unschema [SCHEMA_FILE] [MIGRATIONS_DIR] [RAILS_VERSION]"
12
12
  exit 1
13
13
  end
14
14
  schema_file = ARGV[0]
15
15
  migrations_path = ARGV[1]
16
+ rails_version = ARGV[2]
16
17
 
17
18
  puts "Processing #{schema_file.inspect}"
18
- Unschema::Base.process!(schema_file, migrations_path, true)
19
+ Unschema::Base.process!(schema_file, migrations_path, true, rails_version)
@@ -1,5 +1,5 @@
1
1
  module Unschema
2
- class Base < Struct.new(:schema_file, :migrations_path, :verbose)
2
+ class Base < Struct.new(:schema_file, :migrations_path, :verbose, :rails_version)
3
3
  def self.process!(*args)
4
4
  new(*args).process
5
5
  end
@@ -51,7 +51,7 @@ module Unschema
51
51
  def dump_table_calls(table_name, calls)
52
52
  file = File.join(migrations_path, "#{next_migration}_create_#{table_name}.rb")
53
53
  File.open(file, "w") do |f|
54
- MigrationDumper.new(table_name, calls).dump_to(f)
54
+ MigrationDumper.new(table_name, calls, rails_version: rails_version).dump_to(f)
55
55
  end
56
56
  end
57
57
 
@@ -1,12 +1,13 @@
1
1
  module Unschema
2
2
  class MigrationDumper
3
- def initialize(table_name, calls)
3
+ def initialize(table_name, calls, rails_version:)
4
4
  @table_name = table_name
5
- @calls = calls
5
+ @calls = calls
6
+ @rails_version = rails_version
6
7
  end
7
8
 
8
9
  def dump_to(f)
9
- f << "class Create#{table_name_camelcased} < ActiveRecord::Migration\n"
10
+ f << "class Create#{table_name_camelcased} < ActiveRecord::Migration[#{@rails_version}]\n"
10
11
  f << " def change\n"
11
12
 
12
13
  @calls.each do |call|
@@ -38,17 +39,17 @@ module Unschema
38
39
  end
39
40
 
40
41
  def table_name_camelcased
41
- @table_name.gsub(/^(\w)/){|s| s.upcase }.gsub(/(_\w)/) { |s| s[-1, 1].upcase }
42
+ @table_name.gsub(/^(\w)/) { |s| s.upcase }.gsub(/(_\w)/) { |s| s[-1, 1].upcase }
42
43
  end
43
44
 
44
45
  def stringify_call(call)
45
- args = stringify_args(call.args)
46
+ args = stringify_args(call.args)
46
47
  options = stringify_options(call.options) unless call.options.empty?
47
- [ args, options ].compact.join(", ")
48
+ [args, options].compact.join(", ")
48
49
  end
49
50
 
50
51
  def stringify_args(args)
51
- args.inspect.gsub(/^\[|\]$/,"")
52
+ args.inspect.gsub(/^\[|\]$/, "")
52
53
  end
53
54
 
54
55
  def stringify_options(options)
@@ -1,3 +1,3 @@
1
1
  module Unschema
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,13 +1,11 @@
1
- if ENV['CODECLIMATE_REPO_TOKEN']
2
- require "codeclimate-test-reporter"
3
- CodeClimate::TestReporter.start
4
- end
1
+ require 'simplecov'
2
+ SimpleCov.start
5
3
 
6
4
  require 'minitest/autorun'
7
5
 
8
6
  require 'unschema'
9
7
 
10
- class TestCase < Minitest::Test
8
+ class TestCase < Minitest::Test
11
9
  def assert_string(actual, expect)
12
10
  assert_equal expect.unindent, actual.unindent
13
11
  end
@@ -8,12 +8,13 @@ class EndToEndTest < TestCase
8
8
  end
9
9
 
10
10
  def test_schema_to_migrations
11
- Unschema::Base.process!(schema_file, migrations_path.to_s)
11
+ rails_version = "5.1"
12
+ Unschema::Base.process!(schema_file, migrations_path.to_s, true, rails_version)
12
13
 
13
- assert_equal ["20130222131356_create_abc.rb", "20130222131357_create_table1.rb", "20130222131358_create_the_table2.rb"], Dir[migrations_path.join "*.rb"].map{|path| File.basename(path)}.sort
14
+ assert_equal ["20130222131356_create_abc.rb", "20130222131357_create_table1.rb", "20130222131358_create_the_table2.rb"], Dir[migrations_path.join "*.rb"].map { |path| File.basename(path) }.sort
14
15
 
15
16
  assert_migration "20130222131356_create_abc.rb", <<-MIGRATION
16
- class CreateAbc < ActiveRecord::Migration
17
+ class CreateAbc < ActiveRecord::Migration[#{rails_version}]
17
18
  def change
18
19
  create_table "abc" do |t|
19
20
  t.string "defgh"
@@ -23,7 +24,7 @@ class EndToEndTest < TestCase
23
24
  MIGRATION
24
25
 
25
26
  assert_migration "20130222131357_create_table1.rb", <<-MIGRATION
26
- class CreateTable1 < ActiveRecord::Migration
27
+ class CreateTable1 < ActiveRecord::Migration[#{rails_version}]
27
28
  def change
28
29
  create_table "table1", :force => true do |t|
29
30
  t.string "str"
@@ -38,7 +39,7 @@ class EndToEndTest < TestCase
38
39
  MIGRATION
39
40
 
40
41
  assert_migration "20130222131358_create_the_table2.rb", <<-MIGRATION
41
- class CreateTheTable2 < ActiveRecord::Migration
42
+ class CreateTheTable2 < ActiveRecord::Migration[#{rails_version}]
42
43
  def change
43
44
  create_table "the_table2", :force => true do |t|
44
45
  t.date "date"
@@ -3,18 +3,20 @@ require 'helper'
3
3
 
4
4
  class MigrationDumperTest < TestCase
5
5
  def test_without_calls
6
- create_dumper
6
+ create_dumper(rails_version: "5.1")
7
7
 
8
- assert_change <<-STR
8
+ inner = <<-STR
9
9
  STR
10
+ assert_change inner, rails_version: "5.1"
10
11
  end
11
12
 
12
13
  def test_create_table_call
13
14
  create_dumper \
14
15
  create_call(:create_table, "table", :force => true) { |t|
15
- t.string "uid", :limit => 32, :unique => true
16
+ t.string "uid", :limit => 32, :unique => true
16
17
  t.integer "amount"
17
- }
18
+ },
19
+ rails_version: "5.1"
18
20
 
19
21
  assert_change <<-STR
20
22
  create_table "table", :force => true do |t|
@@ -27,7 +29,8 @@ class MigrationDumperTest < TestCase
27
29
  def test_index_call
28
30
  create_dumper \
29
31
  create_call(:add_index, "table", "uid", :unique => true),
30
- create_call(:add_index, "table", %w[composite index])
32
+ create_call(:add_index, "table", %w[composite index]),
33
+ rails_version: "5.1"
31
34
 
32
35
  assert_change <<-STR
33
36
  add_index "table", "uid", :unique => true
@@ -37,17 +40,17 @@ class MigrationDumperTest < TestCase
37
40
 
38
41
  private
39
42
 
40
- def create_dumper(*calls)
41
- @dumper = Unschema::MigrationDumper.new("foo_bar", calls)
43
+ def create_dumper(*calls, rails_version:)
44
+ @dumper = Unschema::MigrationDumper.new("foo_bar", calls, rails_version: rails_version)
42
45
  end
43
46
 
44
47
  def create_call(name, *args, &block)
45
48
  Unschema::SchemaIntermediator::Call.new(name, *args, &block)
46
49
  end
47
50
 
48
- def assert_change(inner)
51
+ def assert_change(inner, rails_version: "5.1")
49
52
  expect = <<-STR
50
- class CreateFooBar < ActiveRecord::Migration
53
+ class CreateFooBar < ActiveRecord::Migration[#{rails_version}]
51
54
  def change
52
55
  STR
53
56
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unschema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Holderbaum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-19 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.2.2
89
+ rubygems_version: 2.6.13
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Splits your current schema.rb into per-table migrations