pg_comment 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +22 -3
- data/lib/pg_comment/connection_adapters/abstract/schema_definitions.rb +10 -0
- data/lib/pg_comment/connection_adapters/abstract/schema_statements.rb +10 -0
- data/lib/pg_comment/connection_adapters/postgresql_adapter.rb +6 -0
- data/lib/pg_comment/version.rb +1 -1
- data/test/postgre_sql_adapter_test.rb +35 -9
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -6,9 +6,17 @@ Obviously, only the PostgreSQL adapter is supported.
|
|
6
6
|
|
7
7
|
== Warning
|
8
8
|
|
9
|
-
This is still experimental.
|
9
|
+
This is still somewhat experimental. It has to date been tested with:
|
10
10
|
|
11
|
-
|
11
|
+
* Ruby
|
12
|
+
- 1.8.7 REE
|
13
|
+
- 1.9.2 YARV
|
14
|
+
- JRuby 1.6.4
|
15
|
+
* Rails
|
16
|
+
- 3.0.10
|
17
|
+
- 3.1
|
18
|
+
|
19
|
+
All bug reports are welcome.
|
12
20
|
|
13
21
|
== Installation
|
14
22
|
|
@@ -18,12 +26,13 @@ Assuming you're using RubyGems:
|
|
18
26
|
|
19
27
|
== Usage
|
20
28
|
|
21
|
-
PgComment adds
|
29
|
+
PgComment adds five methods to migrations:
|
22
30
|
|
23
31
|
* set_table_comment(table_name, comment)
|
24
32
|
* remove_table_comment(table_name)
|
25
33
|
* set_column_comment(table_name, column_name, comment)
|
26
34
|
* remove_column_comment(table_name, column_name, comment)
|
35
|
+
* set_column_comments(table_name, comments)
|
27
36
|
|
28
37
|
Set a comment on the given table.
|
29
38
|
|
@@ -41,6 +50,11 @@ Removes any comment from the given column of a given table.
|
|
41
50
|
|
42
51
|
remove_column_comment :phone_numbers, :npa
|
43
52
|
|
53
|
+
Set comments on multiple columns in the table.
|
54
|
+
|
55
|
+
set_column_comments :phone_numbers, :npa => 'Numbering Plan Area Code - Allowed ranges: [2-9] for first digit, [0-9] for second and third digit.',
|
56
|
+
:nxx => 'Central Office Number'
|
57
|
+
|
44
58
|
PgComment also adds extra methods to change_table.
|
45
59
|
|
46
60
|
Set comments:
|
@@ -50,6 +64,11 @@ Set comments:
|
|
50
64
|
t.set_column_comment :npa, 'Numbering Plan Area Code - Allowed ranges: [2-9] for first digit, [0-9] for second and third digit.'
|
51
65
|
end
|
52
66
|
|
67
|
+
change_table :phone_numbers do |t|
|
68
|
+
t.set_column_comments :npa => 'Numbering Plan Area Code - Allowed ranges: [2-9] for first digit, [0-9] for second and third digit.',
|
69
|
+
:nxx => 'Central Office Number'
|
70
|
+
end
|
71
|
+
|
53
72
|
Remove comments:
|
54
73
|
|
55
74
|
change_table :phone_numbers do |t|
|
@@ -38,6 +38,16 @@ module PgComment
|
|
38
38
|
@base.set_column_comment(@table_name, column_name, comment)
|
39
39
|
end
|
40
40
|
|
41
|
+
# Sets comments on multiple columns. 'comments' is a hash of column_name => comment pairs.
|
42
|
+
#
|
43
|
+
# ===== Example
|
44
|
+
# ====== Setting comments on the columns of the phone_numbers table
|
45
|
+
# t.set_column_comments :npa => 'Numbering Plan Area Code - Allowed ranges: [2-9] for first digit, [0-9] for second and third digit.',
|
46
|
+
# :nxx => 'Central Office Number'
|
47
|
+
def set_column_comments(comments)
|
48
|
+
@base.set_column_comments(@table_name, comments)
|
49
|
+
end
|
50
|
+
|
41
51
|
# Removes any comment for a given column
|
42
52
|
#
|
43
53
|
# ===== Example
|
@@ -32,6 +32,16 @@ module PgComment
|
|
32
32
|
# Does nothing
|
33
33
|
end
|
34
34
|
|
35
|
+
# Sets comments on multiple columns. 'comments' is a hash of column_name => comment pairs.
|
36
|
+
#
|
37
|
+
# ===== Example
|
38
|
+
# ====== Setting comments on the columns of the phone_numbers table
|
39
|
+
# set_column_comments :phone_numbers, :npa => 'Numbering Plan Area Code - Allowed ranges: [2-9] for first digit, [0-9] for second and third digit.',
|
40
|
+
# :nxx => 'Central Office Number'
|
41
|
+
def set_column_comments(table_name, comments)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
35
45
|
# Removes any comment from the given table.
|
36
46
|
#
|
37
47
|
# ===== Example
|
@@ -15,6 +15,12 @@ module PgComment
|
|
15
15
|
execute sql
|
16
16
|
end
|
17
17
|
|
18
|
+
def set_column_comments(table_name, comments)
|
19
|
+
comments.each_pair do |column_name, comment|
|
20
|
+
set_column_comment table_name, column_name, comment
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
18
24
|
def remove_table_comment(table_name)
|
19
25
|
sql = "COMMENT ON TABLE #{quote_table_name(table_name)} IS NULL;"
|
20
26
|
execute sql
|
data/lib/pg_comment/version.rb
CHANGED
@@ -30,27 +30,53 @@ class PostgreSQLAdapterTest < Test::Unit::TestCase
|
|
30
30
|
include PgComment::ConnectionAdapters::PostgreSQLAdapter
|
31
31
|
end
|
32
32
|
|
33
|
+
def setup
|
34
|
+
@adapter = Adapter.new
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_table_comments_sql
|
38
|
+
expected = [ "COMMENT ON TABLE my_table IS $$table comment$$;",
|
39
|
+
"COMMENT ON TABLE my_table IS NULL;" ]
|
40
|
+
@adapter.set_table_comment :my_table, 'table comment'
|
41
|
+
@adapter.remove_table_comment :my_table
|
42
|
+
assert_equal expected, @adapter.buffer
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_column_comment_sql
|
46
|
+
expected = [ "COMMENT ON COLUMN my_table.my_column IS $$column comment$$;",
|
47
|
+
"COMMENT ON COLUMN my_table.my_column IS NULL;" ]
|
48
|
+
@adapter.set_column_comment :my_table, :my_column, 'column comment'
|
49
|
+
@adapter.remove_column_comment :my_table, :my_column
|
50
|
+
assert_equal expected, @adapter.buffer
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_column_comments_sql
|
54
|
+
expected = [ "COMMENT ON COLUMN my_table.column1 IS $$column comment 1$$;",
|
55
|
+
"COMMENT ON COLUMN my_table.column2 IS $$column comment 2$$;" ]
|
56
|
+
|
57
|
+
@adapter.set_column_comments :my_table, :column1 => 'column comment 1', :column2 => 'column comment 2'
|
58
|
+
assert_equal expected, @adapter.buffer
|
59
|
+
end
|
60
|
+
|
33
61
|
def test_sql_generation
|
34
62
|
expected = [ "COMMENT ON TABLE my_table IS $$table comment$$;",
|
35
63
|
"COMMENT ON COLUMN my_table.my_column IS $$column comment$$;",
|
36
64
|
"COMMENT ON TABLE my_table IS NULL;",
|
37
65
|
"COMMENT ON COLUMN my_table.my_column IS NULL;" ]
|
38
66
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
assert_equal expected, a.buffer
|
67
|
+
@adapter.set_table_comment :my_table, 'table comment'
|
68
|
+
@adapter.set_column_comment :my_table, :my_column, 'column comment'
|
69
|
+
@adapter.remove_table_comment :my_table
|
70
|
+
@adapter.remove_column_comment :my_table, :my_column
|
71
|
+
assert_equal expected, @adapter.buffer
|
45
72
|
end
|
46
73
|
|
47
74
|
def test_comments
|
48
|
-
a = Adapter.new
|
49
75
|
expected = [ { 'column_name' => nil, 'comment' => 'table comment' },
|
50
76
|
{ 'column_name' => 'column1', 'comment' => 'column comment 1' },
|
51
77
|
{ 'column_name' => 'column2', 'comment' => 'column comment 2' } ]
|
52
|
-
|
53
|
-
results =
|
78
|
+
@adapter.select_results = expected
|
79
|
+
results = @adapter.comments( nil )
|
54
80
|
assert_not_nil results
|
55
81
|
assert_equal 3, results.size, "Should have three comment rows."
|
56
82
|
results.each_with_index do |comment_row, index|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_comment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &7406540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *7406540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: test-unit
|
27
|
-
requirement: &
|
27
|
+
requirement: &7405880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *7405880
|
36
36
|
description: Extends Rails migrations to support setting column and table comments. Pulls
|
37
37
|
out comments into schema.rb
|
38
38
|
email:
|