sequel-annotate 1.1.0 → 1.2.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
- SHA1:
3
- metadata.gz: 2f316737efff6528dad01a3dd9a142299d89430a
4
- data.tar.gz: 1cd80a2169fd571993dceac826153c71fcf9e70f
2
+ SHA256:
3
+ metadata.gz: 112ffb3483f88eacd72945f7890fac2d21b8cfa8f4559b13210eb76d80e36e53
4
+ data.tar.gz: b2a580e9ddc239a8d2fb948ac5c571733915d9badf2c84385f3d21aaede7ab71
5
5
  SHA512:
6
- metadata.gz: 3a5d46059231408e13f9fe1752a164a038dfead63b28601184552410982eb04532a8f4083355ac42cf51adab9dfdb4ca95d3c3bed28b0fbf2b45f69a0e9a3dec
7
- data.tar.gz: 36855434041c486606a055cd42029dec03a8613a62aaeefd4ce8431fce89cd28f8e07398b2d395d5b2ecec0d9a8edad85abae1556f76c0f6e572077285ff8b37
6
+ metadata.gz: edcaf9424b611f0ec0b08fb511ef2f7f9d245756040e8adf829101264846c0768f24e4d52d143d64fed4e8a05d58aa820758023e6f1d49e83ed0b87e64c0aa70
7
+ data.tar.gz: 267dbf8b5693e541abbe3d97154adddfd839d2ea0e3e88475146c0d4739b6f1b42cfd2d01959984d8d7a68851375875a0e11ec28fbf1d5ab8b5c942f2d9f9efd
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.2.0 (2018-04-02)
2
+
3
+ * Handle PostgreSQL 10+ identity columns when running on Sequel 5.7+ (jeremyevans)
4
+
5
+ * Use multiline regexps when parsing schema on PostgreSQL (jeremyevans) (#5)
6
+
1
7
  === 1.1.0 (2017-09-06)
2
8
 
3
9
  * Support :position=>:before option to annotate to put annotation at the beginning of the file (a0s) (#4)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015-2017 Jeremy Evans
1
+ Copyright (c) 2015-2018 Jeremy Evans
2
2
  Copyright (c) 2013-2015 Kenny Meyer
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  desc "Run specs"
14
14
  task :spec do
15
- sh "#{FileUtils::RUBY} -rubygems -I lib spec/sequel-annotate_spec.rb"
15
+ sh "#{FileUtils::RUBY} -I lib spec/sequel-annotate_spec.rb"
16
16
  end
17
17
 
18
18
  task :default => :spec
@@ -115,7 +115,7 @@ SQL
115
115
  unless rows.empty?
116
116
  output << "# Indexes:"
117
117
  rows = rows.map do |r|
118
- [r[:relname], "#{"PRIMARY KEY " if r[:indisprimary]}#{"UNIQUE " if r[:indisunique] && !r[:indisprimary]}#{r[:pg_get_indexdef].match(/USING (.+)\z/)[1]}"]
118
+ [r[:relname], "#{"PRIMARY KEY " if r[:indisprimary]}#{"UNIQUE " if r[:indisunique] && !r[:indisprimary]}#{r[:pg_get_indexdef].match(/USING (.+)\z/m)[1]}"]
119
119
  end
120
120
  output.concat(align(rows))
121
121
  end
@@ -129,7 +129,7 @@ SQL
129
129
  unless rows.empty?
130
130
  output << "# Check constraints:"
131
131
  rows = rows.map do |r|
132
- [r[:conname], r[:pg_get_constraintdef].match(/CHECK (.+)\z/)[1]]
132
+ [r[:conname], r[:pg_get_constraintdef].match(/CHECK (.+)\z/m)[1]]
133
133
  end
134
134
  output.concat(align(rows))
135
135
  end
@@ -143,7 +143,7 @@ SQL
143
143
  unless rows.empty?
144
144
  output << "# Foreign key constraints:"
145
145
  rows = rows.map do |r|
146
- [r[:conname], r[:condef].match(/FOREIGN KEY (.+)\z/)[1]]
146
+ [r[:conname], r[:condef].match(/FOREIGN KEY (.+)\z/m)[1]]
147
147
  end
148
148
  output.concat(align(rows))
149
149
  end
@@ -157,7 +157,7 @@ SQL
157
157
  unless rows.empty?
158
158
  output << "# Referenced By:"
159
159
  rows = rows.map do |r|
160
- [r[:conrelid], r[:conname], r[:condef].match(/FOREIGN KEY (.+)\z/)[1]]
160
+ [r[:conrelid], r[:conname], r[:condef].match(/FOREIGN KEY (.+)\z/m)[1]]
161
161
  end
162
162
  output.concat(align(rows))
163
163
  end
@@ -171,7 +171,7 @@ SQL
171
171
  unless rows.empty?
172
172
  output << "# Triggers:"
173
173
  rows = rows.map do |r|
174
- [r[:tgname], r[:pg_get_triggerdef].match(/((?:BEFORE|AFTER) .+)\z/)[1]]
174
+ [r[:tgname], r[:pg_get_triggerdef].match(/((?:BEFORE|AFTER) .+)\z/m)[1]]
175
175
  end
176
176
  output.concat(align(rows))
177
177
  end
@@ -185,7 +185,7 @@ SQL
185
185
  output << "# Columns:"
186
186
  rows = model.columns.map do |col|
187
187
  sch = model.db_schema[col]
188
- [col.to_s, sch[:db_type], "#{"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]}"]
188
+ [col.to_s, sch[:db_type], "#{"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}"]
189
189
  end
190
190
  output.concat(align(rows))
191
191
  end
@@ -66,6 +66,13 @@ class ::SManufacturer < Sequel::Model(SDB[:manufacturers]); end
66
66
 
67
67
 
68
68
  describe Sequel::Annotate do
69
+ def fix_pg_comment(comment)
70
+ if DB.server_version >= 100002 && (Sequel::MAJOR > 5 || (Sequel::MAJOR == 5 && Sequel::MINOR >= 7))
71
+ comment = comment.sub(/DEFAULT nextval\('[a-z]+_id_seq'::regclass\)/, 'GENERATED BY DEFAULT AS IDENTITY')
72
+ end
73
+ comment
74
+ end
75
+
69
76
  before do
70
77
  Dir.mkdir('spec/tmp') unless File.directory?('spec/tmp')
71
78
  end
@@ -74,7 +81,7 @@ describe Sequel::Annotate do
74
81
  end
75
82
 
76
83
  it "#schema_info should return the model schema comment" do
77
- Sequel::Annotate.new(Item).schema_comment.must_equal((<<OUTPUT).chomp)
84
+ Sequel::Annotate.new(Item).schema_comment.must_equal(fix_pg_comment((<<OUTPUT).chomp))
78
85
  # Table: items
79
86
  # Columns:
80
87
  # id | integer | PRIMARY KEY DEFAULT nextval('items_id_seq'::regclass)
@@ -97,7 +104,7 @@ describe Sequel::Annotate do
97
104
  # valid_price | BEFORE INSERT OR UPDATE ON items FOR EACH ROW EXECUTE PROCEDURE valid_price()
98
105
  OUTPUT
99
106
 
100
- Sequel::Annotate.new(Category).schema_comment.must_equal((<<OUTPUT).chomp)
107
+ Sequel::Annotate.new(Category).schema_comment.must_equal(fix_pg_comment((<<OUTPUT).chomp))
101
108
  # Table: categories
102
109
  # Columns:
103
110
  # id | integer | PRIMARY KEY DEFAULT nextval('categories_id_seq'::regclass)
@@ -165,7 +172,9 @@ OUTPUT
165
172
  filename = model.name.downcase
166
173
  2.times do
167
174
  Sequel::Annotate.new(model).annotate("spec/tmp/#{filename}.rb", *args)
168
- File.read("spec/tmp/#{filename}.rb").must_equal File.read("spec/annotated_#{pos}/#{filename}.rb")
175
+ expected = File.read("spec/annotated_#{pos}/#{filename}.rb")
176
+ expected = fix_pg_comment(expected) if model.db == DB
177
+ File.read("spec/tmp/#{filename}.rb").must_equal expected
169
178
  end
170
179
  end
171
180
  end
@@ -177,7 +186,9 @@ OUTPUT
177
186
  Sequel::Annotate.annotate(Dir["spec/tmp/*.rb"], *args)
178
187
  [Item, Category, Manufacturer, SItem, SCategory, SManufacturer].each do |model|
179
188
  filename = model.name.downcase
180
- File.read("spec/tmp/#{filename}.rb").must_equal File.read("spec/annotated_#{pos}/#{filename}.rb")
189
+ expected = File.read("spec/annotated_#{pos}/#{filename}.rb")
190
+ expected = fix_pg_comment(expected) if model.db == DB
191
+ File.read("spec/tmp/#{filename}.rb").must_equal expected
181
192
  end
182
193
  end
183
194
  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.1.0
4
+ version: 1.2.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: 2017-09-06 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.6.13
136
+ rubygems_version: 2.7.6
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: Annotate Sequel models with schema information