ghost_schema 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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ghost_schema.gemspec +26 -0
- data/lib/ghost_schema.rb +10 -0
- data/lib/ghost_schema/migration_store.rb +30 -0
- data/lib/ghost_schema/railtie.rb +8 -0
- data/lib/ghost_schema/tasks/enhancer.rb +15 -0
- data/lib/ghost_schema/version.rb +3 -0
- data/lib/tasks/ghost_schema_tasks.rake +36 -0
- metadata +102 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7b93cee1ba1d96eaf22f6dce97c6e35a399bf2164a521afef730a8cb91f77f0c
|
|
4
|
+
data.tar.gz: 2f59f3974b2ff0ec70f19b0b3be36e01146390c2f7144b4914428c2b1fd17010
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7e8842d03807237ac9eb48f7ff4ae7a5e53a546756fc1520a007409ccacb3f925b0236645211d0e663d8b3e0c1b73808322c7d19716347aa5e8c35f9b0a2cd83
|
|
7
|
+
data.tar.gz: ae293f9157a69e48b2b69ae38e90e2c5abd08231f32fa4c9094b454297ec37234073ec3291f5b79224a198775c0374b697f773c590ef811529e30b03d06f81c2
|
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) 2018 meganemura
|
|
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,52 @@
|
|
|
1
|
+
# GhostSchema
|
|
2
|
+
|
|
3
|
+
**DO NOT USE THIS GEM IN PRODUCTION.**
|
|
4
|
+
|
|
5
|
+
This gem is intended to be used under development environment.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'ghost_schema'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Switching between development branches may causes you following errors.
|
|
16
|
+
|
|
17
|
+
```console
|
|
18
|
+
$ bin/rails db:migrate:status
|
|
19
|
+
|
|
20
|
+
database: xxx_development
|
|
21
|
+
|
|
22
|
+
Status Migration ID Migration Name
|
|
23
|
+
--------------------------------------------------
|
|
24
|
+
up 20171019092851 Init schema
|
|
25
|
+
(snip)
|
|
26
|
+
up 20180319070119 Remove columns
|
|
27
|
+
up 20180330010101 ********** NO FILE **********
|
|
28
|
+
|
|
29
|
+
$ bin/rails db:rollback VERSION=20180330010101
|
|
30
|
+
rails aborted!
|
|
31
|
+
ActiveRecord::UnknownMigrationVersionError:
|
|
32
|
+
|
|
33
|
+
No migration with version number 20180330010101.
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This gem copies migration files when you run db:migrate.
|
|
37
|
+
If you want to run db:migrate:down for missing migration file,
|
|
38
|
+
you can do by running db:ghost:migrate:down.
|
|
39
|
+
|
|
40
|
+
```console
|
|
41
|
+
$ bin/rails db:ghost:migrate:down VERSION=20180330010101
|
|
42
|
+
== 20180330010101 AddAwesomeColumns: reverting ==============
|
|
43
|
+
(snip)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Contributing
|
|
47
|
+
|
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/meganemura/ghost_schema.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "ghost_schema"
|
|
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,26 @@
|
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "ghost_schema/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "ghost_schema"
|
|
7
|
+
spec.version = GhostSchema::VERSION
|
|
8
|
+
spec.authors = ["meganemura"]
|
|
9
|
+
spec.email = ["meganemura@users.noreply.github.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Improve development experience of rollbacking Rails missing migrations"
|
|
12
|
+
spec.description = spec.summary
|
|
13
|
+
spec.homepage = "https://github.com/meganemura/ghost_schema"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
|
18
|
+
end
|
|
19
|
+
spec.bindir = "exe"
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
26
|
+
end
|
data/lib/ghost_schema.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module GhostSchema
|
|
2
|
+
class MigrationStore
|
|
3
|
+
class << self
|
|
4
|
+
attr_accessor :original_migrations_paths
|
|
5
|
+
attr_accessor :before_migrating_migrations
|
|
6
|
+
attr_accessor :after_migrating_migrations
|
|
7
|
+
|
|
8
|
+
def copy_files
|
|
9
|
+
copy_target_files.each do |file|
|
|
10
|
+
FileUtils.copy(file, GhostSchema.migrations_path)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def copy_target_files
|
|
17
|
+
patterns = /#{diff_versions.join('|')}/
|
|
18
|
+
|
|
19
|
+
original_migrations_paths.flat_map do |migrations_path|
|
|
20
|
+
pattern = File.join(migrations_path, '*')
|
|
21
|
+
Dir.glob(pattern).select {|x| patterns.match?(x) }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def diff_versions
|
|
26
|
+
after_migrating_migrations - before_migrating_migrations
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module GhostSchema
|
|
2
|
+
module Tasks
|
|
3
|
+
module Enhancer
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
def enhance
|
|
7
|
+
task = Rake::Task['db:migrate']
|
|
8
|
+
task.enhance(['db:ghost:store_versions_before_migrations'])
|
|
9
|
+
task.enhance do
|
|
10
|
+
Rake::Task['db:ghost:copy_migrated_versions'].invoke
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
namespace :db do
|
|
2
|
+
namespace :ghost do
|
|
3
|
+
namespace :migrate do
|
|
4
|
+
desc 'Runs the "down" for a given migration VERSION from tmp/schema_ghosts.'
|
|
5
|
+
task down: [:prepare_directory, 'db:load_config'] do
|
|
6
|
+
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [Rails.root.join('tmp', 'schema_ghosts')]
|
|
7
|
+
ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
|
|
8
|
+
Rake::Task['db:migrate:down'].invoke
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
task :prepare_directory do
|
|
12
|
+
FileUtils.mkdir_p(Rails.root.join('tmp', 'schema_ghosts'))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# desc 'store versions'
|
|
17
|
+
task store_versions_before_migrations: [:store_original_migrations_paths] do
|
|
18
|
+
GhostSchema::MigrationStore.before_migrating_migrations = ActiveRecord::Base.connection.migration_context.get_all_versions
|
|
19
|
+
Rake::Task['db:ghost:restore_original_migrations_paths'].invoke
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# desc 'copy migrations'
|
|
23
|
+
task :copy_migrated_versions do
|
|
24
|
+
GhostSchema::MigrationStore.after_migrating_migrations = ActiveRecord::Base.connection.migration_context.get_all_versions
|
|
25
|
+
GhostSchema::MigrationStore.copy_files
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
task :store_original_migrations_paths do
|
|
29
|
+
GhostSchema::MigrationStore.original_migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
|
|
30
|
+
end
|
|
31
|
+
task :restore_original_migrations_paths do
|
|
32
|
+
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = GhostSchema::MigrationStore.original_migrations_paths
|
|
33
|
+
ActiveRecord::Migrator.migrations_paths = GhostSchema::MigrationStore.original_migrations_paths
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ghost_schema
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- meganemura
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
description: Improve development experience of rollbacking Rails missing migrations
|
|
56
|
+
email:
|
|
57
|
+
- meganemura@users.noreply.github.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".rspec"
|
|
64
|
+
- ".travis.yml"
|
|
65
|
+
- Gemfile
|
|
66
|
+
- LICENSE.txt
|
|
67
|
+
- README.md
|
|
68
|
+
- Rakefile
|
|
69
|
+
- bin/console
|
|
70
|
+
- bin/setup
|
|
71
|
+
- ghost_schema.gemspec
|
|
72
|
+
- lib/ghost_schema.rb
|
|
73
|
+
- lib/ghost_schema/migration_store.rb
|
|
74
|
+
- lib/ghost_schema/railtie.rb
|
|
75
|
+
- lib/ghost_schema/tasks/enhancer.rb
|
|
76
|
+
- lib/ghost_schema/version.rb
|
|
77
|
+
- lib/tasks/ghost_schema_tasks.rake
|
|
78
|
+
homepage: https://github.com/meganemura/ghost_schema
|
|
79
|
+
licenses:
|
|
80
|
+
- MIT
|
|
81
|
+
metadata: {}
|
|
82
|
+
post_install_message:
|
|
83
|
+
rdoc_options: []
|
|
84
|
+
require_paths:
|
|
85
|
+
- lib
|
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
requirements: []
|
|
97
|
+
rubyforge_project:
|
|
98
|
+
rubygems_version: 2.7.6
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 4
|
|
101
|
+
summary: Improve development experience of rollbacking Rails missing migrations
|
|
102
|
+
test_files: []
|