declare_schema 0.1.1 → 0.3.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +37 -0
- data/CHANGELOG.md +36 -4
- data/Gemfile +0 -2
- data/Gemfile.lock +1 -4
- data/Rakefile +13 -20
- data/gemfiles/rails_4.gemfile +4 -7
- data/gemfiles/rails_5.gemfile +4 -7
- data/gemfiles/rails_6.gemfile +4 -7
- data/lib/declare_schema/model.rb +21 -23
- data/lib/declare_schema/model/field_spec.rb +1 -12
- data/lib/declare_schema/version.rb +1 -1
- data/lib/generators/declare_schema/migration/migration_generator.rb +20 -13
- data/lib/generators/declare_schema/migration/migrator.rb +57 -33
- data/lib/generators/declare_schema/migration/templates/migration.rb.erb +1 -1
- data/lib/generators/declare_schema/support/eval_template.rb +12 -3
- data/lib/generators/declare_schema/support/model.rb +77 -2
- data/spec/lib/declare_schema/api_spec.rb +125 -0
- data/spec/lib/declare_schema/field_declaration_dsl_spec.rb +8 -4
- data/spec/lib/declare_schema/generator_spec.rb +57 -0
- data/spec/lib/declare_schema/interactive_primary_key_spec.rb +51 -0
- data/spec/lib/declare_schema/migration_generator_spec.rb +735 -0
- data/spec/lib/declare_schema/prepare_testapp.rb +31 -0
- data/spec/lib/generators/declare_schema/migration/migrator_spec.rb +42 -0
- data/spec/spec_helper.rb +26 -0
- metadata +9 -11
- data/.jenkins/Jenkinsfile +0 -72
- data/.jenkins/ruby_build_pod.yml +0 -19
- data/lib/generators/declare_schema/model/templates/model_injection.rb.erb +0 -25
- data/test/api.rdoctest +0 -136
- data/test/generators.rdoctest +0 -60
- data/test/interactive_primary_key.rdoctest +0 -56
- data/test/migration_generator.rdoctest +0 -846
- data/test/migration_generator_comments.rdoctestDISABLED +0 -74
- data/test/prepare_testapp.rb +0 -15
@@ -1,74 +0,0 @@
|
|
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}
|
data/test/prepare_testapp.rb
DELETED
@@ -1,15 +0,0 @@
|
|
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)
|