ghost_schema 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
+ SHA256:
3
+ metadata.gz: 7b93cee1ba1d96eaf22f6dce97c6e35a399bf2164a521afef730a8cb91f77f0c
4
+ data.tar.gz: 2f59f3974b2ff0ec70f19b0b3be36e01146390c2f7144b4914428c2b1fd17010
5
+ SHA512:
6
+ metadata.gz: 7e8842d03807237ac9eb48f7ff4ae7a5e53a546756fc1520a007409ccacb3f925b0236645211d0e663d8b3e0c1b73808322c7d19716347aa5e8c35f9b0a2cd83
7
+ data.tar.gz: ae293f9157a69e48b2b69ae38e90e2c5abd08231f32fa4c9094b454297ec37234073ec3291f5b79224a198775c0374b697f773c590ef811529e30b03d06f81c2
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ghost_schema.gemspec
6
+ gemspec
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
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
@@ -0,0 +1,10 @@
1
+ require "ghost_schema/railtie"
2
+ require "ghost_schema/migration_store"
3
+ require "ghost_schema/tasks/enhancer"
4
+ require "ghost_schema/version"
5
+
6
+ module GhostSchema
7
+ def self.migrations_path
8
+ Rails.root.join('tmp', 'schema_ghosts')
9
+ end
10
+ end
@@ -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,8 @@
1
+ module GhostSchema
2
+ class Railtie < ::Rails::Railtie
3
+ rake_tasks do
4
+ Tasks::Enhancer.enhance
5
+ load 'tasks/ghost_schema_tasks.rake'
6
+ end
7
+ end
8
+ 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,3 @@
1
+ module GhostSchema
2
+ VERSION = "0.1.0"
3
+ 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: []