activerecord-column_metadata 0.0.2 → 0.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## 0.0.3 (12 July 2013)
2
+
3
+ Add column_metadata(table_name, column_name, metadata) for use in migrations
4
+
5
+ ## 0.0.2 (12 July 2013)
6
+
7
+ Workaround for bundler namespace bug
8
+
9
+ ## 0.0.1 (12 July 2013)
10
+
11
+ Reading and writing column metadata
@@ -3,7 +3,7 @@ require 'json'
3
3
  module ActiveRecord
4
4
  class ColumnMetadata
5
5
  # Retrieves metadata stored in the database for +table_name+ as
6
- # [["col_name", {"key" => "val"}], ...]
6
+ # [["col_name", {"key" => "val"}], ...] ordered by col_name alphabetically
7
7
  def self.to_a(table_name)
8
8
  res = ActiveRecord::Base.connection.query(<<-END_SQL, 'Get comments')
9
9
  SELECT a.attname,
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  class ColumnMetadata
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -52,6 +52,10 @@ module ActiveRecord
52
52
  end
53
53
  alias_method_chain :add_column, :metadata
54
54
 
55
+ def column_metadata(table_name, column_name, metadata)
56
+ write_json_comment(table_name, column_name, metadata)
57
+ end
58
+
55
59
  def write_json_comment(table_name, column_name, comment)
56
60
  execute "COMMENT ON COLUMN #{quote_table_name(table_name)}.#{quote_column_name(column_name)} IS #{quote(comment.to_json)}"
57
61
  end
@@ -31,7 +31,7 @@ describe ActiveRecord::ColumnMetadata do
31
31
  add_column :people, :surname, :string, :metadata => {full_text_search: "double_metaphone"}
32
32
  end
33
33
  end
34
-
34
+
35
35
  describe 'write should add JSON in comment' do
36
36
  it 'with create_table' do
37
37
  CreateTableMigration.up
@@ -39,12 +39,25 @@ describe ActiveRecord::ColumnMetadata do
39
39
  expect(res).to include( ["name",'{"something":true}'])
40
40
  end
41
41
 
42
- it 'with add_collumn' do
42
+ it 'with add_column' do
43
43
  CreateTableMigration.up
44
44
  AddColumnMigration.up
45
45
  res = get_comments("people")
46
46
  expect(res).to include( ['surname', '{"full_text_search":"double_metaphone"}'])
47
47
  end
48
+
49
+ class AddColumnMetadataMigration < ActiveRecord::Migration
50
+ def self.up
51
+ column_metadata :people, :name, {completely: "different"}
52
+ end
53
+ end
54
+
55
+ it 'with add_column_metadata' do
56
+ CreateTableMigration.up
57
+ AddColumnMetadataMigration.up
58
+ res = get_comments("people")
59
+ expect(res).to include( ['name', '{"completely":"different"}'])
60
+ end
48
61
  end
49
62
 
50
63
  describe 'read' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-column_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -120,6 +120,7 @@ files:
120
120
  - .gitignore
121
121
  - .rspec
122
122
  - .travis.yml
123
+ - CHANGELOG.md
123
124
  - Gemfile
124
125
  - LICENSE.txt
125
126
  - README.md