safer_migrations 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +30 -0
- data/Rakefile +10 -0
- data/lib/safer_migrations/command_recorder.rb +21 -0
- data/lib/safer_migrations/errors.rb +6 -0
- data/lib/safer_migrations/schema_statements.rb +26 -0
- data/lib/safer_migrations/version.rb +5 -0
- data/lib/safer_migrations.rb +14 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6ad6bd8008a2d391b97b18ec2c14b12a51a35c875c34b0cfa2f61ec079ed89b9
|
4
|
+
data.tar.gz: c5892a3dfd9646c4c1d8b38a7538189f056b1deb771d6302220efde903eec311
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b7d30166b71ad5a053f5fdcef23ee166004e5867867cd841fbf133cf517666c27e3289203e5936cc4f17f3bdbfbdc0ca74c7110809b2d380cb2658a1c952b9b
|
7
|
+
data.tar.gz: 12e0ba7df956e5678ffa13bc4cbc8851f0265017e3c2498da953d60bff02f55f1384f4272fda52b4cc298da28650f1256d275a8cf3928ecf41acc05aeb6e1c02
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Yuji Yaginuma
|
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,30 @@
|
|
1
|
+
# SaferMigrations
|
2
|
+
|
3
|
+
`SaferMigrations` provides safer methods for Active Record Migrations.
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Install the gem and add to the application's Gemfile by executing:
|
7
|
+
|
8
|
+
$ bundle add safer_migrations
|
9
|
+
|
10
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
11
|
+
|
12
|
+
$ gem install safer_migrations
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
TODO: Write usage instructions here
|
17
|
+
|
18
|
+
## Development
|
19
|
+
|
20
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
21
|
+
|
22
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/y-yagi/safer_migrations.
|
27
|
+
|
28
|
+
## License
|
29
|
+
|
30
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SaferMigrations
|
4
|
+
module CommandRecorder
|
5
|
+
ruby2_keywords def safer_remove_column(*args, &block)
|
6
|
+
record(:safer_remove_column, args, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def invert_safer_remove_column(args)
|
10
|
+
invert_remove_column(args)
|
11
|
+
end
|
12
|
+
|
13
|
+
ruby2_keywords def safer_remove_columns(*args, &block)
|
14
|
+
record(:safer_remove_columns, args, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def invert_safer_remove_columns(args)
|
18
|
+
invert_remove_columns(args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SaferMigrations
|
4
|
+
module SchemaStatements
|
5
|
+
def safer_remove_column(table_name, column_name, type = nil, **options)
|
6
|
+
validate_remove_column(table_name, column_name)
|
7
|
+
remove_column(table_name, column_name, type = nil, **options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def safer_remove_columns(table_name, *column_names, type: nil, **options)
|
11
|
+
column_names.each do |column_name|
|
12
|
+
validate_remove_column(table_name, column_name)
|
13
|
+
end
|
14
|
+
remove_columns(table_name, *column_names, type = nil, **options)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def validate_remove_column(table_name, column_name)
|
20
|
+
model = table_name.to_s.classify.constantize
|
21
|
+
if model.column_names.include?(column_name.to_s)
|
22
|
+
raise SaferMigrations::DangerousMigrationError, "'#{model}' model still uses '#{column_name}'"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "active_record"
|
5
|
+
|
6
|
+
require_relative "safer_migrations/version"
|
7
|
+
require_relative "safer_migrations/errors"
|
8
|
+
require_relative "safer_migrations/command_recorder"
|
9
|
+
require_relative "safer_migrations/schema_statements"
|
10
|
+
|
11
|
+
ActiveSupport.on_load(:active_record) do
|
12
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(SaferMigrations::SchemaStatements)
|
13
|
+
ActiveRecord::Migration::CommandRecorder.prepend(SaferMigrations::CommandRecorder)
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: safer_migrations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yuji yaginuma
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-06-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '6.1'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- yuuji.yaginuma@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE.txt
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/safer_migrations.rb
|
52
|
+
- lib/safer_migrations/command_recorder.rb
|
53
|
+
- lib/safer_migrations/errors.rb
|
54
|
+
- lib/safer_migrations/schema_statements.rb
|
55
|
+
- lib/safer_migrations/version.rb
|
56
|
+
homepage: https://github.com/y-yagi
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata:
|
60
|
+
homepage_uri: https://github.com/y-yagi
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.1.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.5.9
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Provide safer migration methods
|
80
|
+
test_files: []
|