migration_comments 0.1.2 → 0.1.3

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.
data/README.rdoc CHANGED
@@ -32,11 +32,8 @@ file.
32
32
  To add a comment to an existing structure...
33
33
 
34
34
  def self.up
35
- add_table_comment :table_name, "A table comment"
36
- comment_table :table_name, "A table comment" # does the same thing
37
-
38
- add_column_comment :table_name, :column_name, "A column comment"
39
- comment_column :table_name, :column_name, "A column comment" # does the same thing
35
+ set_table_comment :table_name, "A table comment"
36
+ set_column_comment :table_name, :column_name, "A column comment"
40
37
  end
41
38
 
42
39
  Or you can use the change_table macro...
@@ -1,16 +1,19 @@
1
1
  module MigrationComments::ActiveRecord::ConnectionAdapters
2
2
  module AbstractAdapter
3
- def add_table_comment(table_name, comment_text)
4
- # SQL standard doesn't support schema commenting
5
- raise "Table comments are not supported"
3
+ def set_table_comment(table_name, comment_text)
6
4
  end
7
- alias comment_table :add_table_comment
8
5
 
9
- def add_column_comment(table_name, column_name, comment_text)
10
- # SQL standard doesn't support schema commenting
11
- raise "Column comments are not supported"
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)
12
16
  end
13
- alias comment_column :add_column_comment
14
17
 
15
18
  def comments_supported?
16
19
  false
@@ -18,12 +21,12 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
18
21
 
19
22
  # Remove a comment on a table (if set)
20
23
  def remove_table_comment(table_name)
21
- add_table_comment(table_name, nil)
24
+ set_table_comment(table_name, nil)
22
25
  end
23
26
 
24
27
  # Remove a comment on a column (if set)
25
28
  def remove_column_comment(table_name, column_name)
26
- add_column_comment(table_name, column_name, nil)
29
+ set_column_comment(table_name, column_name, nil)
27
30
  end
28
31
 
29
32
  def retrieve_table_comment(table_name)
@@ -2,8 +2,8 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
2
2
  class CommentDefinition < Struct.new(:adapter, :table, :column_name, :comment_text)
3
3
  def to_dump
4
4
  table_comment? ?
5
- "add_table_comment :#{table_name}, %{#{comment_text}}" :
6
- "add_column_comment :#{table_name}, :#{column_name}, %{#{comment_text}}"
5
+ "set_table_comment :#{table_name}, %{#{comment_text}}" :
6
+ "set_column_comment :#{table_name}, :#{column_name}, %{#{comment_text}}"
7
7
  end
8
8
 
9
9
  def to_sql
@@ -8,11 +8,11 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
8
8
  end
9
9
  end
10
10
 
11
- def add_table_comment(table_name, comment_text)
11
+ def set_table_comment(table_name, comment_text)
12
12
  execute "ALTER TABLE #{table_name} COMMENT #{escaped_comment(comment_text)}"
13
13
  end
14
14
 
15
- def add_column_comment(table_name, column_name, comment_text)
15
+ def set_column_comment(table_name, column_name, comment_text)
16
16
  column = column_for(table_name, column_name)
17
17
  change_column table_name, column_name, column.sql_type, :comment => comment_text
18
18
  end
@@ -58,9 +58,9 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
58
58
 
59
59
  def execute_comment(comment_definition)
60
60
  if comment_definition.table_comment?
61
- add_table_comment comment_definition.table_name, comment_definition.comment_text
61
+ set_table_comment comment_definition.table_name, comment_definition.comment_text
62
62
  else
63
- add_column_comment comment_definition.table_name, comment_definition.column_name, comment_definition.comment_text
63
+ set_column_comment comment_definition.table_name, comment_definition.column_name, comment_definition.comment_text
64
64
  end
65
65
  end
66
66
 
@@ -13,12 +13,12 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
13
13
  end
14
14
 
15
15
  # Set a comment on a table
16
- def add_table_comment(table_name, comment_text)
16
+ def set_table_comment(table_name, comment_text)
17
17
  execute CommentDefinition.new(self, table_name, nil, comment_text).to_sql
18
18
  end
19
19
 
20
20
  # Set a comment on a column
21
- def add_column_comment(table_name, column_name, comment_text)
21
+ def set_column_comment(table_name, column_name, comment_text)
22
22
  execute CommentDefinition.new(self, table_name, column_name, comment_text).to_sql
23
23
  end
24
24
 
@@ -49,14 +49,14 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
49
49
  def add_column_with_migration_comments(table_name, column_name, type, options = {})
50
50
  add_column_without_migration_comments(table_name, column_name, type, options)
51
51
  if options[:comment]
52
- add_column_comment(table_name, column_name, options[:comment])
52
+ set_column_comment(table_name, column_name, options[:comment])
53
53
  end
54
54
  end
55
55
 
56
56
  def change_column_with_migration_comments(table_name, column_name, type, options = {})
57
57
  change_column_without_migration_comments(table_name, column_name, type, options)
58
58
  if options.keys.include?(:comment)
59
- add_column_comment(table_name, column_name, options[:comment])
59
+ set_column_comment(table_name, column_name, options[:comment])
60
60
  end
61
61
  end
62
62
 
@@ -8,11 +8,11 @@ module MigrationComments::ActiveRecord::ConnectionAdapters
8
8
  end
9
9
  end
10
10
 
11
- def add_table_comment(table_name, comment_text)
11
+ def set_table_comment(table_name, comment_text)
12
12
  alter_table(table_name, :comment => comment_text)
13
13
  end
14
14
 
15
- def add_column_comment(table_name, column_name, comment_text)
15
+ def set_column_comment(table_name, column_name, comment_text)
16
16
  column = column_for(table_name, column_name)
17
17
  change_column table_name, column_name, column.sql_type, :comment => comment_text
18
18
  end
@@ -1,11 +1,11 @@
1
1
  module MigrationComments::ActiveRecord::ConnectionAdapters
2
2
  module Table
3
3
  def change_comment(column_name, comment_text)
4
- @base.add_column_comment(@table_name, column_name, comment_text)
4
+ @base.set_column_comment(@table_name, column_name, comment_text)
5
5
  end
6
6
 
7
7
  def change_table_comment(comment_text)
8
- @base.add_table_comment(@table_name, comment_text)
8
+ @base.set_table_comment(@table_name, comment_text)
9
9
  end
10
10
  alias comment :change_table_comment
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module MigrationComments
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -7,7 +7,7 @@ class AddCommentsTest < Test::Unit::TestCase
7
7
  comment_text = "a comment on the sample table"
8
8
  result = nil
9
9
  ActiveRecord::Schema.define do
10
- add_table_comment :sample, comment_text
10
+ set_table_comment :sample, comment_text
11
11
  result = retrieve_table_comment :sample
12
12
  end
13
13
  assert_equal comment_text, result
@@ -18,7 +18,7 @@ class AddCommentsTest < Test::Unit::TestCase
18
18
  result_field1 = nil
19
19
  result_field2 = nil
20
20
  ActiveRecord::Schema.define do
21
- add_column_comment :sample, :field1, comment_text
21
+ set_column_comment :sample, :field1, comment_text
22
22
  result_field1 = retrieve_column_comment :sample, :field1
23
23
  result_field2 = retrieve_column_comment :sample, :field2
24
24
  end
@@ -104,7 +104,7 @@ class AddCommentsTest < Test::Unit::TestCase
104
104
  comment_text = "a comment on the sample table"
105
105
  result = nil
106
106
  ActiveRecord::Schema.define do
107
- add_table_comment :sample, comment_text
107
+ set_table_comment :sample, comment_text
108
108
  remove_table_comment :sample
109
109
  result = retrieve_table_comment :sample
110
110
  end
@@ -115,7 +115,7 @@ class AddCommentsTest < Test::Unit::TestCase
115
115
  comment_text = "a comment on field1 of sample table"
116
116
  result = nil
117
117
  ActiveRecord::Schema.define do
118
- add_column_comment :sample, :field1, comment_text
118
+ set_column_comment :sample, :field1, comment_text
119
119
  remove_column_comment :sample, :field1
120
120
  result = retrieve_column_comment :sample, :field1
121
121
  end
@@ -126,7 +126,7 @@ class AddCommentsTest < Test::Unit::TestCase
126
126
  comment_text = "a \"comment\" \\ that ' needs; escaping''"
127
127
  result = nil
128
128
  ActiveRecord::Schema.define do
129
- add_table_comment :sample, comment_text
129
+ set_table_comment :sample, comment_text
130
130
  result = retrieve_table_comment :sample
131
131
  end
132
132
  assert_equal comment_text, result
@@ -16,8 +16,8 @@ class AnnotateModelsTest < Test::Unit::TestCase
16
16
  ActiveRecord::Schema.define do
17
17
  db_type = :mysql if connection.is_a?(ActiveRecord::ConnectionAdapters::MysqlAdapter) rescue false
18
18
 
19
- add_table_comment :sample, "a table comment"
20
- add_column_comment :sample, :field1, "a \"comment\" \\ that ' needs; escaping''"
19
+ set_table_comment :sample, "a table comment"
20
+ set_column_comment :sample, :field1, "a \"comment\" \\ that ' needs; escaping''"
21
21
  add_column :sample, :field3, :string, :null => false, :default => '', :comment => "third column comment"
22
22
  end
23
23
 
@@ -8,8 +8,8 @@ class SchemaDumperTest < Test::Unit::TestCase
8
8
  ActiveRecord::Schema.define do
9
9
  db_type = :sqlite if connection.is_a?(ActiveRecord::ConnectionAdapters::SQLiteAdapter) rescue false
10
10
 
11
- add_table_comment :sample, "a table comment"
12
- add_column_comment :sample, :field1, "a \"comment\" \\ that ' needs; escaping''"
11
+ set_table_comment :sample, "a table comment"
12
+ set_column_comment :sample, :field1, "a \"comment\" \\ that ' needs; escaping''"
13
13
  add_column :sample, :field3, :string, :null => false, :default => "", :comment => "third column comment"
14
14
  end
15
15
  dest = StringIO.new
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migration_comments
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pinny