declare_schema 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.dependabot/config.yml +10 -0
- data/.github/workflows/gem_release.yml +38 -0
- data/.gitignore +14 -0
- data/.jenkins/Jenkinsfile +72 -0
- data/.jenkins/ruby_build_pod.yml +19 -0
- data/.rspec +2 -0
- data/.rubocop.yml +189 -0
- data/.ruby-version +1 -0
- data/Appraisals +14 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +24 -0
- data/Gemfile.lock +203 -0
- data/LICENSE.txt +22 -0
- data/README.md +11 -0
- data/Rakefile +56 -0
- data/bin/declare_schema +11 -0
- data/declare_schema.gemspec +25 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_4.gemfile +25 -0
- data/gemfiles/rails_5.gemfile +25 -0
- data/gemfiles/rails_6.gemfile +25 -0
- data/lib/declare_schema.rb +44 -0
- data/lib/declare_schema/command.rb +65 -0
- data/lib/declare_schema/extensions/active_record/fields_declaration.rb +28 -0
- data/lib/declare_schema/extensions/module.rb +36 -0
- data/lib/declare_schema/field_declaration_dsl.rb +40 -0
- data/lib/declare_schema/model.rb +242 -0
- data/lib/declare_schema/model/field_spec.rb +162 -0
- data/lib/declare_schema/model/index_spec.rb +175 -0
- data/lib/declare_schema/railtie.rb +12 -0
- data/lib/declare_schema/version.rb +5 -0
- data/lib/generators/declare_schema/migration/USAGE +47 -0
- data/lib/generators/declare_schema/migration/migration_generator.rb +184 -0
- data/lib/generators/declare_schema/migration/migrator.rb +567 -0
- data/lib/generators/declare_schema/migration/templates/migration.rb.erb +9 -0
- data/lib/generators/declare_schema/model/USAGE +19 -0
- data/lib/generators/declare_schema/model/model_generator.rb +12 -0
- data/lib/generators/declare_schema/model/templates/model_injection.rb.erb +25 -0
- data/lib/generators/declare_schema/support/eval_template.rb +21 -0
- data/lib/generators/declare_schema/support/model.rb +64 -0
- data/lib/generators/declare_schema/support/thor_shell.rb +39 -0
- data/spec/lib/declare_schema/field_declaration_dsl_spec.rb +28 -0
- data/spec/spec_helper.rb +28 -0
- data/test/api.rdoctest +136 -0
- data/test/doc-only.rdoctest +76 -0
- data/test/generators.rdoctest +60 -0
- data/test/interactive_primary_key.rdoctest +56 -0
- data/test/migration_generator.rdoctest +846 -0
- data/test/migration_generator_comments.rdoctestDISABLED +74 -0
- data/test/prepare_testapp.rb +15 -0
- data/test_responses.txt +2 -0
- metadata +109 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
# DeclareSchema - Migration Generator Comments
|
2
|
+
|
3
|
+
Our test requires to prepare the testapp for a different environment:
|
4
|
+
{.hidden}
|
5
|
+
|
6
|
+
doctest_require: ENV["RAILS_ENV"] = 'mysql_test'; 'prepare_testapp'
|
7
|
+
|
8
|
+
>> system "cd #{TESTAPP_PATH} && rake --trace db:setup"
|
9
|
+
=> true
|
10
|
+
|
11
|
+
>> p Rails.env
|
12
|
+
>>
|
13
|
+
def nuke_model_class(klass)
|
14
|
+
ActiveSupport::DescendantsTracker.instance_eval do
|
15
|
+
class_variable_get('@@direct_descendants')[ActiveRecord::Base].delete(klass)
|
16
|
+
end
|
17
|
+
Object.instance_eval { remove_const klass.name.to_sym }
|
18
|
+
end
|
19
|
+
|
20
|
+
{.hidden}
|
21
|
+
|
22
|
+
|
23
|
+
## Comments
|
24
|
+
|
25
|
+
Comments can be added to tables and fields with DeclareSchema.
|
26
|
+
|
27
|
+
>>
|
28
|
+
class Product < ActiveRecord::Base
|
29
|
+
fields do
|
30
|
+
name :string, comment: "short name"
|
31
|
+
description :string
|
32
|
+
end
|
33
|
+
end
|
34
|
+
>> Rails.env
|
35
|
+
=> "mysql_test"
|
36
|
+
>> Rails::Generators.invoke 'declare_schema:migration', %w(-n -m)
|
37
|
+
|
38
|
+
These comments will be saved to your schema if you have the [column_comments](http://github.com/bryanlarsen/column_comments) plugin installed. If you do not have this plugin installed, the comments will be available by querying `field_specs`:
|
39
|
+
|
40
|
+
>> Product.field_specs["name"].comment
|
41
|
+
=> "short name"
|
42
|
+
|
43
|
+
The plugin [activerecord-comments](http://github.com/bryanlarsen/activerecord-comments) may be used to get the comments from the database directly. If the plugin is installed, use this instead:
|
44
|
+
|
45
|
+
Product.column("name").comment
|
46
|
+
|
47
|
+
Because it will be quite common for people not to have both [column_comments](http://github.com/bryanlarsen/column_comments) and [activerecord-comments](http://github.com/bryanlarsen/activerecord-comments) installed, it is impossible for DeclareSchema to determine the difference between no previous comment and a previously missing plugin. Therefore, DeclareSchema will not generate a migration if the only change was to add a comment. DeclareSchema will generate a migration for a comment change, but only if the plugin is installed.
|
48
|
+
|
49
|
+
>> require 'activerecord-comments'
|
50
|
+
|
51
|
+
>> # manually add comment as the column_comments plugin would
|
52
|
+
>> Product.connection.execute "alter table `products` modify `name` varchar(255) default null comment 'short name';"
|
53
|
+
|
54
|
+
>>
|
55
|
+
class Product < ActiveRecord::Base
|
56
|
+
fields do
|
57
|
+
name :string, comment: "Short namex"
|
58
|
+
description :string, comment: "Long name"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
>> up, down = Generators::DeclareSchema::Migration::Migrator.run
|
62
|
+
>> up.split(',').slice(0,3).join(',')
|
63
|
+
=> 'change_column :products, :name, :string'
|
64
|
+
>> up.split(',').slice(3,2).sort.join(',')
|
65
|
+
=> " :comment => \"Short namex\", :limit => 255"
|
66
|
+
|
67
|
+
|
68
|
+
Cleanup
|
69
|
+
{.hidden}
|
70
|
+
|
71
|
+
>> nuke_model_class(Product)
|
72
|
+
>> ActiveRecord::Base.connection.execute "drop table `products`;"
|
73
|
+
>> system "cd #{TESTAPP_PATH} && rake db:drop RAILS_ENV=mysql_test"
|
74
|
+
{.hidden}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
TESTAPP_PATH = ENV['TESTAPP_PATH'] || File.join(Dir.tmpdir, 'declare_schema_testapp')
|
7
|
+
system %(rake test:prepare_testapp TESTAPP_PATH=#{TESTAPP_PATH})
|
8
|
+
system %(echo "gem 'kramdown'" >> #{TESTAPP_PATH}/Gemfile)
|
9
|
+
system %(echo "gem 'RedCloth'" >> #{TESTAPP_PATH}/Gemfile)
|
10
|
+
FileUtils.chdir TESTAPP_PATH
|
11
|
+
system "mkdir -p #{TESTAPP_PATH}/app/assets/config"
|
12
|
+
system "echo '' >> #{TESTAPP_PATH}/app/assets/config/manifest.js"
|
13
|
+
require "#{TESTAPP_PATH}/config/environment"
|
14
|
+
require 'rails/generators'
|
15
|
+
Rails::Generators.configure!(Rails.application.config.generators)
|
data/test_responses.txt
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: declare_schema
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Invoca Development adapted from hobo_fields by Tom Locke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
description: Declare your Rails/active_record model schemas and have database migrations
|
28
|
+
generated for you!
|
29
|
+
email: development@invoca.com
|
30
|
+
executables:
|
31
|
+
- declare_schema
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".dependabot/config.yml"
|
36
|
+
- ".github/workflows/gem_release.yml"
|
37
|
+
- ".gitignore"
|
38
|
+
- ".jenkins/Jenkinsfile"
|
39
|
+
- ".jenkins/ruby_build_pod.yml"
|
40
|
+
- ".rspec"
|
41
|
+
- ".rubocop.yml"
|
42
|
+
- ".ruby-version"
|
43
|
+
- Appraisals
|
44
|
+
- CHANGELOG.md
|
45
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
47
|
+
- LICENSE.txt
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- bin/declare_schema
|
51
|
+
- declare_schema.gemspec
|
52
|
+
- gemfiles/.bundle/config
|
53
|
+
- gemfiles/rails_4.gemfile
|
54
|
+
- gemfiles/rails_5.gemfile
|
55
|
+
- gemfiles/rails_6.gemfile
|
56
|
+
- lib/declare_schema.rb
|
57
|
+
- lib/declare_schema/command.rb
|
58
|
+
- lib/declare_schema/extensions/active_record/fields_declaration.rb
|
59
|
+
- lib/declare_schema/extensions/module.rb
|
60
|
+
- lib/declare_schema/field_declaration_dsl.rb
|
61
|
+
- lib/declare_schema/model.rb
|
62
|
+
- lib/declare_schema/model/field_spec.rb
|
63
|
+
- lib/declare_schema/model/index_spec.rb
|
64
|
+
- lib/declare_schema/railtie.rb
|
65
|
+
- lib/declare_schema/version.rb
|
66
|
+
- lib/generators/declare_schema/migration/USAGE
|
67
|
+
- lib/generators/declare_schema/migration/migration_generator.rb
|
68
|
+
- lib/generators/declare_schema/migration/migrator.rb
|
69
|
+
- lib/generators/declare_schema/migration/templates/migration.rb.erb
|
70
|
+
- lib/generators/declare_schema/model/USAGE
|
71
|
+
- lib/generators/declare_schema/model/model_generator.rb
|
72
|
+
- lib/generators/declare_schema/model/templates/model_injection.rb.erb
|
73
|
+
- lib/generators/declare_schema/support/eval_template.rb
|
74
|
+
- lib/generators/declare_schema/support/model.rb
|
75
|
+
- lib/generators/declare_schema/support/thor_shell.rb
|
76
|
+
- spec/lib/declare_schema/field_declaration_dsl_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- test/api.rdoctest
|
79
|
+
- test/doc-only.rdoctest
|
80
|
+
- test/generators.rdoctest
|
81
|
+
- test/interactive_primary_key.rdoctest
|
82
|
+
- test/migration_generator.rdoctest
|
83
|
+
- test/migration_generator_comments.rdoctestDISABLED
|
84
|
+
- test/prepare_testapp.rb
|
85
|
+
- test_responses.txt
|
86
|
+
homepage: https://github.com/Invoca/declare_schema
|
87
|
+
licenses: []
|
88
|
+
metadata:
|
89
|
+
allowed_push_host: https://rubygems.org
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.3.6
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.0.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Database migration generator for Rails
|
109
|
+
test_files: []
|