deprecated_columns 0.1.0

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: 84cf7ea6278f1e8dc25fd4057b20643a03b487ec
4
+ data.tar.gz: 529cd11e87e2eeffd4c8336745132f4aa540507e
5
+ SHA512:
6
+ metadata.gz: 4938ee1ad63d749e44d9cdb13b15f6b4e9aa12113630f108864828369366065d826cafade716d77b425ffcc66c9777a4fdcb0ed785dfc50f5d49758fa90676f0
7
+ data.tar.gz: 6a33d174c844840bc2e0909c02e81b02b926c78c68cff26a0329fda86936f09aa6560da7c5ab44758a95d8e640dacca65c05437fb8472219d32a4b8fca6b3def
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.10.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+
3
+ * Initial release
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in deprecated_columns.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Government Digital Service
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,45 @@
1
+ # DeprecatedColumns
2
+
3
+ Permits a grace period for substractive column changes, via Active Record
4
+ migrations.
5
+
6
+ This was inspired by (read: entirely lifted) from Whitehall with a few
7
+ modifications.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```gem 'deprecated_columns'```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install deprecated_columns
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ class User < ActiveRecord::Base
27
+ deprecated_columns :name
28
+ end
29
+ ```
30
+
31
+ For subtractive migrations to columns in your schema you'll see a warning,
32
+ unless you've specifically marked the column(s) using the `deprecated_columns`
33
+ macro.
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at
38
+ https://github.com/alphagov/deprecated_columns. This project is intended to
39
+ be a safe, welcoming space for collaboration, and contributors are expected to
40
+ adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT
45
+ License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "gem_publisher"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ task :publish_gem do |t|
10
+ gem = GemPublisher.publish_if_updated("deprecated_columns.gemspec", :rubygems)
11
+ puts "Published #{gem}" if gem
12
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "deprecated_columns"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "deprecated_columns/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "deprecated_columns"
8
+ spec.version = DeprecatedColumns::VERSION
9
+ spec.authors = ["Ben Lovell"]
10
+ spec.email = ["benjamin.lovell@gmail.com"]
11
+
12
+ spec.summary = %q{Active Record compliant column/attribute deprecator}
13
+ spec.description = %q{Mark column(s) for deprecation to permit subtractive schema changes in production.}
14
+ spec.homepage = "https://www.gov.uk/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = ">= 2.0.0"
23
+
24
+ spec.add_dependency "rails", ">= 4.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec-rails"
29
+ spec.add_development_dependency "sqlite3"
30
+ spec.add_development_dependency "pry-byebug"
31
+ spec.add_development_dependency "gem_publisher", "~> 1.1.1"
32
+ end
data/jenkins.sh ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/bash -xe
2
+
3
+ # Gemfile.lock is not in source control because this is a gem
4
+ rm -f Gemfile.lock
5
+
6
+ git clean -fdx
7
+
8
+ bundle install --path "${HOME}/bundles/${JOB_NAME}"
9
+ bundle exec rake
10
+
11
+ if [[ -n "$PUBLISH_GEM" ]]; then
12
+ bundle exec rake publish_gem
13
+ fi
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ VENV_PATH="${HOME}/venv/${JOB_NAME}"
5
+
6
+ [ -x ${VENV_PATH}/bin/pip ] || virtualenv ${VENV_PATH}
7
+ . ${VENV_PATH}/bin/activate
8
+
9
+ pip install -q ghtools
10
+
11
+ REPO="alphagov/deprecated_columns"
12
+ gh-status "$REPO" "$GIT_COMMIT" pending -d "\"Build #${BUILD_NUMBER} is running on Jenkins\"" -u "$BUILD_URL" >/dev/null
13
+
14
+ if ./jenkins.sh; then
15
+ gh-status "$REPO" "$GIT_COMMIT" success -d "\"Build #${BUILD_NUMBER} succeeded on Jenkins\"" -u "$BUILD_URL" >/dev/null
16
+ exit 0
17
+ else
18
+ gh-status "$REPO" "$GIT_COMMIT" failure -d "\"Build #${BUILD_NUMBER} failed on Jenkins\"" -u "$BUILD_URL" >/dev/null
19
+ exit 1
20
+ fi
@@ -0,0 +1,32 @@
1
+ require "deprecated_columns/version"
2
+ require "deprecated_columns/warn_on_column_removal"
3
+
4
+ module DeprecatedColumns
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def deprecated_columns(*names)
11
+ unless self.respond_to?(:deprecated_column_list)
12
+ class_attribute :deprecated_column_list
13
+ self.deprecated_column_list = []
14
+ end
15
+
16
+ self.deprecated_column_list += names.map(&:to_s)
17
+
18
+ class_eval do
19
+ def attribute_names
20
+ super.reject { |name| deprecated_column_list.include?(name) }
21
+ end
22
+
23
+ def columns
24
+ super.reject { |column| deprecated_column_list.include?(column.name) }
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ ActiveRecord::Base.send :include, DeprecatedColumns
32
+ ActiveRecord::Migration.send :prepend, WarnOnColumnRemoval
@@ -0,0 +1,3 @@
1
+ module DeprecatedColumns
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ module WarnOnColumnRemoval
2
+ def remove_column(table_name, column_name, type = nil, options = {})
3
+ puts column_deprecation_status(table_name, column_name)
4
+
5
+ super
6
+ end
7
+
8
+ def column_deprecation_status(table_name, column_name)
9
+ begin
10
+ klass = table_name.to_s.singularize.camelize.constantize
11
+ rescue NameError
12
+ return "WARNING: Couldn't find model for table #{table_name}. I can't tell " +
13
+ "if column #{column_name} has been deprecated."
14
+ end
15
+
16
+ if klass.try(:deprecated_column_list).to_a.include?(column_name.to_s)
17
+ "OK: #{table_name}.#{column_name} has been deprecated."
18
+ else
19
+ "WARNING: #{table_name}.#{column_name} has not been deprecated. Please " +
20
+ "use the `deprecated_columns` macro to avoid crashing the application " +
21
+ "at deploy time."
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deprecated_columns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Lovell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.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: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
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
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: gem_publisher
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.1.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.1.1
111
+ description: Mark column(s) for deprecation to permit subtractive schema changes in
112
+ production.
113
+ email:
114
+ - benjamin.lovell@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".ruby-version"
122
+ - ".travis.yml"
123
+ - CHANGELOG.md
124
+ - CODE_OF_CONDUCT.md
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/console
130
+ - bin/setup
131
+ - deprecated_columns.gemspec
132
+ - jenkins.sh
133
+ - jenkins_branches.sh
134
+ - lib/deprecated_columns.rb
135
+ - lib/deprecated_columns/version.rb
136
+ - lib/deprecated_columns/warn_on_column_removal.rb
137
+ homepage: https://www.gov.uk/
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 2.0.0
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.4.5.1
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Active Record compliant column/attribute deprecator
161
+ test_files: []