sequel-annotate 1.3.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 +4 -4
- data/CHANGELOG +34 -0
- data/README.rdoc +16 -1
- data/Rakefile +13 -10
- data/lib/sequel/annotate.rb +138 -45
- data/spec/annotated_after/scomplexdataset.rb +7 -0
- data/spec/annotated_after/sitemwithcoding.rb +20 -0
- data/spec/annotated_after/sitemwithencoding.rb +20 -0
- data/spec/annotated_after/sitemwithfrozenliteral.rb +20 -0
- data/spec/annotated_after/sitemwithwarnindent.rb +20 -0
- data/spec/annotated_after/sitemwithwarnpastscope.rb +21 -0
- data/spec/annotated_before/scomplexdataset.rb +7 -0
- data/spec/annotated_before/sitemwithcoding.rb +20 -0
- data/spec/annotated_before/sitemwithencoding.rb +20 -0
- data/spec/annotated_before/sitemwithfrozenliteral.rb +20 -0
- data/spec/annotated_before/sitemwithwarnindent.rb +20 -0
- data/spec/annotated_before/sitemwithwarnpastscope.rb +21 -0
- data/spec/sequel-annotate_spec.rb +145 -7
- data/spec/unannotated/not_model.rb +4 -0
- data/spec/unannotated/scomplexdataset.rb +7 -0
- data/spec/unannotated/sitemwithcoding.rb +4 -0
- data/spec/unannotated/sitemwithencoding.rb +4 -0
- data/spec/unannotated/sitemwithfrozenliteral.rb +4 -0
- data/spec/unannotated/sitemwithmagiccomment.rb +4 -0
- data/spec/unannotated/sitemwithwarnindent.rb +4 -0
- data/spec/unannotated/sitemwithwarnpastscope.rb +5 -0
- metadata +42 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1af766f00a25bee67411ffb02da42718bfca2a4f6da4054470916559f03af2fd
|
4
|
+
data.tar.gz: 798ae4e7a20c53d3114358aff783ce97f2ad43f4ee66044b1df3f6ebcafa5b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1bb2645eaf30455d1a55eaf79cd50d7410544d5de75db501ba5d62523d2de8b0d12464291b887fd7c0b7a34adf3622231c6ca81e2ad70f23ae1a923773ccfd8
|
7
|
+
data.tar.gz: b57d33307b4295bf3a120d162ea1850cf008092ca21e16127e2cf07874d49dc35df18b44b57512aaea9ac6255ce694ba3cdd3004a3dde90282fc7c6b69b39fe3
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
=== 1.7.0 (2021-05-20)
|
2
|
+
|
3
|
+
* Add support for table comments on PostgreSQL (TSMMark) (#21)
|
4
|
+
|
5
|
+
=== 1.6.0 (2020-10-05)
|
6
|
+
|
7
|
+
* Add support for :namespace=>true option to attempt to automatically determine namespace (adam12) (#20)
|
8
|
+
|
9
|
+
* Skip models that select from a subquery (adam12, jeremyevans) (#17)
|
10
|
+
|
11
|
+
* Allow files to be skipped with sequel-annotate: false magic comment (adam12) (#18)
|
12
|
+
|
13
|
+
* Ignore opening of singleton classes with class << when looking for models (adam12) (#16)
|
14
|
+
|
15
|
+
=== 1.5.0 (2020-05-04)
|
16
|
+
|
17
|
+
* Add support for magic comments in model files when using the :position=>:before option (qortex, jeremyevans) (#15)
|
18
|
+
|
19
|
+
* Add support for PostgreSQL column comments (rgalanakis, jeremyevans) (#14)
|
20
|
+
|
21
|
+
* Respect domain types on PostgreSQL (chanks) (#13)
|
22
|
+
|
23
|
+
* Make schema comments handle table names that aren't just symbols (chanks) (#12)
|
24
|
+
|
25
|
+
=== 1.4.0 (2018-11-15)
|
26
|
+
|
27
|
+
* Support adding borders to the beginning and end of comments via :border option (kreynolds) (#9)
|
28
|
+
|
29
|
+
* Support excluding indexes, constraints, and triggers from annotation via options (kreynolds) (#9)
|
30
|
+
|
31
|
+
=== 1.3.1 (2018-09-27)
|
32
|
+
|
33
|
+
* Make sure all annotation lines are commented by handling newlines inside annotations (jeremyevans)
|
34
|
+
|
1
35
|
=== 1.3.0 (2018-07-17)
|
2
36
|
|
3
37
|
* Support :namespace option to specify namespace to add for models nested in namespaces (jeremyevans)
|
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@ default, it includes information on columns, indexes, and foreign key
|
|
5
5
|
constraints for the current table.
|
6
6
|
|
7
7
|
On PostgreSQL, this includes more advanced information, including
|
8
|
-
check constraints, triggers, and foreign keys constraints for other
|
8
|
+
check constraints, triggers, comments, and foreign keys constraints for other
|
9
9
|
tables that reference the current table.
|
10
10
|
|
11
11
|
== Example
|
@@ -83,6 +83,21 @@ Then you can use the +:namespace+ option to set the namespace to use:
|
|
83
83
|
|
84
84
|
Sequel::Annotate.annotate(Dir['models/*.rb'], namespace: 'ModelNamespace')
|
85
85
|
|
86
|
+
For PostgreSQL, you can optionally leave out indexes, foreign_keys, references,
|
87
|
+
triggers, comments, and constraints by passing in false as a parameter as follows:
|
88
|
+
|
89
|
+
Sequel::Annotate.annotate(Dir['models/*.rb'], foreign_keys: false,
|
90
|
+
:indexes: false, constraints: false, comments: false)
|
91
|
+
|
92
|
+
The columns section can have a border on the top and bottom for easier visual distinction by setting the :border option to true
|
93
|
+
|
94
|
+
Sequel::Annotate.annotate(Dir['models/*.rb'], border: true)
|
95
|
+
|
96
|
+
Models that use datasets that select from subqueries are automatically skipped,
|
97
|
+
as annotations don't really make sense for them since they are not backed by a
|
98
|
+
table. You can skip other models by using a <tt># sequel-annotate: false</tt>
|
99
|
+
magic comment somewhere in the file.
|
100
|
+
|
86
101
|
=== Rake Task
|
87
102
|
|
88
103
|
Here's an example rake task for sequel-annotate:
|
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']
|
@@ -28,19 +39,11 @@ begin
|
|
28
39
|
rescue Gem::LoadError
|
29
40
|
end
|
30
41
|
|
31
|
-
rdoc_task_class = begin
|
32
|
-
require "rdoc/task"
|
33
|
-
RDoc::Task
|
34
|
-
rescue LoadError
|
35
|
-
require "rake/rdoctask"
|
36
|
-
Rake::RDocTask
|
37
|
-
end
|
38
|
-
|
39
42
|
RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
|
40
43
|
|
41
|
-
|
44
|
+
require "rdoc/task"
|
45
|
+
RDoc::Task.new do |rdoc|
|
42
46
|
rdoc.rdoc_dir = "rdoc"
|
43
47
|
rdoc.options += RDOC_OPTS
|
44
48
|
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
|
45
49
|
end
|
46
|
-
|
data/lib/sequel/annotate.rb
CHANGED
@@ -13,11 +13,22 @@ module Sequel
|
|
13
13
|
namespace = options[:namespace]
|
14
14
|
|
15
15
|
paths.each do |path|
|
16
|
-
|
16
|
+
text = File.read(path)
|
17
|
+
|
18
|
+
next if text.match(/^#\s+sequel-annotate:\s+false$/i)
|
19
|
+
|
20
|
+
name = nil
|
21
|
+
if namespace == true
|
22
|
+
constants = text.scan(/\bmodule ([^\s]+)|class ([^\s<]+)\s*</).flatten.compact
|
23
|
+
name = constants.join("::") if constants.any?
|
24
|
+
elsif match = text.match(/class ([^\s<]+)\s*</)
|
17
25
|
name = match[1]
|
18
26
|
if namespace
|
19
27
|
name = "#{namespace}::#{name}"
|
20
28
|
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if name
|
21
32
|
klass = name.constantize
|
22
33
|
if klass.ancestors.include?(Sequel::Model)
|
23
34
|
new(klass).annotate(path, options)
|
@@ -37,11 +48,18 @@ module Sequel
|
|
37
48
|
# Append the schema comment (or replace it if one already exists) to
|
38
49
|
# the file at the given path.
|
39
50
|
def annotate(path, options = {})
|
51
|
+
return if skip_model?
|
52
|
+
|
40
53
|
orig = current = File.read(path).rstrip
|
41
54
|
|
42
55
|
if options[:position] == :before
|
56
|
+
if current =~ /\A((?:^\s*$|^#\s*(?:frozen_string_literal|coding|encoding|warn_indent|warn_past_scope)[^\n]*\s*)*)/m
|
57
|
+
magic_comments = $1
|
58
|
+
current.slice!(0, magic_comments.length)
|
59
|
+
end
|
60
|
+
|
43
61
|
current = current.gsub(/\A#\sTable[^\n\r]+\r?\n(?:#[^\n\r]*\r?\n)*/m, '').lstrip
|
44
|
-
current = "#{schema_comment}#{$/}#{$/}#{current}"
|
62
|
+
current = "#{magic_comments}#{schema_comment(options)}#{$/}#{$/}#{current}"
|
45
63
|
else
|
46
64
|
if m = current.reverse.match(/#{"#{$/}# Table: ".reverse}/m)
|
47
65
|
offset = current.length - m.end(0) + 1
|
@@ -52,7 +70,7 @@ module Sequel
|
|
52
70
|
current = current[0...offset].rstrip
|
53
71
|
end
|
54
72
|
end
|
55
|
-
current += "#{$/}#{$/}#{schema_comment}"
|
73
|
+
current += "#{$/}#{$/}#{schema_comment(options)}"
|
56
74
|
end
|
57
75
|
|
58
76
|
if orig != current
|
@@ -67,17 +85,38 @@ module Sequel
|
|
67
85
|
# key constraints in this table referencing other tables.
|
68
86
|
# On PostgreSQL, also includes check constraints, triggers,
|
69
87
|
# and foreign key constraints in other tables referencing this table.
|
70
|
-
|
88
|
+
#
|
89
|
+
# Options:
|
90
|
+
# :border :: Include a border above and below the comment.
|
91
|
+
# :indexes :: Do not include indexes in annotation if set to +false+.
|
92
|
+
# :foreign_keys :: Do not include foreign key constraints in annotation if set to +false+.
|
93
|
+
#
|
94
|
+
# PostgreSQL-specific options:
|
95
|
+
# :constraints :: Do not include check constraints if set to +false+.
|
96
|
+
# :references :: Do not include foreign key constraints in other tables referencing
|
97
|
+
# this table if set to +false+.
|
98
|
+
# :triggers :: Do not include triggers in annotation if set to +false+.
|
99
|
+
def schema_comment(options = {})
|
100
|
+
return "" if skip_model?
|
101
|
+
|
71
102
|
output = []
|
72
|
-
output << "# Table: #{model.table_name}"
|
103
|
+
output << "# Table: #{model.dataset.with_quote_identifiers(false).literal(model.table_name)}"
|
73
104
|
|
74
105
|
meth = :"_schema_comment_#{model.db.database_type}"
|
75
106
|
if respond_to?(meth, true)
|
76
|
-
send(meth, output)
|
107
|
+
send(meth, output, options)
|
77
108
|
else
|
78
109
|
schema_comment_columns(output)
|
79
|
-
schema_comment_indexes(output)
|
80
|
-
schema_comment_foreign_keys(output)
|
110
|
+
schema_comment_indexes(output) unless options[:indexes] == false
|
111
|
+
schema_comment_foreign_keys(output) unless options[:foreign_keys] == false
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
# Add beginning and end to the table if specified
|
116
|
+
if options[:border]
|
117
|
+
border = "# #{'-' * (output.map(&:size).max - 2)}"
|
118
|
+
output.push(border)
|
119
|
+
output.insert(1, border)
|
81
120
|
end
|
82
121
|
|
83
122
|
output.join($/)
|
@@ -96,105 +135,151 @@ module Sequel
|
|
96
135
|
|
97
136
|
cols.times do |i|
|
98
137
|
rows.each do |r|
|
99
|
-
lengths[i] = r[i].length if r[i].length > lengths[i]
|
138
|
+
lengths[i] = r[i].length if r[i] && r[i].length > lengths[i]
|
100
139
|
end
|
101
140
|
end
|
102
141
|
|
103
142
|
rows.map do |r|
|
104
|
-
"# #{r.zip(lengths).map{|c, l| c.ljust(l)}.join(' | ')}".strip
|
143
|
+
"# #{r.zip(lengths).map{|c, l| c.to_s.ljust(l).gsub("\n", "\n# ")}.join(' | ')}".strip
|
105
144
|
end
|
106
145
|
end
|
107
146
|
|
108
147
|
# Use the standard columns schema output, but use PostgreSQL specific
|
109
148
|
# code for additional schema information.
|
110
|
-
def _schema_comment_postgres(output)
|
111
|
-
|
149
|
+
def _schema_comment_postgres(output, options = {})
|
150
|
+
_table_comment_postgres(output, options)
|
151
|
+
schema_comment_columns(output, options)
|
112
152
|
oid = model.db.send(:regclass_oid, model.table_name)
|
113
153
|
|
114
154
|
# These queries below are all based on the queries that psql
|
115
155
|
# uses, captured using the -E option to psql.
|
116
156
|
|
117
|
-
|
157
|
+
unless options[:indexes] == false
|
158
|
+
rows = model.db.fetch(<<SQL, :oid=>oid).all
|
118
159
|
SELECT c2.relname, i.indisprimary, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)
|
119
160
|
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
|
120
161
|
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))
|
121
162
|
WHERE c.oid = :oid AND c.oid = i.indrelid AND i.indexrelid = c2.oid AND indisvalid
|
122
163
|
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname;
|
123
164
|
SQL
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
165
|
+
unless rows.empty?
|
166
|
+
output << "# Indexes:"
|
167
|
+
rows = rows.map do |r|
|
168
|
+
[r[:relname], "#{"PRIMARY KEY " if r[:indisprimary]}#{"UNIQUE " if r[:indisunique] && !r[:indisprimary]}#{r[:pg_get_indexdef].match(/USING (.+)\z/m)[1]}"]
|
169
|
+
end
|
170
|
+
output.concat(align(rows))
|
128
171
|
end
|
129
|
-
output.concat(align(rows))
|
130
172
|
end
|
131
173
|
|
132
|
-
|
174
|
+
unless options[:constraints] == false
|
175
|
+
rows = model.db.fetch(<<SQL, :oid=>oid).all
|
133
176
|
SELECT r.conname, pg_catalog.pg_get_constraintdef(r.oid, true)
|
134
177
|
FROM pg_catalog.pg_constraint r
|
135
178
|
WHERE r.conrelid = :oid AND r.contype = 'c'
|
136
179
|
ORDER BY 1;
|
137
180
|
SQL
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
181
|
+
unless rows.empty?
|
182
|
+
output << "# Check constraints:"
|
183
|
+
rows = rows.map do |r|
|
184
|
+
[r[:conname], r[:pg_get_constraintdef].match(/CHECK (.+)\z/m)[1]]
|
185
|
+
end
|
186
|
+
output.concat(align(rows))
|
142
187
|
end
|
143
|
-
output.concat(align(rows))
|
144
188
|
end
|
145
189
|
|
146
|
-
|
190
|
+
unless options[:foreign_keys] == false
|
191
|
+
rows = model.db.fetch(<<SQL, :oid=>oid).all
|
147
192
|
SELECT conname,
|
148
193
|
pg_catalog.pg_get_constraintdef(r.oid, true) as condef
|
149
194
|
FROM pg_catalog.pg_constraint r
|
150
195
|
WHERE r.conrelid = :oid AND r.contype = 'f' ORDER BY 1;
|
151
196
|
SQL
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
197
|
+
unless rows.empty?
|
198
|
+
output << "# Foreign key constraints:"
|
199
|
+
rows = rows.map do |r|
|
200
|
+
[r[:conname], r[:condef].match(/FOREIGN KEY (.+)\z/m)[1]]
|
201
|
+
end
|
202
|
+
output.concat(align(rows))
|
156
203
|
end
|
157
|
-
output.concat(align(rows))
|
158
204
|
end
|
159
205
|
|
160
|
-
|
161
|
-
|
206
|
+
unless options[:references] == false
|
207
|
+
rows = model.db.fetch(<<SQL, :oid=>oid).all
|
208
|
+
SELECT conname, conrelid::pg_catalog.regclass::text,
|
162
209
|
pg_catalog.pg_get_constraintdef(c.oid, true) as condef
|
163
210
|
FROM pg_catalog.pg_constraint c
|
164
211
|
WHERE c.confrelid = :oid AND c.contype = 'f' ORDER BY 2, 1;
|
165
212
|
SQL
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
213
|
+
unless rows.empty?
|
214
|
+
output << "# Referenced By:"
|
215
|
+
rows = rows.map do |r|
|
216
|
+
[r[:conrelid], r[:conname], r[:condef].match(/FOREIGN KEY (.+)\z/m)[1]]
|
217
|
+
end
|
218
|
+
output.concat(align(rows))
|
170
219
|
end
|
171
|
-
output.concat(align(rows))
|
172
220
|
end
|
173
221
|
|
174
|
-
|
222
|
+
unless options[:triggers] == false
|
223
|
+
rows = model.db.fetch(<<SQL, :oid=>oid).all
|
175
224
|
SELECT t.tgname, pg_catalog.pg_get_triggerdef(t.oid, true), t.tgenabled, t.tgisinternal
|
176
225
|
FROM pg_catalog.pg_trigger t
|
177
226
|
WHERE t.tgrelid = :oid AND (NOT t.tgisinternal OR (t.tgisinternal AND t.tgenabled = 'D'))
|
178
227
|
ORDER BY 1;
|
179
228
|
SQL
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
229
|
+
unless rows.empty?
|
230
|
+
output << "# Triggers:"
|
231
|
+
rows = rows.map do |r|
|
232
|
+
[r[:tgname], r[:pg_get_triggerdef].match(/((?:BEFORE|AFTER) .+)\z/m)[1]]
|
233
|
+
end
|
234
|
+
output.concat(align(rows))
|
184
235
|
end
|
185
|
-
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def _column_comments_postgres
|
240
|
+
model.db.fetch(<<SQL, :oid=>model.db.send(:regclass_oid, model.table_name)).to_hash(:attname, :description)
|
241
|
+
SELECT a.attname, d.description
|
242
|
+
FROM pg_description d
|
243
|
+
JOIN pg_attribute a ON (d.objoid = a.attrelid AND d.objsubid = a.attnum)
|
244
|
+
WHERE d.objoid = :oid AND COALESCE(d.description, '') != '';
|
245
|
+
SQL
|
246
|
+
end
|
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)
|
186
257
|
end
|
187
258
|
end
|
188
259
|
|
189
260
|
# The standard column schema information to output.
|
190
|
-
def schema_comment_columns(output)
|
261
|
+
def schema_comment_columns(output, options = {})
|
191
262
|
if cpk = model.primary_key.is_a?(Array)
|
192
263
|
output << "# Primary Key: (#{model.primary_key.join(', ')})"
|
193
264
|
end
|
194
265
|
output << "# Columns:"
|
266
|
+
|
267
|
+
meth = :"_column_comments_#{model.db.database_type}"
|
268
|
+
column_comments = if options[:comments] != false && respond_to?(meth, true)
|
269
|
+
send(meth)
|
270
|
+
else
|
271
|
+
{}
|
272
|
+
end
|
273
|
+
|
195
274
|
rows = model.columns.map do |col|
|
196
275
|
sch = model.db_schema[col]
|
197
|
-
|
276
|
+
parts = [
|
277
|
+
col.to_s,
|
278
|
+
sch[:db_domain_type] || sch[:db_type],
|
279
|
+
"#{"PRIMARY KEY #{"AUTOINCREMENT " if sch[:auto_increment] && model.db.database_type != :postgres}" if sch[:primary_key] && !cpk}#{"NOT NULL " if sch[:allow_null] == false && !sch[:primary_key]}#{"DEFAULT #{sch[:default]}" if sch[:default]}#{"GENERATED BY DEFAULT AS IDENTITY" if sch[:auto_increment] && !sch[:default] && model.db.database_type == :postgres && model.db.server_version >= 100000}",
|
280
|
+
]
|
281
|
+
parts << (column_comments[col.to_s] || '') unless column_comments.empty?
|
282
|
+
parts
|
198
283
|
end
|
199
284
|
output.concat(align(rows))
|
200
285
|
end
|
@@ -220,5 +305,13 @@ SQL
|
|
220
305
|
output.concat(align(rows).sort)
|
221
306
|
end
|
222
307
|
end
|
308
|
+
|
309
|
+
# Whether we should skip annotations for the model.
|
310
|
+
# True if the model selects from a dataset.
|
311
|
+
def skip_model?
|
312
|
+
model.dataset.joined_dataset? || model.dataset.first_source_table.is_a?(Dataset)
|
313
|
+
rescue Sequel::Error
|
314
|
+
true
|
315
|
+
end
|
223
316
|
end
|
224
317
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: xyz
|
2
|
+
|
3
|
+
class SItemWithCoding < Sequel::Model(SDB[:items])
|
4
|
+
end
|
5
|
+
|
6
|
+
# Table: items
|
7
|
+
# Columns:
|
8
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
9
|
+
# category_id | integer | NOT NULL
|
10
|
+
# manufacturer_name | varchar(50) |
|
11
|
+
# manufacturer_location | varchar(255) |
|
12
|
+
# in_stock | boolean | DEFAULT 0
|
13
|
+
# name | varchar(255) | DEFAULT 'John'
|
14
|
+
# price | double precision | DEFAULT 0
|
15
|
+
# Indexes:
|
16
|
+
# manufacturer_name | (manufacturer_name)
|
17
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
18
|
+
# Foreign key constraints:
|
19
|
+
# (category_id) REFERENCES categories
|
20
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class SItemWithEncoding < Sequel::Model(SDB[:items])
|
4
|
+
end
|
5
|
+
|
6
|
+
# Table: items
|
7
|
+
# Columns:
|
8
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
9
|
+
# category_id | integer | NOT NULL
|
10
|
+
# manufacturer_name | varchar(50) |
|
11
|
+
# manufacturer_location | varchar(255) |
|
12
|
+
# in_stock | boolean | DEFAULT 0
|
13
|
+
# name | varchar(255) | DEFAULT 'John'
|
14
|
+
# price | double precision | DEFAULT 0
|
15
|
+
# Indexes:
|
16
|
+
# manufacturer_name | (manufacturer_name)
|
17
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
18
|
+
# Foreign key constraints:
|
19
|
+
# (category_id) REFERENCES categories
|
20
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SItemWithFrozenLiteral < Sequel::Model(SDB[:items])
|
4
|
+
end
|
5
|
+
|
6
|
+
# Table: items
|
7
|
+
# Columns:
|
8
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
9
|
+
# category_id | integer | NOT NULL
|
10
|
+
# manufacturer_name | varchar(50) |
|
11
|
+
# manufacturer_location | varchar(255) |
|
12
|
+
# in_stock | boolean | DEFAULT 0
|
13
|
+
# name | varchar(255) | DEFAULT 'John'
|
14
|
+
# price | double precision | DEFAULT 0
|
15
|
+
# Indexes:
|
16
|
+
# manufacturer_name | (manufacturer_name)
|
17
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
18
|
+
# Foreign key constraints:
|
19
|
+
# (category_id) REFERENCES categories
|
20
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# warn_indent: true
|
2
|
+
|
3
|
+
class SItemWithWarnIndent < Sequel::Model(SDB[:items])
|
4
|
+
end
|
5
|
+
|
6
|
+
# Table: items
|
7
|
+
# Columns:
|
8
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
9
|
+
# category_id | integer | NOT NULL
|
10
|
+
# manufacturer_name | varchar(50) |
|
11
|
+
# manufacturer_location | varchar(255) |
|
12
|
+
# in_stock | boolean | DEFAULT 0
|
13
|
+
# name | varchar(255) | DEFAULT 'John'
|
14
|
+
# price | double precision | DEFAULT 0
|
15
|
+
# Indexes:
|
16
|
+
# manufacturer_name | (manufacturer_name)
|
17
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
18
|
+
# Foreign key constraints:
|
19
|
+
# (category_id) REFERENCES categories
|
20
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# warn_past_scope: true
|
2
|
+
# warn_indent: false
|
3
|
+
# Additional comment that should stay
|
4
|
+
class SItemWithWarnPastScope < Sequel::Model(SDB[:items])
|
5
|
+
end
|
6
|
+
|
7
|
+
# Table: items
|
8
|
+
# Columns:
|
9
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
10
|
+
# category_id | integer | NOT NULL
|
11
|
+
# manufacturer_name | varchar(50) |
|
12
|
+
# manufacturer_location | varchar(255) |
|
13
|
+
# in_stock | boolean | DEFAULT 0
|
14
|
+
# name | varchar(255) | DEFAULT 'John'
|
15
|
+
# price | double precision | DEFAULT 0
|
16
|
+
# Indexes:
|
17
|
+
# manufacturer_name | (manufacturer_name)
|
18
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
19
|
+
# Foreign key constraints:
|
20
|
+
# (category_id) REFERENCES categories
|
21
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: xyz
|
2
|
+
|
3
|
+
# Table: items
|
4
|
+
# Columns:
|
5
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
6
|
+
# category_id | integer | NOT NULL
|
7
|
+
# manufacturer_name | varchar(50) |
|
8
|
+
# manufacturer_location | varchar(255) |
|
9
|
+
# in_stock | boolean | DEFAULT 0
|
10
|
+
# name | varchar(255) | DEFAULT 'John'
|
11
|
+
# price | double precision | DEFAULT 0
|
12
|
+
# Indexes:
|
13
|
+
# manufacturer_name | (manufacturer_name)
|
14
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
15
|
+
# Foreign key constraints:
|
16
|
+
# (category_id) REFERENCES categories
|
17
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
18
|
+
|
19
|
+
class SItemWithCoding < Sequel::Model(SDB[:items])
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Table: items
|
4
|
+
# Columns:
|
5
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
6
|
+
# category_id | integer | NOT NULL
|
7
|
+
# manufacturer_name | varchar(50) |
|
8
|
+
# manufacturer_location | varchar(255) |
|
9
|
+
# in_stock | boolean | DEFAULT 0
|
10
|
+
# name | varchar(255) | DEFAULT 'John'
|
11
|
+
# price | double precision | DEFAULT 0
|
12
|
+
# Indexes:
|
13
|
+
# manufacturer_name | (manufacturer_name)
|
14
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
15
|
+
# Foreign key constraints:
|
16
|
+
# (category_id) REFERENCES categories
|
17
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
18
|
+
|
19
|
+
class SItemWithEncoding < Sequel::Model(SDB[:items])
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Table: items
|
4
|
+
# Columns:
|
5
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
6
|
+
# category_id | integer | NOT NULL
|
7
|
+
# manufacturer_name | varchar(50) |
|
8
|
+
# manufacturer_location | varchar(255) |
|
9
|
+
# in_stock | boolean | DEFAULT 0
|
10
|
+
# name | varchar(255) | DEFAULT 'John'
|
11
|
+
# price | double precision | DEFAULT 0
|
12
|
+
# Indexes:
|
13
|
+
# manufacturer_name | (manufacturer_name)
|
14
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
15
|
+
# Foreign key constraints:
|
16
|
+
# (category_id) REFERENCES categories
|
17
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
18
|
+
|
19
|
+
class SItemWithFrozenLiteral < Sequel::Model(SDB[:items])
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# warn_indent: true
|
2
|
+
|
3
|
+
# Table: items
|
4
|
+
# Columns:
|
5
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
6
|
+
# category_id | integer | NOT NULL
|
7
|
+
# manufacturer_name | varchar(50) |
|
8
|
+
# manufacturer_location | varchar(255) |
|
9
|
+
# in_stock | boolean | DEFAULT 0
|
10
|
+
# name | varchar(255) | DEFAULT 'John'
|
11
|
+
# price | double precision | DEFAULT 0
|
12
|
+
# Indexes:
|
13
|
+
# manufacturer_name | (manufacturer_name)
|
14
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
15
|
+
# Foreign key constraints:
|
16
|
+
# (category_id) REFERENCES categories
|
17
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
18
|
+
|
19
|
+
class SItemWithWarnIndent < Sequel::Model(SDB[:items])
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# warn_past_scope: true
|
2
|
+
# warn_indent: false
|
3
|
+
# Table: items
|
4
|
+
# Columns:
|
5
|
+
# id | integer | PRIMARY KEY AUTOINCREMENT
|
6
|
+
# category_id | integer | NOT NULL
|
7
|
+
# manufacturer_name | varchar(50) |
|
8
|
+
# manufacturer_location | varchar(255) |
|
9
|
+
# in_stock | boolean | DEFAULT 0
|
10
|
+
# name | varchar(255) | DEFAULT 'John'
|
11
|
+
# price | double precision | DEFAULT 0
|
12
|
+
# Indexes:
|
13
|
+
# manufacturer_name | (manufacturer_name)
|
14
|
+
# name | UNIQUE (manufacturer_name, manufacturer_location)
|
15
|
+
# Foreign key constraints:
|
16
|
+
# (category_id) REFERENCES categories
|
17
|
+
# (manufacturer_name, manufacturer_location) REFERENCES manufacturers
|
18
|
+
|
19
|
+
# Additional comment that should stay
|
20
|
+
class SItemWithWarnPastScope < Sequel::Model(SDB[:items])
|
21
|
+
end
|
@@ -4,10 +4,12 @@ require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/sequel/annot
|
|
4
4
|
|
5
5
|
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
6
6
|
gem 'minitest'
|
7
|
-
require 'minitest/autorun'
|
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
|
-
|
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
|
@@ -16,7 +18,7 @@ end
|
|
16
18
|
|
17
19
|
DB.drop_function(:valid_price) rescue nil
|
18
20
|
[DB, SDB].each do |db|
|
19
|
-
db.drop_table?(:items, :manufacturers, :categories)
|
21
|
+
db.drop_table?(:newline_tests, :items, :manufacturers, :categories, :comment_tests)
|
20
22
|
|
21
23
|
db.create_table :categories do
|
22
24
|
primary_key :id
|
@@ -32,7 +34,7 @@ DB.drop_function(:valid_price) rescue nil
|
|
32
34
|
db.create_table :items do
|
33
35
|
primary_key :id
|
34
36
|
foreign_key :category_id, :categories, :null => false
|
35
|
-
foreign_key [:manufacturer_name, :manufacturer_location], :manufacturers
|
37
|
+
foreign_key [:manufacturer_name, :manufacturer_location], :manufacturers, :name=>:items_manufacturer_name_fkey
|
36
38
|
|
37
39
|
String :manufacturer_name, :size => 50
|
38
40
|
String :manufacturer_location
|
@@ -45,6 +47,12 @@ DB.drop_function(:valid_price) rescue nil
|
|
45
47
|
index [:manufacturer_name, :manufacturer_location], :name=>:name, :unique=>true
|
46
48
|
index [:manufacturer_name], :name=>:manufacturer_name
|
47
49
|
end
|
50
|
+
|
51
|
+
db.create_table :newline_tests do
|
52
|
+
Integer :abcde_fghi_id
|
53
|
+
Integer :jkl_mnopqr_id
|
54
|
+
constraint(:valid_stuvw_xyz0, Sequel.case({{:abcde_fghi_id=>[5,6]}=>Sequel.~(:jkl_mnopqr_id=>nil)}, :jkl_mnopqr_id=>nil))
|
55
|
+
end
|
48
56
|
end
|
49
57
|
|
50
58
|
DB.run <<SQL
|
@@ -64,17 +72,44 @@ CREATE TRIGGER valid_price BEFORE INSERT OR UPDATE ON items
|
|
64
72
|
FOR EACH ROW EXECUTE PROCEDURE valid_price();
|
65
73
|
SQL
|
66
74
|
|
75
|
+
DB.run "CREATE DOMAIN test_domain AS text"
|
76
|
+
|
77
|
+
DB.create_table :domain_tests do
|
78
|
+
primary_key :id
|
79
|
+
test_domain :test_column
|
80
|
+
end
|
81
|
+
|
82
|
+
DB.create_table :comment_tests do
|
83
|
+
primary_key :id
|
84
|
+
String :name
|
85
|
+
end
|
86
|
+
|
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'"
|
89
|
+
|
67
90
|
Minitest.after_run do
|
68
|
-
DB.drop_table(:items, :manufacturers, :categories)
|
91
|
+
DB.drop_table(:items, :manufacturers, :categories, :domain_tests, :comment_tests)
|
92
|
+
DB.run "DROP DOMAIN test_domain"
|
69
93
|
DB.drop_function(:valid_price)
|
70
94
|
end
|
71
95
|
|
72
96
|
class ::Item < Sequel::Model; end
|
73
97
|
class ::Category < Sequel::Model; end
|
74
98
|
class ::Manufacturer < Sequel::Model; end
|
99
|
+
class ::DomainTest < Sequel::Model; end
|
100
|
+
class ::CommentTest < Sequel::Model; end
|
75
101
|
class ::SItem < Sequel::Model(SDB[:items]); end
|
102
|
+
class ::SItemWithFrozenLiteral < Sequel::Model(SDB[:items]); end
|
103
|
+
class ::SItemWithCoding < Sequel::Model(SDB[:items]); end
|
104
|
+
class ::SItemWithEncoding < Sequel::Model(SDB[:items]); end
|
105
|
+
class ::SItemWithWarnIndent < Sequel::Model(SDB[:items]); end
|
106
|
+
class ::SItemWithWarnPastScope < Sequel::Model(SDB[:items]); end
|
107
|
+
class ::SItemWithMagicComment < Sequel::Model(SDB[:items]); end
|
76
108
|
class ::SCategory < Sequel::Model(SDB[:categories]); end
|
77
109
|
class ::SManufacturer < Sequel::Model(SDB[:manufacturers]); end
|
110
|
+
class ::NewlineTest < Sequel::Model; end
|
111
|
+
class ::QualifiedTableNameTest < Sequel::Model(Sequel.qualify(:public, :categories)); end
|
112
|
+
class SComplexDataset < Sequel::Model(SDB[:items].left_join(:categories, :id => :category_id).select{items[:name]}); end
|
78
113
|
|
79
114
|
# Abstract Base Class
|
80
115
|
ABC = Class.new(Sequel::Model)
|
@@ -90,6 +125,9 @@ describe Sequel::Annotate do
|
|
90
125
|
if DB.server_version >= 100002 && (Sequel::MAJOR > 5 || (Sequel::MAJOR == 5 && Sequel::MINOR >= 7))
|
91
126
|
comment = comment.sub(/DEFAULT nextval\('[a-z]+_id_seq'::regclass\)/, 'GENERATED BY DEFAULT AS IDENTITY')
|
92
127
|
end
|
128
|
+
if DB.server_version >= 120000
|
129
|
+
comment = comment.gsub(/FOR EACH ROW EXECUTE PROCEDURE/, 'FOR EACH ROW EXECUTE FUNCTION')
|
130
|
+
end
|
93
131
|
comment
|
94
132
|
end
|
95
133
|
|
@@ -100,6 +138,52 @@ describe Sequel::Annotate do
|
|
100
138
|
Dir['spec/tmp/*.rb'].each{|f| File.delete(f)}
|
101
139
|
end
|
102
140
|
|
141
|
+
it "skips files with the sequel-annotate magic comment set to false" do
|
142
|
+
FileUtils.cp('spec/unannotated/sitemwithmagiccomment.rb', 'spec/tmp/')
|
143
|
+
Sequel::Annotate.annotate(['spec/tmp/sitemwithmagiccomment.rb'])
|
144
|
+
File.read('spec/tmp/sitemwithmagiccomment.rb').must_equal File.read('spec/unannotated/sitemwithmagiccomment.rb')
|
145
|
+
end
|
146
|
+
|
147
|
+
it "#schema_info should not return sections we set to false" do
|
148
|
+
Sequel::Annotate.new(Item).schema_comment(:indexes => false, :constraints => false, :foreign_keys => false, :triggers => false).must_equal(fix_pg_comment((<<OUTPUT).chomp))
|
149
|
+
# Table: items
|
150
|
+
# Columns:
|
151
|
+
# id | integer | PRIMARY KEY DEFAULT nextval('items_id_seq'::regclass)
|
152
|
+
# category_id | integer | NOT NULL
|
153
|
+
# manufacturer_name | character varying(50) |
|
154
|
+
# manufacturer_location | text |
|
155
|
+
# in_stock | boolean | DEFAULT false
|
156
|
+
# name | text | DEFAULT 'John'::text
|
157
|
+
# price | double precision | DEFAULT 0
|
158
|
+
OUTPUT
|
159
|
+
|
160
|
+
Sequel::Annotate.new(Category).schema_comment(:references => false).must_equal(fix_pg_comment((<<OUTPUT).chomp))
|
161
|
+
# Table: categories
|
162
|
+
# Columns:
|
163
|
+
# id | integer | PRIMARY KEY DEFAULT nextval('categories_id_seq'::regclass)
|
164
|
+
# name | text | NOT NULL
|
165
|
+
# Indexes:
|
166
|
+
# categories_pkey | PRIMARY KEY btree (id)
|
167
|
+
# categories_name_key | UNIQUE btree (name)
|
168
|
+
OUTPUT
|
169
|
+
end
|
170
|
+
|
171
|
+
it "#schema_info should return a border if we want one" do
|
172
|
+
Sequel::Annotate.new(Item).schema_comment(:border => true, :indexes => false, :constraints => false, :foreign_keys => false, :triggers => false).gsub(/----+/, '---').must_equal(fix_pg_comment((<<OUTPUT).chomp))
|
173
|
+
# Table: items
|
174
|
+
# ---
|
175
|
+
# Columns:
|
176
|
+
# id | integer | PRIMARY KEY DEFAULT nextval('items_id_seq'::regclass)
|
177
|
+
# category_id | integer | NOT NULL
|
178
|
+
# manufacturer_name | character varying(50) |
|
179
|
+
# manufacturer_location | text |
|
180
|
+
# in_stock | boolean | DEFAULT false
|
181
|
+
# name | text | DEFAULT 'John'::text
|
182
|
+
# price | double precision | DEFAULT 0
|
183
|
+
# ---
|
184
|
+
OUTPUT
|
185
|
+
end
|
186
|
+
|
103
187
|
it "#schema_info should return the model schema comment" do
|
104
188
|
Sequel::Annotate.new(Item).schema_comment.must_equal(fix_pg_comment((<<OUTPUT).chomp))
|
105
189
|
# Table: items
|
@@ -124,6 +208,7 @@ describe Sequel::Annotate do
|
|
124
208
|
# valid_price | BEFORE INSERT OR UPDATE ON items FOR EACH ROW EXECUTE PROCEDURE valid_price()
|
125
209
|
OUTPUT
|
126
210
|
|
211
|
+
Sequel::Annotate.new(SComplexDataset).schema_comment.must_equal("")
|
127
212
|
Sequel::Annotate.new(Category).schema_comment.must_equal(fix_pg_comment((<<OUTPUT).chomp))
|
128
213
|
# Table: categories
|
129
214
|
# Columns:
|
@@ -146,6 +231,19 @@ OUTPUT
|
|
146
231
|
# manufacturers_pkey | PRIMARY KEY btree (name, location)
|
147
232
|
# Referenced By:
|
148
233
|
# items | items_manufacturer_name_fkey | (manufacturer_name, manufacturer_location) REFERENCES manufacturers(name, location)
|
234
|
+
OUTPUT
|
235
|
+
|
236
|
+
Sequel::Annotate.new(NewlineTest).schema_comment.must_equal((<<OUTPUT).chomp)
|
237
|
+
# Table: newline_tests
|
238
|
+
# Columns:
|
239
|
+
# abcde_fghi_id | integer |
|
240
|
+
# jkl_mnopqr_id | integer |
|
241
|
+
# Check constraints:
|
242
|
+
# valid_stuvw_xyz0 | (
|
243
|
+
# CASE
|
244
|
+
# WHEN abcde_fghi_id = ANY (ARRAY[5, 6]) THEN jkl_mnopqr_id IS NOT NULL
|
245
|
+
# ELSE jkl_mnopqr_id IS NULL
|
246
|
+
# END)
|
149
247
|
OUTPUT
|
150
248
|
|
151
249
|
Sequel::Annotate.new(SItem).schema_comment.must_equal((<<OUTPUT).chomp)
|
@@ -181,6 +279,37 @@ OUTPUT
|
|
181
279
|
# Columns:
|
182
280
|
# name | varchar(255) |
|
183
281
|
# location | varchar(255) |
|
282
|
+
OUTPUT
|
283
|
+
|
284
|
+
Sequel::Annotate.new(QualifiedTableNameTest).schema_comment.must_equal(fix_pg_comment((<<OUTPUT).chomp))
|
285
|
+
# Table: public.categories
|
286
|
+
# Columns:
|
287
|
+
# id | integer | PRIMARY KEY DEFAULT nextval('categories_id_seq'::regclass)
|
288
|
+
# name | text | NOT NULL
|
289
|
+
# Indexes:
|
290
|
+
# categories_pkey | PRIMARY KEY btree (id)
|
291
|
+
# categories_name_key | UNIQUE btree (name)
|
292
|
+
# Referenced By:
|
293
|
+
# items | items_category_id_fkey | (category_id) REFERENCES categories(id)
|
294
|
+
OUTPUT
|
295
|
+
|
296
|
+
Sequel::Annotate.new(DomainTest).schema_comment.must_equal(fix_pg_comment((<<OUTPUT).chomp))
|
297
|
+
# Table: domain_tests
|
298
|
+
# Columns:
|
299
|
+
# id | integer | PRIMARY KEY DEFAULT nextval('categories_id_seq'::regclass)
|
300
|
+
# test_column | test_domain |
|
301
|
+
# Indexes:
|
302
|
+
# domain_tests_pkey | PRIMARY KEY btree (id)
|
303
|
+
OUTPUT
|
304
|
+
|
305
|
+
Sequel::Annotate.new(CommentTest).schema_comment.must_equal(fix_pg_comment((<<OUTPUT).chomp))
|
306
|
+
# Table: comment_tests
|
307
|
+
# Comment: comment_tests table comment
|
308
|
+
# Columns:
|
309
|
+
# id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY |
|
310
|
+
# name | text | | name column comment
|
311
|
+
# Indexes:
|
312
|
+
# comment_tests_pkey | PRIMARY KEY btree (id)
|
184
313
|
OUTPUT
|
185
314
|
end
|
186
315
|
|
@@ -188,7 +317,7 @@ OUTPUT
|
|
188
317
|
it "#annotate #{desc} should annotate the file comment" do
|
189
318
|
FileUtils.cp(Dir['spec/unannotated/*.rb'], 'spec/tmp')
|
190
319
|
|
191
|
-
[Item, Category, Manufacturer, SItem, SCategory, SManufacturer].each do |model|
|
320
|
+
[Item, Category, Manufacturer, SItem, SCategory, SManufacturer, SItemWithFrozenLiteral, SItemWithCoding, SItemWithEncoding, SItemWithWarnIndent, SItemWithWarnPastScope, SComplexDataset].each do |model|
|
192
321
|
filename = model.name.downcase
|
193
322
|
2.times do
|
194
323
|
Sequel::Annotate.new(model).annotate("spec/tmp/#{filename}.rb", *args)
|
@@ -204,7 +333,7 @@ OUTPUT
|
|
204
333
|
|
205
334
|
2.times do
|
206
335
|
Sequel::Annotate.annotate(Dir["spec/tmp/*.rb"], *args)
|
207
|
-
[Item, Category, Manufacturer, SItem, SCategory, SManufacturer].each do |model|
|
336
|
+
[Item, Category, Manufacturer, SItem, SCategory, SManufacturer, SItemWithFrozenLiteral, SItemWithCoding, SItemWithEncoding, SItemWithWarnIndent, SItemWithWarnPastScope, SComplexDataset].each do |model|
|
208
337
|
filename = model.name.downcase
|
209
338
|
expected = File.read("spec/annotated_#{pos}/#{filename}.rb")
|
210
339
|
expected = fix_pg_comment(expected) if model.db == DB
|
@@ -218,5 +347,14 @@ OUTPUT
|
|
218
347
|
FileUtils.cp('spec/namespaced/itm_unannotated.rb', 'spec/tmp/')
|
219
348
|
Sequel::Annotate.annotate(["spec/tmp/itm_unannotated.rb"], :namespace=>'ModelNamespace')
|
220
349
|
File.read("spec/tmp/itm_unannotated.rb").must_equal fix_pg_comment(File.read('spec/namespaced/itm_annotated.rb'))
|
350
|
+
Sequel::Annotate.annotate(["spec/tmp/itm_unannotated.rb"], :namespace=>'ModelNamespace', :border=>true)
|
351
|
+
Sequel::Annotate.annotate(["spec/tmp/itm_unannotated.rb"], :namespace=>'ModelNamespace')
|
352
|
+
File.read("spec/tmp/itm_unannotated.rb").must_equal fix_pg_comment(File.read('spec/namespaced/itm_annotated.rb'))
|
353
|
+
end
|
354
|
+
|
355
|
+
it ".annotate #{desc} should handle :namespace => true option" do
|
356
|
+
FileUtils.cp('spec/namespaced/itm_unannotated.rb', 'spec/tmp')
|
357
|
+
Sequel::Annotate.annotate(["spec/tmp/itm_unannotated.rb"], :namespace=>true)
|
358
|
+
File.read("spec/tmp/itm_unannotated.rb").must_equal fix_pg_comment(File.read('spec/namespaced/itm_annotated.rb'))
|
221
359
|
end
|
222
360
|
end
|
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.
|
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:
|
11
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-global_expectations
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pg
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +86,7 @@ description: |
|
|
72
86
|
constraints for the current table.
|
73
87
|
|
74
88
|
On PostgreSQL, this includes more advanced information, including
|
75
|
-
check constraints, triggers, and foreign keys constraints for other
|
89
|
+
check constraints, triggers, comments, and foreign keys constraints for other
|
76
90
|
tables that reference the current table.
|
77
91
|
email: code@jeremyevans.net
|
78
92
|
executables: []
|
@@ -91,13 +105,25 @@ files:
|
|
91
105
|
- spec/annotated_after/item.rb
|
92
106
|
- spec/annotated_after/manufacturer.rb
|
93
107
|
- spec/annotated_after/scategory.rb
|
108
|
+
- spec/annotated_after/scomplexdataset.rb
|
94
109
|
- spec/annotated_after/sitem.rb
|
110
|
+
- spec/annotated_after/sitemwithcoding.rb
|
111
|
+
- spec/annotated_after/sitemwithencoding.rb
|
112
|
+
- spec/annotated_after/sitemwithfrozenliteral.rb
|
113
|
+
- spec/annotated_after/sitemwithwarnindent.rb
|
114
|
+
- spec/annotated_after/sitemwithwarnpastscope.rb
|
95
115
|
- spec/annotated_after/smanufacturer.rb
|
96
116
|
- spec/annotated_before/category.rb
|
97
117
|
- spec/annotated_before/item.rb
|
98
118
|
- spec/annotated_before/manufacturer.rb
|
99
119
|
- spec/annotated_before/scategory.rb
|
120
|
+
- spec/annotated_before/scomplexdataset.rb
|
100
121
|
- spec/annotated_before/sitem.rb
|
122
|
+
- spec/annotated_before/sitemwithcoding.rb
|
123
|
+
- spec/annotated_before/sitemwithencoding.rb
|
124
|
+
- spec/annotated_before/sitemwithfrozenliteral.rb
|
125
|
+
- spec/annotated_before/sitemwithwarnindent.rb
|
126
|
+
- spec/annotated_before/sitemwithwarnpastscope.rb
|
101
127
|
- spec/annotated_before/smanufacturer.rb
|
102
128
|
- spec/namespaced/itm_annotated.rb
|
103
129
|
- spec/namespaced/itm_unannotated.rb
|
@@ -105,13 +131,24 @@ files:
|
|
105
131
|
- spec/unannotated/category.rb
|
106
132
|
- spec/unannotated/item.rb
|
107
133
|
- spec/unannotated/manufacturer.rb
|
134
|
+
- spec/unannotated/not_model.rb
|
108
135
|
- spec/unannotated/scategory.rb
|
136
|
+
- spec/unannotated/scomplexdataset.rb
|
109
137
|
- spec/unannotated/sitem.rb
|
138
|
+
- spec/unannotated/sitemwithcoding.rb
|
139
|
+
- spec/unannotated/sitemwithencoding.rb
|
140
|
+
- spec/unannotated/sitemwithfrozenliteral.rb
|
141
|
+
- spec/unannotated/sitemwithmagiccomment.rb
|
142
|
+
- spec/unannotated/sitemwithwarnindent.rb
|
143
|
+
- spec/unannotated/sitemwithwarnpastscope.rb
|
110
144
|
- spec/unannotated/smanufacturer.rb
|
111
145
|
homepage: http://github.com/jeremyevans/sequel-annotate
|
112
146
|
licenses:
|
113
147
|
- MIT
|
114
|
-
metadata:
|
148
|
+
metadata:
|
149
|
+
bug_tracker_uri: https://github.com/jeremyevans/sequel-annotate/issues
|
150
|
+
changelog_uri: https://github.com/jeremyevans/sequel-annotate/blob/master/CHANGELOG
|
151
|
+
source_code_uri: https://github.com/jeremyevans/sequel-annotate
|
115
152
|
post_install_message:
|
116
153
|
rdoc_options:
|
117
154
|
- "--quiet"
|
@@ -134,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
171
|
- !ruby/object:Gem::Version
|
135
172
|
version: '0'
|
136
173
|
requirements: []
|
137
|
-
|
138
|
-
rubygems_version: 2.7.6
|
174
|
+
rubygems_version: 3.2.15
|
139
175
|
signing_key:
|
140
176
|
specification_version: 4
|
141
177
|
summary: Annotate Sequel models with schema information
|