migration_comments 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
- .idea/*
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/*
6
6
  test/db/migration_comments_test
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Pinny Markowitz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,81 +1,84 @@
1
- = MigrationComments
2
-
3
- Comments for your migrations
4
-
5
- Tested on:
6
-
7
- Ruby 1.8.7 using Rails 3.x.
8
- Ruby 1.8.6 using Rails 2.3.x.
9
-
10
- == Why?
11
-
12
- Migrations are wonderful. They handle all your schema changes, and in a pinch they can bring
13
- any database up to speed. However, database schemas can change rapidly while a project is
14
- maturing, and it can be difficult to know (or remember) the purpose for each table and field.
15
- As such, they deserve to be commented. These comments should be available for display wherever
16
- those fields are found.
17
-
18
- == Solution!
19
-
20
- Using MigrationComments, you can simply add comments during your migrations. Or if you already
21
- have existing data structures, just add the comments afterwards in a separate migration. And of
22
- course you can always modify and delete these comments in later migrations.
23
-
24
- So where are these comments used? Firstly, they will be included in your schema.rb dump which
25
- is where your IDE (e.g. RubyMine) should be learning about your model structure. This means that
26
- they'll be available at any point in your project. Additionally, if you are using the 'annotate'
27
- gem, these comments will be added to the annotations that are generated within your model.rb
28
- file.
29
-
30
- == Examples
31
-
32
- To add a comment to an existing structure...
33
-
34
- def self.up
35
- set_table_comment :table_name, "A table comment"
36
- set_column_comment :table_name, :column_name, "A column comment"
37
- end
38
-
39
- Or you can use the change_table macro...
40
-
41
- def self.up
42
- change_table :table_name do |t|
43
- t.comment "A table comment"
44
- t.change_comment :column_name, "A column comment"
45
- end
46
- end
47
-
48
- Creating a new table?
49
-
50
- def self.up
51
- create_table :table_name, :comment => "A table comment" do |t|
52
- t.string :column_name, :comment => "A column comment"
53
- end
54
- end
55
-
56
- You can also remove comments...
57
-
58
- def self.up
59
- remove_table_comment :table_name
60
- remove_column_comment :table_name, :column_name
61
- end
62
-
63
- Or you can combine these commands while modifying a table...
64
-
65
- def self.up
66
- change_table :existing_table do |t|
67
- t.comment nil # remove an existing table comment
68
- t.string :new_column, :comment => "a new column" # add a new column with a comment
69
- t.change_comment :existing_column, nil # remove a comment on an existing column
70
- t.integer :another_existing_column, :comment => nil # remove a comment on an existing column while modifying the column type
71
- t.boolean :column_with_comment # modify an existing column without altering the comment
72
- end
73
- end
74
-
75
-
76
- == Requirements
77
-
78
- You must be using a supported DBMS (currently PostgreSQL, MySQL, and SQLite).
79
-
80
- If this isn't an option for you, check out the 'schema_comments' gem:
81
- https://github.com/akm/schema_comments
1
+ = MigrationComments
2
+
3
+ Comments for your migrations
4
+
5
+ Tested on:
6
+
7
+ * Ruby 1.8.7/1.9.x using Rails 3.x
8
+ * Ruby 1.8.6/1.8.7 using Rails 2.3.x.
9
+
10
+ == Why?
11
+
12
+ Migrations are wonderful. They handle all your schema changes, and in a pinch they can bring
13
+ any database up to speed. However, database schemas can change rapidly while a project is
14
+ maturing, and it can be difficult to know (or remember) the purpose for each table and field.
15
+ As such, they deserve to be commented. These comments should be available for display wherever
16
+ those fields are found.
17
+
18
+ == Solution!
19
+
20
+ Using MigrationComments, you can simply add comments during your migrations. Or if you already
21
+ have existing data structures, just add the comments afterwards in a separate migration. And of
22
+ course you can always modify and delete these comments in later migrations.
23
+
24
+ So where are these comments used? Firstly, they will be included in your schema.rb dump which
25
+ is where your IDE (e.g. RubyMine) should be learning about your model structure. This means that
26
+ they'll be available at any point in your project. Additionally, if you are using the 'annotate'
27
+ gem, these comments will be added to the annotations that are generated within your model.rb
28
+ file.
29
+
30
+ == Examples
31
+
32
+ To add a comment to an existing structure...
33
+
34
+ def self.up
35
+ set_table_comment :table_name, "A table comment"
36
+ set_column_comment :table_name, :column_name, "A column comment"
37
+ end
38
+
39
+ Or you can use the change_table macro...
40
+
41
+ def self.up
42
+ change_table :table_name do |t|
43
+ t.comment "A table comment"
44
+ t.change_comment :column_name, "A column comment"
45
+ end
46
+ end
47
+
48
+ Creating a new table?
49
+
50
+ def self.up
51
+ create_table :table_name, :comment => "A table comment" do |t|
52
+ t.string :column_name, :comment => "A column comment"
53
+ end
54
+ end
55
+
56
+ You can also remove comments...
57
+
58
+ def self.up
59
+ remove_table_comment :table_name
60
+ remove_column_comment :table_name, :column_name
61
+ end
62
+
63
+ Or you can combine these commands while modifying a table...
64
+
65
+ def self.up
66
+ change_table :existing_table do |t|
67
+ t.comment nil # remove an existing table comment
68
+ t.string :new_column, :comment => "a new column" # add a new column with a comment
69
+ t.change_comment :existing_column, nil # remove a comment on an existing column
70
+ t.integer :another_existing_column, :comment => nil # remove a comment on an existing column while modifying the column type
71
+ t.boolean :column_with_comment # modify an existing column without altering the comment
72
+ end
73
+ end
74
+
75
+
76
+ == Requirements
77
+
78
+ You must be using a supported DBMS (currently PostgreSQL, MySQL, and SQLite).
79
+
80
+ If this isn't an option for you, check out the 'schema_comments' gem at https://github.com/akm/schema_comments
81
+
82
+ == Licensing
83
+
84
+ See MIT-LICENSE file for details.
@@ -1,60 +1,60 @@
1
- require "migration_comments/version"
2
-
3
- require 'migration_comments/active_record/schema_dumper'
4
- require 'migration_comments/active_record/connection_adapters/comment_definition'
5
- require 'migration_comments/active_record/connection_adapters/column_definition'
6
- require 'migration_comments/active_record/connection_adapters/column'
7
- require 'migration_comments/active_record/connection_adapters/table'
8
- require 'migration_comments/active_record/connection_adapters/table_definition'
9
- require 'migration_comments/active_record/connection_adapters/abstract_adapter'
10
- require 'migration_comments/active_record/connection_adapters/mysql_adapter'
11
- require 'migration_comments/active_record/connection_adapters/mysql2_adapter'
12
- require 'migration_comments/active_record/connection_adapters/postgresql_adapter'
13
- require 'migration_comments/active_record/connection_adapters/sqlite_adapter'
14
-
15
- module MigrationComments
16
- def self.setup
17
- base_names = %w(SchemaDumper) +
18
- %w(ColumnDefinition Column Table TableDefinition AbstractAdapter).map{|name| "ConnectionAdapters::#{name}"}
19
-
20
- base_names.each do |base_name|
21
- ar_class = "ActiveRecord::#{base_name}".constantize
22
- mc_class = "MigrationComments::ActiveRecord::#{base_name}".constantize
23
- unless ar_class.ancestors.include?(mc_class)
24
- ar_class.__send__(:include, mc_class)
25
- end
26
- end
27
-
28
- %w(PostgreSQL Mysql Mysql2 SQLite).each do |adapter|
29
- begin
30
- require("active_record/connection_adapters/#{adapter.downcase}_adapter")
31
- adapter_class = ('ActiveRecord::ConnectionAdapters::' << "#{adapter}Adapter").constantize
32
- mc_class = ('MigrationComments::ActiveRecord::ConnectionAdapters::' << "#{adapter}Adapter").constantize
33
- adapter_class.module_eval do
34
- adapter_class.__send__(:include, mc_class)
35
- end
36
- rescue Exception => ex
37
- end
38
- end
39
-
40
- # annotations are not required for this gem, but if they exist they should be updated
41
- begin
42
- begin # first try to load from the 'annotate' gem
43
- require 'annotate/annotate_models'
44
- rescue Exception => ex
45
- # continue as it may be already accessible through a plugin
46
- end
47
- gem_class = AnnotateModels
48
- # don't require this until after the original AnnotateModels loads to avoid namespace confusion
49
- require 'migration_comments/annotate_models'
50
- mc_class = MigrationComments::AnnotateModels
51
- unless gem_class.ancestors.include?(mc_class)
52
- gem_class.__send__(:include, mc_class)
53
- end
54
- rescue Exception => ex
55
- # if we got here, don't bother installing comments into annotations
56
- end
57
- end
58
- end
59
-
1
+ require "migration_comments/version"
2
+
3
+ require 'migration_comments/active_record/schema_dumper'
4
+ require 'migration_comments/active_record/connection_adapters/comment_definition'
5
+ require 'migration_comments/active_record/connection_adapters/column_definition'
6
+ require 'migration_comments/active_record/connection_adapters/column'
7
+ require 'migration_comments/active_record/connection_adapters/table'
8
+ require 'migration_comments/active_record/connection_adapters/table_definition'
9
+ require 'migration_comments/active_record/connection_adapters/abstract_adapter'
10
+ require 'migration_comments/active_record/connection_adapters/mysql_adapter'
11
+ require 'migration_comments/active_record/connection_adapters/mysql2_adapter'
12
+ require 'migration_comments/active_record/connection_adapters/postgresql_adapter'
13
+ require 'migration_comments/active_record/connection_adapters/sqlite_adapter'
14
+
15
+ module MigrationComments
16
+ def self.setup
17
+ base_names = %w(SchemaDumper) +
18
+ %w(ColumnDefinition Column Table TableDefinition AbstractAdapter).map{|name| "ConnectionAdapters::#{name}"}
19
+
20
+ base_names.each do |base_name|
21
+ ar_class = "ActiveRecord::#{base_name}".constantize
22
+ mc_class = "MigrationComments::ActiveRecord::#{base_name}".constantize
23
+ unless ar_class.ancestors.include?(mc_class)
24
+ ar_class.__send__(:include, mc_class)
25
+ end
26
+ end
27
+
28
+ %w(PostgreSQL Mysql Mysql2 SQLite).each do |adapter|
29
+ begin
30
+ require("active_record/connection_adapters/#{adapter.downcase}_adapter")
31
+ adapter_class = ('ActiveRecord::ConnectionAdapters::' << "#{adapter}Adapter").constantize
32
+ mc_class = ('MigrationComments::ActiveRecord::ConnectionAdapters::' << "#{adapter}Adapter").constantize
33
+ adapter_class.module_eval do
34
+ adapter_class.__send__(:include, mc_class)
35
+ end
36
+ rescue Exception => ex
37
+ end
38
+ end
39
+
40
+ # annotations are not required for this gem, but if they exist they should be updated
41
+ begin
42
+ begin # first try to load from the 'annotate' gem
43
+ require 'annotate/annotate_models'
44
+ rescue Exception => ex
45
+ # continue as it may be already accessible through a plugin
46
+ end
47
+ gem_class = AnnotateModels
48
+ # don't require this until after the original AnnotateModels loads to avoid namespace confusion
49
+ require 'migration_comments/annotate_models'
50
+ mc_class = MigrationComments::AnnotateModels
51
+ unless gem_class.ancestors.include?(mc_class)
52
+ gem_class.__send__(:include, mc_class)
53
+ end
54
+ rescue Exception => ex
55
+ # if we got here, don't bother installing comments into annotations
56
+ end
57
+ end
58
+ end
59
+
60
60
  MigrationComments.setup
@@ -1,44 +1,44 @@
1
- module MigrationComments::ActiveRecord::ConnectionAdapters
2
- module AbstractAdapter
3
- def set_table_comment(table_name, comment_text)
4
- end
5
-
6
- def set_column_comment(table_name, column_name, comment_text)
7
- end
8
-
9
- def add_table_comment(*args)
10
- puts "'add_table_comment' is deprecated, and will be removed in future releases. Use 'set_table_comment' instead."
11
- set_table_comment(*args)
12
- end
13
- def add_column_comment(*args)
14
- puts "'add_column_comment' is deprecated, and will be removed in future releases. Use 'set_column_comment' instead."
15
- set_column_comment(*args)
16
- end
17
-
18
- def comments_supported?
19
- false
20
- end
21
-
22
- # Remove a comment on a table (if set)
23
- def remove_table_comment(table_name)
24
- set_table_comment(table_name, nil)
25
- end
26
-
27
- # Remove a comment on a column (if set)
28
- def remove_column_comment(table_name, column_name)
29
- set_column_comment(table_name, column_name, nil)
30
- end
31
-
32
- def retrieve_table_comment(table_name)
33
- nil
34
- end
35
-
36
- def retrieve_column_comments(table_name, *column_names)
37
- {}
38
- end
39
-
40
- def retrieve_column_comment(table_name, column_name)
41
- retrieve_column_comments(table_name, column_name)[column_name]
42
- end
43
- end
44
- end
1
+ module MigrationComments::ActiveRecord::ConnectionAdapters
2
+ module AbstractAdapter
3
+ def set_table_comment(table_name, comment_text)
4
+ end
5
+
6
+ def set_column_comment(table_name, column_name, comment_text)
7
+ end
8
+
9
+ def add_table_comment(*args)
10
+ puts "'add_table_comment' is deprecated, and will be removed in future releases. Use 'set_table_comment' instead."
11
+ set_table_comment(*args)
12
+ end
13
+ def add_column_comment(*args)
14
+ puts "'add_column_comment' is deprecated, and will be removed in future releases. Use 'set_column_comment' instead."
15
+ set_column_comment(*args)
16
+ end
17
+
18
+ def comments_supported?
19
+ false
20
+ end
21
+
22
+ # Remove a comment on a table (if set)
23
+ def remove_table_comment(table_name)
24
+ set_table_comment(table_name, nil)
25
+ end
26
+
27
+ # Remove a comment on a column (if set)
28
+ def remove_column_comment(table_name, column_name)
29
+ set_column_comment(table_name, column_name, nil)
30
+ end
31
+
32
+ def retrieve_table_comment(table_name)
33
+ nil
34
+ end
35
+
36
+ def retrieve_column_comments(table_name, *column_names)
37
+ {}
38
+ end
39
+
40
+ def retrieve_column_comment(table_name, column_name)
41
+ retrieve_column_comments(table_name, column_name)[column_name]
42
+ end
43
+ end
44
+ end
@@ -1,9 +1,9 @@
1
- module MigrationComments::ActiveRecord::ConnectionAdapters
2
- module Column
3
- def self.included(base)
4
- base.class_eval do
5
- attr_accessor :comment
6
- end
7
- end
8
- end
1
+ module MigrationComments::ActiveRecord::ConnectionAdapters
2
+ module Column
3
+ def self.included(base)
4
+ base.class_eval do
5
+ attr_accessor :comment
6
+ end
7
+ end
8
+ end
9
9
  end
@@ -1,5 +1,5 @@
1
- module MigrationComments::ActiveRecord::ConnectionAdapters
2
- module ColumnDefinition
3
- attr_accessor :comment
4
- end
1
+ module MigrationComments::ActiveRecord::ConnectionAdapters
2
+ module ColumnDefinition
3
+ attr_accessor :comment
4
+ end
5
5
  end
@@ -1,22 +1,22 @@
1
- module MigrationComments::ActiveRecord::ConnectionAdapters
2
- class CommentDefinition < Struct.new(:adapter, :table, :column_name, :comment_text)
3
- def to_dump
4
- table_comment? ?
5
- "set_table_comment :#{table_name}, %{#{comment_text}}" :
6
- "set_column_comment :#{table_name}, :#{column_name}, %{#{comment_text}}"
7
- end
8
-
9
- def to_sql
10
- adapter.comment_sql(self)
11
- end
12
- alias to_s :to_sql
13
-
14
- def table_comment?
15
- column_name.blank?
16
- end
17
-
18
- def table_name
19
- table.respond_to?(:name) ? table.name : table
20
- end
21
- end
1
+ module MigrationComments::ActiveRecord::ConnectionAdapters
2
+ class CommentDefinition < Struct.new(:adapter, :table, :column_name, :comment_text)
3
+ def to_dump
4
+ table_comment? ?
5
+ "set_table_comment :#{table_name}, %{#{comment_text}}" :
6
+ "set_column_comment :#{table_name}, :#{column_name}, %{#{comment_text}}"
7
+ end
8
+
9
+ def to_sql
10
+ adapter.comment_sql(self)
11
+ end
12
+ alias to_s :to_sql
13
+
14
+ def table_comment?
15
+ column_name.blank?
16
+ end
17
+
18
+ def table_name
19
+ table.respond_to?(:name) ? table.name : table
20
+ end
21
+ end
22
22
  end