migration_data 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3832601395165ae09ded4ba1609528ae1743142e
4
+ data.tar.gz: 2ad9a69f0b54b83b0aa9f86ea5b91fe80726358a
5
+ SHA512:
6
+ metadata.gz: bbde24c5b3c6a5a998438c41411be08472823725f7e89ddbaa38ba055775d4ef109c76e3ae02f0b545b922926ee3c52794fe9ee0d84ab4b586dd276dfddba93e
7
+ data.tar.gz: 02fe7cd0bf6b53c5327b9206b5432d63520cdb0c37530e0b665ccaa71a2b79ff35810bb96c81c77d2fba8e9c539c0648f9923364199319c5300ea5c39a85a265
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 migration_data.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andrey Koleshko
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,71 @@
1
+ # MigrationData
2
+
3
+ This gem provides functionality to write any code in migrations safely without regression.
4
+
5
+ Sometimes we have to write some Rails code in the migrations and it's hard to
6
+ keep them in working state because models wich are used there changes too often. there
7
+ some techniques which help to avoid these pitfalls. For example, define model
8
+ classes in the migrations or write raw SQL. But they don't help in 100% cases anyway.
9
+ This gem promises to solve the problem in a simple way.
10
+
11
+ Currently the gem supports Rails 4 and Ruby >= 2.0.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'migration_data'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install migration_data
26
+
27
+ ## Usage
28
+
29
+ Just define in your migration `data` method:
30
+
31
+ ```ruby
32
+ class CreateUsers < ActiveRecord::Migration
33
+ def change
34
+ # Database schema changes as usual
35
+ end
36
+
37
+ def data
38
+ User.create!(name: 'Andrey', email: 'ka8725@gmail.com')
39
+ end
40
+ end
41
+ ```
42
+
43
+ That's it. Now when you run migrations with the `rake db:migrate` command the `data` method will be run on `up`.
44
+
45
+ NOTE: it's not run on `down`. If you have any reason to do it please fell free to make pull request.
46
+
47
+ ## Testing migrations
48
+
49
+ To keep your migrations working don't forget to write test foe them.
50
+ Possible `RSpec` test for the migration looks like this:
51
+
52
+ ```ruby
53
+ require 'spec_helper'
54
+ require Rails.root.join(ActiveRecord::Migrator.migrations_paths).join('20130906111511_create_users.rb')
55
+
56
+ desribe CreateUsers do
57
+ describe '#data' do
58
+ it 'works' do
59
+ expect { CreateUsers.new.data }.to_not raise_exception
60
+ end
61
+ end
62
+ end
63
+ ```
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it ( http://github.com/ka8725/migration_data/fork )
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+
3
+
4
+ require 'rake/testtask'
5
+
6
+ desc 'Default: run unit tests.'
7
+ task default: :test
8
+
9
+ desc 'Test the migration_data plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
@@ -0,0 +1,12 @@
1
+ require 'migration_data/version'
2
+
3
+ module MigrationData
4
+ def exec_migration(conn, direction)
5
+ super
6
+ if direction == :up && respond_to?(:data)
7
+ data
8
+ end
9
+ end
10
+ end
11
+
12
+ ActiveRecord::Migration.prepend(MigrationData)
@@ -0,0 +1,3 @@
1
+ module MigrationData
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'migration_data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "migration_data"
8
+ spec.version = MigrationData::VERSION
9
+ spec.authors = ["Andrey Koleshko"]
10
+ spec.email = ["ka8725@gmail.com"]
11
+ spec.summary = %q{Provides possibility to write any code in migrations safely without regression.}
12
+ spec.description = %q{Sometimes we have to write some Rails code in the migrations and it's hard to
13
+ keep them in working state because models wich are used there changes too often. there
14
+ some techniques which help to avoid these pitfalls. For example, define model
15
+ classes in the migrations or write raw SQL. But they don't help in 100% cases anyway.
16
+ This gem promises to solve the problem in a simple way.}
17
+ spec.homepage = ""
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files`.split($/)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.5'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'sqlite3'
28
+ spec.add_dependency 'activerecord', '~> 4.0'
29
+ end
@@ -0,0 +1,31 @@
1
+ require 'minitest/autorun'
2
+ require 'active_record'
3
+ require 'migration_data'
4
+
5
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'tmp/test.sqlite3')
6
+
7
+ class MyMigration < ActiveRecord::Migration
8
+ attr_reader :migrated_data
9
+
10
+ def data
11
+ @migrated_data = true
12
+ end
13
+ end
14
+
15
+ describe MyMigration do
16
+ before do
17
+ @migration = MyMigration.new
18
+ end
19
+
20
+ describe '#migrate' do
21
+ it 'runs #data on up direction' do
22
+ @migration.migrate(:up)
23
+ assert @migration.migrated_data
24
+ end
25
+
26
+ it "doesn't run #data on down direction" do
27
+ @migration.migrate(:down)
28
+ assert_nil @migration.migrated_data
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: migration_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Koleshko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ description: |-
70
+ Sometimes we have to write some Rails code in the migrations and it's hard to
71
+ keep them in working state because models wich are used there changes too often. there
72
+ some techniques which help to avoid these pitfalls. For example, define model
73
+ classes in the migrations or write raw SQL. But they don't help in 100% cases anyway.
74
+ This gem promises to solve the problem in a simple way.
75
+ email:
76
+ - ka8725@gmail.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - lib/migration_data.rb
87
+ - lib/migration_data/version.rb
88
+ - migration_data.gemspec
89
+ - test/migration_test.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.0
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Provides possibility to write any code in migrations safely without regression.
114
+ test_files:
115
+ - test/migration_test.rb
116
+ has_rdoc: