declare_schema 0.1.3 → 0.2.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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}
@@ -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)