safer_migrations 0.1.1 → 0.1.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 +4 -4
- data/README.md +13 -1
- data/lib/safer_migrations/schema_statements.rb +35 -11
- data/lib/safer_migrations/version.rb +1 -1
- data/lib/safer_migrations.rb +29 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c294834ff3b4b77adb2e284fe48078e3b7482559539b1fa6974f2dc0a13ec8d
|
4
|
+
data.tar.gz: 3773b0eb7ccf1ed43514caabb462caf12ac7383641e796c305a92f100e803860
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fa2ec4033335b64091a95defeabe042ffd6ee86cdfbe8c0517516b199211b059fd410377448001571392231d1163e16cf9655ff6c0aed5da69c38047c0522c8
|
7
|
+
data.tar.gz: c9253a672f540ecec3fc46d74ac4f4862bce92d42324e772b652a8833d5972c7d1d9b179d9923cad086a6c3c87dbf3709d848a4b0a6fbf3f86bf6f455626cb3a
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# SaferMigrations
|
2
2
|
|
3
3
|
`SaferMigrations` provides safer methods for Active Record Migrations.
|
4
|
+
|
4
5
|
## Installation
|
5
6
|
|
6
7
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -13,7 +14,18 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
13
14
|
|
14
15
|
## Usage
|
15
16
|
|
16
|
-
|
17
|
+
This gem provides the following methods for Active Record Migrations.
|
18
|
+
|
19
|
+
* `safer_remove_column`
|
20
|
+
* `safer_remove_columns`
|
21
|
+
* `safer_rename_column`
|
22
|
+
* `t.safer_remove`
|
23
|
+
* `t.safer_rename`
|
24
|
+
|
25
|
+
These methods check whether a column that will be removed is still used in a model. If a model uses it, these methods raise an error. In that case, you should specify a column to `ignored_columns` first.
|
26
|
+
|
27
|
+
Except for checking it, the behavior is same as well as the Rail's default methods.
|
28
|
+
|
17
29
|
|
18
30
|
## Development
|
19
31
|
|
@@ -2,21 +2,45 @@
|
|
2
2
|
|
3
3
|
module SaferMigrations
|
4
4
|
module SchemaStatements
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
if SaferMigrations.enforce_safer_methods
|
6
|
+
def remove_column(table_name, column_name, type = nil, **options)
|
7
|
+
validate_remove_column(table_name, column_name)
|
8
|
+
super
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def remove_columns(table_name, *column_names, type: nil, **options)
|
12
|
+
column_names.each do |column_name|
|
13
|
+
validate_remove_column(table_name, column_name)
|
14
|
+
end
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def rename_column(table_name, column_name, new_column_name)
|
12
19
|
validate_remove_column(table_name, column_name)
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
alias_method :safer_remove_column, :remove_column
|
24
|
+
alias_method :safer_remove_columns, :remove_columns
|
25
|
+
alias_method :safer_rename_column, :rename_column
|
26
|
+
else
|
27
|
+
def safer_remove_column(table_name, column_name, type = nil, **options)
|
28
|
+
validate_remove_column(table_name, column_name)
|
29
|
+
remove_column(table_name, column_name, type, **options)
|
13
30
|
end
|
14
|
-
remove_columns(table_name, *column_names, type = nil, **options)
|
15
|
-
end
|
16
31
|
|
17
|
-
|
18
|
-
|
19
|
-
|
32
|
+
def safer_remove_columns(table_name, *column_names, type: nil, **options)
|
33
|
+
column_names.each do |column_name|
|
34
|
+
validate_remove_column(table_name, column_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
remove_columns(table_name, *column_names, type: type, **options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def safer_rename_column(table_name, column_name, new_column_name)
|
41
|
+
validate_remove_column(table_name, column_name)
|
42
|
+
rename_column(table_name, column_name, new_column_name)
|
43
|
+
end
|
20
44
|
end
|
21
45
|
|
22
46
|
private
|
data/lib/safer_migrations.rb
CHANGED
@@ -3,14 +3,39 @@
|
|
3
3
|
require "active_support"
|
4
4
|
require "active_record"
|
5
5
|
|
6
|
+
module SaferMigrations
|
7
|
+
class << self
|
8
|
+
attr_accessor :enforce_safer_methods
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
6
12
|
require_relative "safer_migrations/version"
|
7
13
|
require_relative "safer_migrations/errors"
|
8
|
-
require_relative "safer_migrations/command_recorder"
|
9
|
-
require_relative "safer_migrations/schema_statements"
|
10
|
-
require_relative "safer_migrations/schema_definitions"
|
11
14
|
|
12
15
|
ActiveSupport.on_load(:active_record) do
|
13
|
-
|
16
|
+
require_relative "safer_migrations/command_recorder"
|
17
|
+
require_relative "safer_migrations/schema_definitions"
|
18
|
+
|
14
19
|
ActiveRecord::ConnectionAdapters::Table.prepend(SaferMigrations::TableDefinition)
|
15
20
|
ActiveRecord::Migration::CommandRecorder.prepend(SaferMigrations::CommandRecorder)
|
16
21
|
end
|
22
|
+
|
23
|
+
ActiveSupport.on_load(:active_record_sqlite3adapter) do
|
24
|
+
require_relative "safer_migrations/schema_statements"
|
25
|
+
self.prepend(SaferMigrations::SchemaStatements)
|
26
|
+
end
|
27
|
+
|
28
|
+
ActiveSupport.on_load(:active_record_mysql2adapter) do
|
29
|
+
require_relative "safer_migrations/schema_statements"
|
30
|
+
self.prepend(SaferMigrations::SchemaStatements)
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveSupport.on_load(:active_record_trilogyadapter) do
|
34
|
+
require_relative "safer_migrations/schema_statements"
|
35
|
+
self.prepend(SaferMigrations::SchemaStatements)
|
36
|
+
end
|
37
|
+
|
38
|
+
ActiveSupport.on_load(:active_record_postgresqladapter) do
|
39
|
+
require_relative "safer_migrations/schema_statements"
|
40
|
+
self.prepend(SaferMigrations::SchemaStatements)
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safer_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji yaginuma
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -54,11 +54,11 @@ files:
|
|
54
54
|
- lib/safer_migrations/schema_definitions.rb
|
55
55
|
- lib/safer_migrations/schema_statements.rb
|
56
56
|
- lib/safer_migrations/version.rb
|
57
|
-
homepage: https://github.com/y-yagi
|
57
|
+
homepage: https://github.com/y-yagi/safer_migrations
|
58
58
|
licenses:
|
59
59
|
- MIT
|
60
60
|
metadata:
|
61
|
-
homepage_uri: https://github.com/y-yagi
|
61
|
+
homepage_uri: https://github.com/y-yagi/safer_migrations
|
62
62
|
post_install_message:
|
63
63
|
rdoc_options: []
|
64
64
|
require_paths:
|