sequel-annotate 1.6.0 → 1.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42122bfc730bb5345c90160c5a17b0861c3a5a8308dfc6a008c1fccc0b73fe3e
4
- data.tar.gz: 7bbb33c84261d97a66c17b942c19fc0b432d4029b8e384f148ec79ddf96c196e
3
+ metadata.gz: 1af766f00a25bee67411ffb02da42718bfca2a4f6da4054470916559f03af2fd
4
+ data.tar.gz: 798ae4e7a20c53d3114358aff783ce97f2ad43f4ee66044b1df3f6ebcafa5b33
5
5
  SHA512:
6
- metadata.gz: 4ee1e34b6317be4e57f113a33e47c83190157ee3cbbae9cfd209c8806895aacc5e44604bbf2f0cfcbee1114a8822ed0c36a9ccdad628cb66daab58873d9020b8
7
- data.tar.gz: d27e5074fb1c7642993647185605d0d714482d1f9ce5bc9e7b58817872f69674d0e803fa68210d0d73b2c176a479a44224a3678c602b1681116acae8dbf16d8c
6
+ metadata.gz: a1bb2645eaf30455d1a55eaf79cd50d7410544d5de75db501ba5d62523d2de8b0d12464291b887fd7c0b7a34adf3622231c6ca81e2ad70f23ae1a923773ccfd8
7
+ data.tar.gz: b57d33307b4295bf3a120d162ea1850cf008092ca21e16127e2cf07874d49dc35df18b44b57512aaea9ac6255ce694ba3cdd3004a3dde90282fc7c6b69b39fe3
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.7.0 (2021-05-20)
2
+
3
+ * Add support for table comments on PostgreSQL (TSMMark) (#21)
4
+
1
5
  === 1.6.0 (2020-10-05)
2
6
 
3
7
  * Add support for :namespace=>true option to attempt to automatically determine namespace (adam12) (#20)
data/Rakefile CHANGED
@@ -17,6 +17,17 @@ end
17
17
 
18
18
  task :default => :spec
19
19
 
20
+ desc "Run specs in CI"
21
+ task :spec_ci do
22
+ ENV['SEQUEL_ANNOTATE_SPEC_CI'] = '1'
23
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
24
+ ENV['SEQUEL_ANNOTATE_SPEC_POSTGRES_URL'] = "jdbc:postgresql://localhost/?user=postgres"
25
+ else
26
+ ENV['SEQUEL_ANNOTATE_SPEC_POSTGRES_URL'] = "postgres://localhost/?user=postgres"
27
+ end
28
+ Rake::Task['spec'].invoke
29
+ end
30
+
20
31
  ### RDoc
21
32
 
22
33
  RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'sequel-annotate: Annotate Sequel models with schema information']
@@ -147,6 +147,7 @@ module Sequel
147
147
  # Use the standard columns schema output, but use PostgreSQL specific
148
148
  # code for additional schema information.
149
149
  def _schema_comment_postgres(output, options = {})
150
+ _table_comment_postgres(output, options)
150
151
  schema_comment_columns(output, options)
151
152
  oid = model.db.send(:regclass_oid, model.table_name)
152
153
 
@@ -204,7 +205,7 @@ SQL
204
205
 
205
206
  unless options[:references] == false
206
207
  rows = model.db.fetch(<<SQL, :oid=>oid).all
207
- SELECT conname, conrelid::pg_catalog.regclass,
208
+ SELECT conname, conrelid::pg_catalog.regclass::text,
208
209
  pg_catalog.pg_get_constraintdef(c.oid, true) as condef
209
210
  FROM pg_catalog.pg_constraint c
210
211
  WHERE c.confrelid = :oid AND c.contype = 'f' ORDER BY 2, 1;
@@ -244,6 +245,18 @@ WHERE d.objoid = :oid AND COALESCE(d.description, '') != '';
244
245
  SQL
245
246
  end
246
247
 
248
+ def _table_comment_postgres(output, options = {})
249
+ return if options[:comments] == false
250
+
251
+ if table_comment = model.db.fetch(<<SQL, :oid=>model.db.send(:regclass_oid, model.table_name)).single_value
252
+ SELECT obj_description(CAST(:oid AS regclass), 'pg_class') AS "comment" LIMIT 1;
253
+ SQL
254
+ text = align([["Comment: #{table_comment}"]])
255
+ text[0][1] = ''
256
+ output.concat(text)
257
+ end
258
+ end
259
+
247
260
  # The standard column schema information to output.
248
261
  def schema_comment_columns(output, options = {})
249
262
  if cpk = model.primary_key.is_a?(Array)
@@ -7,7 +7,9 @@ gem 'minitest'
7
7
  require 'minitest/global_expectations/autorun'
8
8
 
9
9
  DB = Sequel.connect(ENV['SEQUEL_ANNOTATE_SPEC_POSTGRES_URL'] || 'postgres:///sequel_annotate_test?user=sequel_annotate&password=sequel_annotate')
10
- raise "test database name doesn't end with test" unless DB.get{current_database.function} =~ /test\z/
10
+ unless ENV['SEQUEL_ANNOTATE_SPEC_CI'] == '1' || DB.get{current_database.function} =~ /test\z/
11
+ raise "test database name doesn't end with test"
12
+ end
11
13
  if defined?(JRUBY_VERSION)
12
14
  SDB = Sequel.connect('jdbc:sqlite::memory:')
13
15
  else
@@ -83,6 +85,7 @@ DB.create_table :comment_tests do
83
85
  end
84
86
 
85
87
  DB.run "COMMENT ON COLUMN comment_tests.name IS 'name column comment'"
88
+ DB.run "COMMENT ON TABLE comment_tests IS 'comment_tests table comment'"
86
89
 
87
90
  Minitest.after_run do
88
91
  DB.drop_table(:items, :manufacturers, :categories, :domain_tests, :comment_tests)
@@ -301,6 +304,7 @@ OUTPUT
301
304
 
302
305
  Sequel::Annotate.new(CommentTest).schema_comment.must_equal(fix_pg_comment((<<OUTPUT).chomp))
303
306
  # Table: comment_tests
307
+ # Comment: comment_tests table comment
304
308
  # Columns:
305
309
  # id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY |
306
310
  # name | text | | name column comment
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-annotate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-05 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  requirements: []
174
- rubygems_version: 3.1.4
174
+ rubygems_version: 3.2.15
175
175
  signing_key:
176
176
  specification_version: 4
177
177
  summary: Annotate Sequel models with schema information