schema_plus_core 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/schema_plus/core/active_record/schema_dumper.rb +18 -14
- data/lib/schema_plus/core/schema_dump.rb +6 -1
- data/lib/schema_plus/core/version.rb +1 -1
- data/spec/dumper_spec.rb +59 -1
- metadata +2 -4
- data/spec/support/test_dumper.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52e38bdd3b1c4e571c13dd1622d788e26a7482d2
|
4
|
+
data.tar.gz: fc308fc51c0e41a39bab240d5cd398bad57973eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1907077811c3f92a40bf70c99fb5a2a5fbcdb336238206d06e2eb4b841cc87dd9c992909e2eee89da7f5d9cf6a450d3ffd43f638fa019b288ffba26f40b334d9
|
7
|
+
data.tar.gz: 98f844ac096c11fb8f592ad9fdf9e2e2d4438a5293907943f181fcc77acee326fa4f066288911b56f45b51133a64f2131dcb0f81f91ee0ba2ab573604ab50261
|
data/README.md
CHANGED
@@ -369,6 +369,7 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
|
|
369
369
|
* `table.indexes = []` - an array of SchemaDump::Table::Index objects
|
370
370
|
* `table.statements` - a collection of statements to include in the table definition; each is a string that should start with `"t."`
|
371
371
|
* `table.trailer` - a collection of migration statements to include immediately outside the table definition. Each is a string
|
372
|
+
* `table.alt` - In some cases, ActiveRecord is unable to dump a table in the form of a migration `create_table` statement; in this case `table.pname` will be nil, and `table.alt` will contain the alternate string to dump instead. (E.g. if the table contains custom types, ActiveRecord will be unable to handle it and will just dump an error message as a comment.)
|
372
373
|
|
373
374
|
* `Class SchemaPlus::Core::SchemaDump::Table::Column`
|
374
375
|
|
@@ -450,6 +451,7 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
|
|
450
451
|
|
451
452
|
## History
|
452
453
|
|
454
|
+
* 0.6.0 Added `table.alt` to dumper; Bug fix: Don't crash when AR fails to dump a table. Thanks to [@stenver](https://github.com/stenver) for tracking it down
|
453
455
|
* 0.5.1 Bug fix: Don't choke on a quoted newline in a `CREATE TABLE` statement ([#3](https://github.com/SchemaPlus/schema_plus_core/pull/3)). Thanks to [@mikeauclair](https://github.com/mikeauclair)
|
454
456
|
* 0.5.0 Added `Migration::DropTable`
|
455
457
|
* 0.4.0 Added `implements_reference` to `Migration::Column` stack env
|
@@ -60,20 +60,24 @@ module SchemaPlus
|
|
60
60
|
(?<trailer>.*)
|
61
61
|
\Z
|
62
62
|
}xm
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
(?<
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
63
|
+
if m.nil?
|
64
|
+
env.table.alt = stream.string
|
65
|
+
else
|
66
|
+
env.table.pname = m[:name]
|
67
|
+
env.table.options = m[:options].strip
|
68
|
+
env.table.trailer = m[:trailer].split("\n").map(&:strip).reject{|s| s.blank?}
|
69
|
+
env.table.columns = m[:columns].strip.split("\n").map { |col|
|
70
|
+
m = col.strip.match %r{
|
71
|
+
^
|
72
|
+
t\.(?<type>\S+) \s*
|
73
|
+
[:'"](?<name>[^"\s]+)[,"]? \s*
|
74
|
+
,? \s*
|
75
|
+
(?<options>.*)
|
76
|
+
$
|
77
|
+
}x
|
78
|
+
SchemaDump::Table::Column.new(name: m[:name], type: m[:type], options: m[:options])
|
79
|
+
}
|
80
|
+
end
|
77
81
|
end
|
78
82
|
end
|
79
83
|
|
@@ -43,7 +43,7 @@ module SchemaPlus
|
|
43
43
|
@dependencies[tablename].sort.uniq.reject{|t| @dumper.ignored? t}.each(&block)
|
44
44
|
end
|
45
45
|
|
46
|
-
class Table < KeyStruct[:name, :pname, :options, :columns, :indexes, :statements, :trailer]
|
46
|
+
class Table < KeyStruct[:name, :pname, :options, :columns, :indexes, :statements, :trailer, :alt]
|
47
47
|
def initialize(*args)
|
48
48
|
super
|
49
49
|
self.columns ||= []
|
@@ -53,6 +53,11 @@ module SchemaPlus
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def assemble(stream)
|
56
|
+
if pname.nil?
|
57
|
+
stream.puts alt
|
58
|
+
stream.puts ""
|
59
|
+
return
|
60
|
+
end
|
56
61
|
stream.write " create_table #{pname.inspect}"
|
57
62
|
stream.write ", #{options}" unless options.blank?
|
58
63
|
stream.puts " do |t|"
|
data/spec/dumper_spec.rb
CHANGED
@@ -1,9 +1,65 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
module TestDumper
|
4
|
+
module Middleware
|
5
|
+
module Dumper
|
6
|
+
module Initial
|
7
|
+
include Enableable
|
8
|
+
def after(env)
|
9
|
+
return unless middleware = enabled_middleware(TestDumper, env)
|
10
|
+
env.initial.unshift middleware.to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
module Tables
|
14
|
+
include Enableable
|
15
|
+
def after(env)
|
16
|
+
return unless middleware = enabled_middleware(TestDumper, env)
|
17
|
+
env.dump.tables[middleware.to_s] = env.dump.tables.values.first.dup.tap {|t| t.pname = middleware.to_s }
|
18
|
+
env.dump.depends("things", middleware.to_s)
|
19
|
+
env.dump.depends(middleware.to_s, "other")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
module Table
|
23
|
+
include Enableable
|
24
|
+
def after(env)
|
25
|
+
return unless middleware = enabled_middleware(TestDumper, env)
|
26
|
+
if column = env.table.columns.first
|
27
|
+
column.add_option "option: #{middleware}"
|
28
|
+
column.add_comment "comment: #{middleware}"
|
29
|
+
end
|
30
|
+
env.table.statements << "statement: #{middleware}"
|
31
|
+
env.table.trailer << "trailer: #{middleware}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
module Indexes
|
35
|
+
include Enableable
|
36
|
+
def after(env)
|
37
|
+
return unless env.table.indexes.any?
|
38
|
+
return unless middleware = enabled_middleware(TestDumper, env)
|
39
|
+
env.table.indexes.first.add_option middleware.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
SchemaMonkey.register(TestDumper)
|
47
|
+
|
3
48
|
describe SchemaMonkey::Middleware::Dumper do
|
4
49
|
|
5
50
|
let(:migration) { ::ActiveRecord::Migration }
|
6
51
|
|
52
|
+
TestCustomType = SchemaDev::Rspec::Helpers.postgresql?
|
53
|
+
|
54
|
+
around(:each) do |example|
|
55
|
+
begin
|
56
|
+
migration.execute "CREATE TYPE custom_type AS ENUM ('a', 'b')";
|
57
|
+
example.run
|
58
|
+
ensure
|
59
|
+
migration.execute "DROP TYPE IF EXISTS custom_type CASCADE";
|
60
|
+
end
|
61
|
+
end if TestCustomType
|
62
|
+
|
7
63
|
before(:each) do
|
8
64
|
migration.create_table "things" do |t|
|
9
65
|
t.integer :column
|
@@ -13,6 +69,7 @@ describe SchemaMonkey::Middleware::Dumper do
|
|
13
69
|
t.references :thing
|
14
70
|
end
|
15
71
|
migration.add_foreign_key("other", "things")
|
72
|
+
migration.execute "CREATE TABLE custom_table ( my_column custom_type DEFAULT 'a'::custom_type NOT NULL)" if TestCustomType
|
16
73
|
end
|
17
74
|
|
18
75
|
context TestDumper::Middleware::Dumper::Initial do
|
@@ -26,6 +83,7 @@ describe SchemaMonkey::Middleware::Dumper do
|
|
26
83
|
context TestDumper::Middleware::Dumper::Table do
|
27
84
|
Then { expect(dump).to match(/t[.]integer.*option: #{middleware} \# comment: #{middleware}/) }
|
28
85
|
Then { expect(dump).to match(/statement: #{middleware}\s+end\s+(add_index.*)?\s+trailer: #{middleware}/) }
|
86
|
+
Then { expect(dump).to match(/could not dump table.*custom_table.*unknown type.*custom_type/mi) } if TestCustomType
|
29
87
|
end
|
30
88
|
|
31
89
|
context TestDumper::Middleware::Dumper::Indexes do
|
@@ -41,7 +99,7 @@ describe SchemaMonkey::Middleware::Dumper do
|
|
41
99
|
|
42
100
|
def dump
|
43
101
|
begin
|
44
|
-
middleware.enable
|
102
|
+
middleware.enable once:false
|
45
103
|
stream = StringIO.new
|
46
104
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
47
105
|
return stream.string
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_plus_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronen barzel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -178,7 +178,6 @@ files:
|
|
178
178
|
- spec/spec_helper.rb
|
179
179
|
- spec/sql_struct_spec.rb
|
180
180
|
- spec/support/enableable.rb
|
181
|
-
- spec/support/test_dumper.rb
|
182
181
|
- spec/support/test_reporter.rb
|
183
182
|
homepage: https://github.com/SchemaPlus/schema_plus_core
|
184
183
|
licenses:
|
@@ -211,5 +210,4 @@ test_files:
|
|
211
210
|
- spec/spec_helper.rb
|
212
211
|
- spec/sql_struct_spec.rb
|
213
212
|
- spec/support/enableable.rb
|
214
|
-
- spec/support/test_dumper.rb
|
215
213
|
- spec/support/test_reporter.rb
|
data/spec/support/test_dumper.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
module TestDumper
|
2
|
-
module Middleware
|
3
|
-
module Dumper
|
4
|
-
module Initial
|
5
|
-
include Enableable
|
6
|
-
def after(env)
|
7
|
-
return unless middleware = enabled_middleware(TestDumper, env)
|
8
|
-
env.initial.unshift middleware.to_s
|
9
|
-
end
|
10
|
-
end
|
11
|
-
module Tables
|
12
|
-
include Enableable
|
13
|
-
def after(env)
|
14
|
-
return unless middleware = enabled_middleware(TestDumper, env)
|
15
|
-
env.dump.tables[middleware.to_s] = env.dump.tables.values.first.dup.tap {|t| t.pname = middleware.to_s }
|
16
|
-
env.dump.depends("things", middleware.to_s)
|
17
|
-
env.dump.depends(middleware.to_s, "other")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
module Table
|
21
|
-
include Enableable
|
22
|
-
def after(env)
|
23
|
-
return unless middleware = enabled_middleware(TestDumper, env)
|
24
|
-
env.table.columns.first.add_option "option: #{middleware}"
|
25
|
-
env.table.columns.first.add_comment "comment: #{middleware}"
|
26
|
-
env.table.statements << "statement: #{middleware}"
|
27
|
-
env.table.trailer << "trailer: #{middleware}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
module Indexes
|
31
|
-
include Enableable
|
32
|
-
def after(env)
|
33
|
-
return unless env.table.indexes.any?
|
34
|
-
return unless middleware = enabled_middleware(TestDumper, env)
|
35
|
-
env.table.indexes.first.add_option middleware.to_s
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
SchemaMonkey.register(TestDumper)
|