migrate_unless 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3152e44cda6e2dec4b02b5e8f2969e52429f6563
4
+ data.tar.gz: 758bc7d82b5abcb93e3c118cc5adb48aaccf2de7
5
+ SHA512:
6
+ metadata.gz: 577cc18ebf3fbb9839012e8ee8c732c01f3c294d6f1a897f79cee12864b33697f6e2ed75333b74e9295bacfc1e1e42cd9caeab4bc69a0626f48af7e936def8d5
7
+ data.tar.gz: d9feee9d391a1d5e2851109174e8c7024677d8e530bf2cc82c2ef8c70da2f22535c0e9c460befb44c7c71ef74482c9ad61f54ac1c6a5404f92b8255ff29bb632
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in migrate_unless.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dave Zoltok
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # MigrateUnless
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'migrate_unless'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install migrate_unless
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/migrate_unless/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ require "migrate_unless/version"
2
+
3
+ module MigrateUnless
4
+ class Railtie < Rails::Railtie
5
+ config.app_generators do |g|
6
+ g.templates.unshift File::expand_path('../templates', __FILE__)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module MigrateUnless
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,40 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ <%- if migration_action == 'add#change doesnt mirror `unless` into `if` when reverting a migration: to be fixed in migrate_unless gem ' -%>
3
+ def change
4
+ <% attributes.each do |attribute| -%>
5
+ unless column_exists? :<%= table_name %>, :<%= attribute.name %>
6
+ add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
7
+ <%- if attribute.has_index? -%>
8
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
9
+ <%- end -%>
10
+ end
11
+ <%- end -%>
12
+ end
13
+ <%- else -%>
14
+ def up
15
+ <% attributes.each do |attribute| -%>
16
+ <%- if migration_action -%>
17
+ <% if migration_action == 'add' -%>unless<%- elsif migration_action == 'remove' -%>if<%- end -%> column_exists? :<%= table_name %>, :<%= attribute.name %>
18
+ <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><%= attribute.inject_options %><% end %>
19
+ <%- if attribute.has_index? && migration_action == 'add' -%>
20
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
21
+ <%- end -%>
22
+ end
23
+ <%- end -%>
24
+ <%- end -%>
25
+ end
26
+
27
+ def down
28
+ <% attributes.reverse.each do |attribute| -%>
29
+ <%- if migration_action -%>
30
+ <% if migration_action == 'add' %>if<% else -%>unless<%- end -%> column_exists? :<%= table_name %>, :<%= attribute.name %>
31
+ <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><%= attribute.inject_options %><%- end %>
32
+ <%- if attribute.has_index? && migration_action == 'remove' -%>
33
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
34
+ <%- end -%>
35
+ end
36
+ <%- end -%>
37
+ <%- end -%>
38
+ end
39
+ <%- end -%>
40
+ end
@@ -0,0 +1,18 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ unless table_exists? :<%= table_name %>
4
+ create_table :<%= table_name %> do |t|
5
+ <% attributes.each do |attribute| -%>
6
+ t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
7
+ <% end -%>
8
+ <% if options[:timestamps] %>
9
+ t.timestamps
10
+ <%- end -%>
11
+ end
12
+ end
13
+ <%- attributes_with_index.each do |attribute| -%>
14
+
15
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
16
+ <% end -%>
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'migrate_unless/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "migrate_unless"
8
+ spec.version = MigrateUnless::VERSION
9
+ spec.authors = ["Dave Zoltok", "François Villeneuve"]
10
+ spec.email = ["dzoltok@thestar.ca", "fvilleneuve@thestar.ca"]
11
+ spec.summary = %q{Checks for existence/non-existence of tables and columns in migration}
12
+ spec.description = %q{Overrides the default migration templates to double-check whether tables and columns exist or not before database changes are made.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 0"
23
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: migrate_unless
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dave Zoltok
8
+ - François Villeneuve
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: Overrides the default migration templates to double-check whether tables
43
+ and columns exist or not before database changes are made.
44
+ email:
45
+ - dzoltok@thestar.ca
46
+ - fvilleneuve@thestar.ca
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/migrate_unless.rb
57
+ - lib/migrate_unless/version.rb
58
+ - lib/templates/active_record/migration/migration.rb
59
+ - lib/templates/active_record/model/migration.rb
60
+ - migrate_unless.gemspec
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Checks for existence/non-existence of tables and columns in migration
85
+ test_files: []