rafter 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 +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/core_ext/active_record.rb +34 -0
- data/lib/rafter/railtie.rb +9 -0
- data/lib/rafter/schema.rb +21 -0
- data/lib/rafter/version.rb +3 -0
- data/lib/rafter.rb +8 -0
- data/lib/tasks/database.rake +22 -0
- data/lib/templates/schemafile.rb +21 -0
- data/rafter.gemspec +36 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 837d1cca949cd04112977a5b052b5f2f0af63dd180d3adeb71499d61fd751ae0
|
4
|
+
data.tar.gz: ff0c723931f39909dba6f40d6114fe9caa197cf010dc68468c6ac9416fde3d4f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52931b14548d76391638ead1ffd920b21fa66574501dcb9e7d6a1ff65bdda6982b7db997666e5f7f3b959321daa29cd3cd4973f5f4f0feca950fceb19d7a2d06
|
7
|
+
data.tar.gz: c13c5543ab690c46f8bc80b07ddcc9832147d42e23e6963cc3275aa52e7b27f4c1b6a1bd347994ba1f03f9e597de9a5a2fb7ddc03a6b364258af35b95452aa82
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 masakazutakewaka
|
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,48 @@
|
|
1
|
+
# Rafter
|
2
|
+
|
3
|
+
This gem is a Rails plugin for [ridgepole](https://github.com/winebarrel/ridgepole), a database schema manager.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :development, :test do
|
11
|
+
# ...
|
12
|
+
gem 'rafter'
|
13
|
+
# ...
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install rafter
|
24
|
+
|
25
|
+
## Usege
|
26
|
+
Once you install the gem, it automatically does the followings for you.
|
27
|
+
|
28
|
+
- apply your schema file to the test database with ridgepole before spec is run
|
29
|
+
- update your schema file when a model is generated with Rails CLI (`rails generate model ...`)
|
30
|
+
- apply your schema file when databases are setup with Rails tasks (`rails db:setup`, `rails db:reset`)
|
31
|
+
|
32
|
+
The path to your schema file defaults to `/app_root/db/Schemafile.rb`.
|
33
|
+
|
34
|
+
You can change it by setting the env variable `SCHEMA_FILE`.
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/masakazutakewaka/rafter.
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
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 "rafter"
|
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,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
require 'rails/generators/active_record/model/model_generator'
|
5
|
+
|
6
|
+
module ActiveRecord
|
7
|
+
module Generators
|
8
|
+
class ModelGenerator
|
9
|
+
|
10
|
+
undef_method :create_migration_file
|
11
|
+
|
12
|
+
def append_schema_file
|
13
|
+
attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
|
14
|
+
append_file schema_file, schema_template(File.expand_path('../templates/schemafile.rb', __dir__)), { verbose: false }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def schema_template(source)
|
20
|
+
context = instance_eval("binding")
|
21
|
+
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
|
22
|
+
ERB.new(::File.binread(source), trim_mode: "-", eoutvar: "@output_buffer").result(context)
|
23
|
+
else
|
24
|
+
ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def schema_file
|
29
|
+
not_found = Proc.new { return }
|
30
|
+
[Rails.root.join('db', 'Schemafile.rb'), ENV['SCHEMA_FILE']].find(not_found) { |f| File.file? f }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rafter
|
4
|
+
module Schema
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
def self.apply
|
8
|
+
status = system "ridgepole -c config/database.yml -E #{Rails.env} -f #{schema_file} --apply"
|
9
|
+
raise Error.new('ridgepole failed to apply Schemafile.') if status == false
|
10
|
+
rescue => e
|
11
|
+
puts e.full_message
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.schema_file
|
16
|
+
not_found = Proc.new { NotFoundError.new("Schemafile was not found") }
|
17
|
+
[Rails.root.join('db', 'Schemafile.rb'), ENV['SCHEMA_FILE']].find(not_found) { |f| File.file? f }
|
18
|
+
end
|
19
|
+
private_class_method :schema_file
|
20
|
+
end
|
21
|
+
end
|
data/lib/rafter.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
%w(db:setup db:test:load).each { |t| Rake::Task[t].clear }
|
4
|
+
|
5
|
+
namespace :db do
|
6
|
+
desc "setup with ridgepole"
|
7
|
+
task setup: [:create, "schema:ridgepole:apply", :seed]
|
8
|
+
|
9
|
+
namespace :test do
|
10
|
+
desc "load schema with ridgepole"
|
11
|
+
task load: "schema:ridgepole:apply"
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :schema do
|
15
|
+
namespace :ridgepole do
|
16
|
+
desc "apply ridgepole's schemafile"
|
17
|
+
task :apply do
|
18
|
+
Rafter::Schema.apply
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
create_table :<%= table_name %><%= primary_key_type %>, force: :cascade do |t|
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
<% if attribute.password_digest? -%>
|
5
|
+
t.string :password_digest<%= attribute.inject_options %>
|
6
|
+
<% elsif attribute.token? -%>
|
7
|
+
t.string :<%= attribute.name %><%= attribute.inject_options %>
|
8
|
+
<% else -%>
|
9
|
+
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
|
10
|
+
<% end -%>
|
11
|
+
<% end -%>
|
12
|
+
<% if options[:timestamps] %>
|
13
|
+
t.timestamps
|
14
|
+
<% end -%>
|
15
|
+
end
|
16
|
+
<% attributes.select(&:token?).each do |attribute| -%>
|
17
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true
|
18
|
+
<% end -%>
|
19
|
+
<% attributes_with_index.each do |attribute| -%>
|
20
|
+
add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
|
21
|
+
<% end -%>
|
data/rafter.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rafter/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rafter"
|
8
|
+
spec.version = Rafter::VERSION
|
9
|
+
spec.authors = ["Masakazu Takewaka"]
|
10
|
+
spec.email = ["takewakamma@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Rails plugin for integration with ridgepole."
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/masakazutakewaka/rafter"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency 'ridgepole'
|
27
|
+
spec.add_dependency 'rspec-rails'
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec"
|
32
|
+
spec.add_development_dependency "rails"
|
33
|
+
spec.add_development_dependency "sqlite3"
|
34
|
+
spec.add_development_dependency "bootsnap"
|
35
|
+
spec.add_development_dependency "listen"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rafter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masakazu Takewaka
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ridgepole
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bootsnap
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: listen
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Rails plugin for integration with ridgepole.
|
140
|
+
email:
|
141
|
+
- takewakamma@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- Gemfile
|
149
|
+
- LICENSE.txt
|
150
|
+
- README.md
|
151
|
+
- Rakefile
|
152
|
+
- bin/console
|
153
|
+
- bin/setup
|
154
|
+
- lib/core_ext/active_record.rb
|
155
|
+
- lib/rafter.rb
|
156
|
+
- lib/rafter/railtie.rb
|
157
|
+
- lib/rafter/schema.rb
|
158
|
+
- lib/rafter/version.rb
|
159
|
+
- lib/tasks/database.rake
|
160
|
+
- lib/templates/schemafile.rb
|
161
|
+
- rafter.gemspec
|
162
|
+
homepage: https://github.com/masakazutakewaka/rafter
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubygems_version: 3.0.3
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Rails plugin for integration with ridgepole.
|
185
|
+
test_files: []
|