activerecord-always_reset_column_information 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +88 -0
- data/Rakefile +6 -0
- data/activerecord-always_reset_column_information.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/activerecord/always_reset_column_information.rb +6 -0
- data/lib/activerecord/always_reset_column_information/migration.rb +6 -0
- data/lib/activerecord/always_reset_column_information/version.rb +5 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 80656652e82c82dede134918203e656a648e49f6e4f55a50b0e380d6b5ea1e95
|
4
|
+
data.tar.gz: 4387acbbb14e889501ff010d39b6a56ad0fb1ed513a1aac624e7ee8e201d9b58
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18ce61749334efdfc1e8df31e0b2afa0b185192ee0885f2f77854fb8e204695299fe2f90d38f27a16dd0474a42727aba97a2914a261f92e9800e0282d2842a45
|
7
|
+
data.tar.gz: e666b766750c4a146e705ea452943f80d94894ccf1ea6b7022d0944e39b769dfe64c36a3b02402d0176081e11302587eac1976a4f860958c7a380c6e7bb2b9f3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Takafumi ONAKA
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Activerecord::AlwaysResetColumnInformation
|
2
|
+
|
3
|
+
## What's this
|
4
|
+
|
5
|
+
Call `Model.reset_column_information` for each migrations.
|
6
|
+
|
7
|
+
## Why `reset_column_information` is needed?
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# 001_create_users.rb
|
11
|
+
class CreateUsers < ActiveRecord::Migration[5.1]
|
12
|
+
def up
|
13
|
+
create_table :users do |t|
|
14
|
+
t.string :name
|
15
|
+
end
|
16
|
+
p User.first # 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# 002_add_age_to_users.rb
|
21
|
+
class AddAgeToUsers < ActiveRecord::Migration[5.1]
|
22
|
+
def up
|
23
|
+
add_column :users, :age, :integer # 2
|
24
|
+
User.create(name: "Taro", age: 16) # 3
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
1 Touch `User` model and columns are chaced.
|
30
|
+
2 Add column to `users` table. but `User`'s column cache is still keeping.
|
31
|
+
3 Create user with new column but raise `ActiveModel::UnknownAttributeError: unknown attribute 'age' for User.`
|
32
|
+
|
33
|
+
You can change `002_add_age_to_users.rb` to ensure that creating user.
|
34
|
+
|
35
|
+
```diff
|
36
|
+
class AddAgeToUsers < ActiveRecord::Migration[5.1]
|
37
|
+
def up
|
38
|
+
add_column :users, :age, :integer
|
39
|
+
+ User.reset_column_information
|
40
|
+
User.create(name: "Taro", age: 16)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
But `Reset after touch` in `001_create_users.rb` is better approach.
|
46
|
+
|
47
|
+
```diff
|
48
|
+
class CreateUsers < ActiveRecord::Migration[5.1]
|
49
|
+
def up
|
50
|
+
create_table :users do |t|
|
51
|
+
t.string :name
|
52
|
+
end
|
53
|
+
p User.first
|
54
|
+
+ User.reset_column_information
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
## What does this gem do?
|
61
|
+
|
62
|
+
Reset all models for each migrations.
|
63
|
+
|
64
|
+
Implementation is only this.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
module Activerecord::AlwaysResetColumnInformation::Migration
|
68
|
+
def exec_migration(conn, direction)
|
69
|
+
super
|
70
|
+
ActiveRecord::Base.descendants.each(&:reset_column_information)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
ActiveRecord::Migration.prepend Activerecord::AlwaysResetColumnInformation::Migration
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
## Usage
|
79
|
+
|
80
|
+
Add this line to your application's Gemfile:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
gem "activerecord-always_reset_column_information"
|
84
|
+
```
|
85
|
+
|
86
|
+
## License
|
87
|
+
|
88
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "activerecord/always_reset_column_information/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "activerecord-always_reset_column_information"
|
8
|
+
spec.version = Activerecord::AlwaysResetColumnInformation::VERSION
|
9
|
+
spec.authors = ["Takafumi ONAKA"]
|
10
|
+
spec.email = ["takafumi.onaka@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Call Model.reset_column_information for each migrations"
|
13
|
+
spec.description = "Call Model.reset_column_information for each migrations"
|
14
|
+
spec.homepage = "https://github.com/onk/activerecord-always_reset_column_information"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "activerecord"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "sqlite3"
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "activerecord/always_reset_column_information"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require "activerecord/always_reset_column_information/version"
|
2
|
+
require "activerecord/always_reset_column_information/migration"
|
3
|
+
require "active_record"
|
4
|
+
require "active_record/migration"
|
5
|
+
|
6
|
+
ActiveRecord::Migration.prepend Activerecord::AlwaysResetColumnInformation::Migration
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-always_reset_column_information
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takafumi ONAKA
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
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: rake
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Call Model.reset_column_information for each migrations
|
84
|
+
email:
|
85
|
+
- takafumi.onaka@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- activerecord-always_reset_column_information.gemspec
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/activerecord/always_reset_column_information.rb
|
101
|
+
- lib/activerecord/always_reset_column_information/migration.rb
|
102
|
+
- lib/activerecord/always_reset_column_information/version.rb
|
103
|
+
homepage: https://github.com/onk/activerecord-always_reset_column_information
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.6.14
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Call Model.reset_column_information for each migrations
|
127
|
+
test_files: []
|