screamers 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/rails/generators/screamers/migration/migration_generator.rb +6 -5
- data/lib/screamers.rb +1 -1
- data/lib/screamers/{schema_collector.rb → column_collector.rb} +8 -6
- data/lib/screamers/version.rb +1 -1
- metadata +3 -4
- data/lib/screamers/railtie.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c758d59eefca8fe53f74f8b767551ab74ca28b22
|
4
|
+
data.tar.gz: 4a75e01840b39476caacb21759d49f9ae40ce3a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e355ca06f9e67107698f923f9df8e15d0e104aa0486ecca68f7cee6a0ff2691191ddb9e8defbfaaa71dad336d6e5f2ef41313c5fe1ff11133890ae2330792949
|
7
|
+
data.tar.gz: 9f3d9477e34c444e91c2488a688423313384b0f7c3ac4d570e947d7b0f9eb16d90f450367582660fa6be55d3671e13e8f82bb26c96aef88df7aa41fdbb34c23b
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Screamers [![Build Status](https://travis-ci.org/koic/screamers.svg)](https://travis-ci.org/koic/screamers)
|
1
|
+
# Screamers [![Build Status](https://travis-ci.org/koic/screamers.svg)](https://travis-ci.org/koic/screamers) [![Gem Version](https://badge.fury.io/rb/screamers.svg)](http://badge.fury.io/rb/screamers)
|
2
2
|
|
3
3
|
Generate a migration file that converts column types all at once.
|
4
4
|
|
@@ -26,7 +26,7 @@ Screamers:
|
|
26
26
|
## Synopsis
|
27
27
|
|
28
28
|
```console
|
29
|
-
bin/rails g screamers:migration
|
29
|
+
bin/rails g screamers:migration OLD_COLUMN_TYPE NEW_COLUMN_TYPE
|
30
30
|
```
|
31
31
|
|
32
32
|
## Usage
|
@@ -6,25 +6,26 @@ module Screamers
|
|
6
6
|
module Generators
|
7
7
|
class MigrationGenerator < ::Rails::Generators::Base
|
8
8
|
desc 'Creates a migration file made [Screamers Task]'
|
9
|
-
argument :old_column_type, type: :string, banner: '
|
10
|
-
argument :new_column_type, type: :string, banner: '
|
9
|
+
argument :old_column_type, type: :string, banner: 'OLD_COLUMN_TYPE'
|
10
|
+
argument :new_column_type, type: :string, banner: 'NEW_COLUMN_TYPE'
|
11
11
|
|
12
12
|
def self.source_root
|
13
13
|
File.expand_path('../templates', __FILE__)
|
14
14
|
end
|
15
15
|
|
16
16
|
def create_migration_file
|
17
|
-
collector = Screamers::
|
17
|
+
collector = Screamers::ColumnCollector.new(old_column_type, new_column_type)
|
18
18
|
|
19
|
-
@target_columns = collector.
|
19
|
+
@target_columns = collector.collect_columns
|
20
20
|
|
21
21
|
if @target_columns.empty?
|
22
22
|
puts '[Screamers] There is no change in the schema.'; exit!
|
23
23
|
end
|
24
24
|
|
25
|
+
migrations_path = ActiveRecord::Migrator.migrations_paths.first
|
25
26
|
file_name = "#{Time.current.strftime('%Y%m%d%H%M%S')}_change_#{old_column_type}_to_#{new_column_type}_using_screamers"
|
26
27
|
|
27
|
-
template 'migration.rb.tt', File.join(
|
28
|
+
template 'migration.rb.tt', File.join(migrations_path, "#{file_name}.rb")
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
data/lib/screamers.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
# frozen-string-literal: true
|
2
2
|
|
3
3
|
module Screamers
|
4
|
-
class
|
4
|
+
class ColumnCollector
|
5
5
|
def initialize(old_column_type, new_column_type)
|
6
6
|
@old_column_type = old_column_type.to_sym
|
7
7
|
@new_column_type = new_column_type.to_sym
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def collect_schema
|
10
|
+
def collect_columns
|
13
11
|
tables = ActiveRecord::Base.connection.tables
|
14
|
-
tables.delete('ar_internal_metadata')
|
15
12
|
|
16
13
|
@target_tables = tables.each_with_object({}) {|table, target|
|
17
|
-
|
14
|
+
begin
|
15
|
+
columns = Module.const_get(table.classify).columns
|
16
|
+
rescue
|
17
|
+
puts "An ActiveRecord model mapped to `#{table}` foo could not be found. Please check if you need handmade by yourself."
|
18
|
+
next
|
19
|
+
end
|
18
20
|
|
19
21
|
target_columns = columns.select {|column|
|
20
22
|
column.type == @old_column_type
|
data/lib/screamers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: screamers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koichi ITO
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -127,8 +127,7 @@ files:
|
|
127
127
|
- lib/rails/generators/screamers/migration/migration_generator.rb
|
128
128
|
- lib/rails/generators/screamers/migration/templates/migration.rb.tt
|
129
129
|
- lib/screamers.rb
|
130
|
-
- lib/screamers/
|
131
|
-
- lib/screamers/schema_collector.rb
|
130
|
+
- lib/screamers/column_collector.rb
|
132
131
|
- lib/screamers/version.rb
|
133
132
|
- screamers.gemspec
|
134
133
|
homepage: https://github.com/koic/screamers
|