ignored_columns_tasks 0.0.1 → 0.1.1
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/Changes +7 -0
- data/README.md +8 -3
- data/ignored_columns_tasks.gemspec +1 -1
- data/lib/ignored_columns_tasks/tasks/ignored_columns.rake +2 -2
- data/lib/ignored_columns_tasks/version.rb +1 -1
- data/lib/ignored_columns_tasks.rb +25 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d755fcd6106bbb60881de1e5f4099fca52a81af2fe4bb91506f9d4d17e17a0
|
4
|
+
data.tar.gz: b7c234d546bed73d91286f6d6e75e974f79f224f979e7aa15320f9875a6147ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efb6c72515f5bd6a97db79eb19fb3965b2e76d753e434c3a83bbba1c735b77d554e14602c6eaa82e942195ca825bccfb55a2fb61479a2f22114d8e48ec777ae1
|
7
|
+
data.tar.gz: 50ab666a8657cf2f72dc11032b37798dbd7d62c688b1f3311a6bc509b12a5d15b79ac9bd8e703a5803f3215b76bdf5d88c02040e6b15b78cfbb424d5738b7834
|
data/Changes
ADDED
data/README.md
CHANGED
@@ -32,18 +32,23 @@ If you have ignored columns that must not be dropped add them to the `SKIP_COLUM
|
|
32
32
|
```
|
33
33
|
|
34
34
|
You can set this once for your project instead of specifying it every time.
|
35
|
-
In this case it is recommended to use the `
|
35
|
+
In this case it is recommended to use the `IGNORED_COLUMNS_TASKS_SKIP_COLUMNS` environment variable:
|
36
36
|
|
37
37
|
```sh
|
38
|
-
export
|
38
|
+
export IGNORED_COLUMNS_TASKS_SKIP_COLUMNS="some_column,another_column"
|
39
39
|
```
|
40
40
|
|
41
|
-
This task can also be limited to a single model
|
41
|
+
This task can also be limited to a single model by setting the `MODEL` environment variable:
|
42
42
|
|
43
43
|
```
|
44
44
|
./bin/rails ignored_columns:migration MODEL=User
|
45
45
|
```
|
46
46
|
|
47
|
+
#### Strong Migrations
|
48
|
+
|
49
|
+
If your project uses [Strong Migrations](https://github.com/ankane/strong_migrations) the `remove_column` call
|
50
|
+
will be wrapped in a `safety_assured` block.
|
51
|
+
|
47
52
|
### Ignored Columns That Have Been Dropped From Your Database
|
48
53
|
|
49
54
|
This will print ignored columns that no longer exist the database:
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
16
16
|
spec.metadata["source_code_uri"] = "https://github.com/sshaw/ignored_columns_tasks"
|
17
|
-
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/sshaw/ignored_columns_tasks/blob/master/Changes"
|
18
18
|
|
19
19
|
# Specify which files should be added to the gem when it is released.
|
20
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -9,9 +9,9 @@ namespace :ignored_columns do
|
|
9
9
|
def skip_columns
|
10
10
|
skip = nil
|
11
11
|
|
12
|
-
#
|
12
|
+
# IGNORED_COLUMNS_TASKS_SKIP_COLUMNS is our global, namespaced version
|
13
13
|
# SKIP_COLUMNS is shorter, command-line argument
|
14
|
-
%w[
|
14
|
+
%w[IGNORED_COLUMNS_TASKS_SKIP_COLUMNS SKIP_COLUMNS].each do |name|
|
15
15
|
if ENV[name]
|
16
16
|
skip ||= []
|
17
17
|
skip.concat(ENV[name].split(/\s*,\s/))
|
@@ -72,12 +72,15 @@ module IgnoredColumnsTasks
|
|
72
72
|
return
|
73
73
|
end
|
74
74
|
|
75
|
+
migrations = []
|
75
76
|
to_drop.group_by(&:klass).each do |klass, columns|
|
76
|
-
|
77
|
+
migrations << "remove_ignored_columns_from_#{klass.table_name}"
|
77
78
|
|
78
79
|
# Assume Rails does the shell quoting on Column#name?
|
79
|
-
Rails::Generators.invoke("active_record:migration", [
|
80
|
+
Rails::Generators.invoke("active_record:migration", [migrations[-1], columns.map(&:name)])
|
80
81
|
end
|
82
|
+
|
83
|
+
apply_strong_migrations(migrations) if defined?(StrongMigrations)
|
81
84
|
end
|
82
85
|
|
83
86
|
private
|
@@ -114,6 +117,26 @@ module IgnoredColumnsTasks
|
|
114
117
|
ignored.map { |column| Column.new(class_with_all, column, class_with_all.columns_hash[column]) }
|
115
118
|
end
|
116
119
|
end
|
120
|
+
|
121
|
+
def apply_strong_migrations(migrations)
|
122
|
+
migrations.each do |migration|
|
123
|
+
# Better way to do this? There should only be 1 since db:migrate will fail if suffix exists.
|
124
|
+
path = Dir[ Rails.root.join("db/migrate") / "*_#{migration}.rb" ][0]
|
125
|
+
# If we can't find it could be due to migration generator failing. How to tell? $? and return value not reliable
|
126
|
+
next unless path
|
127
|
+
|
128
|
+
add_safety_assured(path)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def add_safety_assured(path)
|
133
|
+
migration = File.read(path)
|
134
|
+
return if migration =~ /\wsafety_assured\s/
|
135
|
+
|
136
|
+
migration.gsub!(/^(\s*)(remove_column.+)(\s*)$/) { "#$1safety_assured { #$2 }#$3" }
|
137
|
+
|
138
|
+
File.write(path, migration)
|
139
|
+
end
|
117
140
|
end
|
118
141
|
end
|
119
142
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ignored_columns_tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Skye Shaw
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
|
+
- Changes
|
50
51
|
- Gemfile
|
51
52
|
- LICENSE.txt
|
52
53
|
- README.md
|
@@ -64,6 +65,7 @@ licenses:
|
|
64
65
|
metadata:
|
65
66
|
homepage_uri: https://github.com/sshaw/ignored_columns_tasks
|
66
67
|
source_code_uri: https://github.com/sshaw/ignored_columns_tasks
|
68
|
+
changelog_uri: https://github.com/sshaw/ignored_columns_tasks/blob/master/Changes
|
67
69
|
post_install_message:
|
68
70
|
rdoc_options: []
|
69
71
|
require_paths:
|