schema_plus_core 1.0.2 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 467fc076aa3de1e9d6890f4a9ff8e87a81a24c3f
4
- data.tar.gz: 9e35f0a5d5be71a5a53c6aba151d3140c140f387
3
+ metadata.gz: 86e2ba87b085b72dbc2117b25926b21cd17c900f
4
+ data.tar.gz: 3449adbeb2caf2405162f70aab282a117aa81260
5
5
  SHA512:
6
- metadata.gz: 1481e4d731796f2a2db9bce577a115313bd67d489a4a53b9dc24fbd71c38e554f247ddb4aaa02d5148156ed491cc8be64956367541901549df50cc7a4300519d
7
- data.tar.gz: 7e1d8b4995d2482e8b3efda83e608b7e7b5c313c5f33d6264cb743ce0467f23b542c756be4482ec8a7af052b3cd9aa086be71cdc7dfeb72614cb068ef8975ee7
6
+ metadata.gz: f9972320f4d103ed11fb2a2f4e2951d95b47b8212bf9d30f31b61ca0edf137abc01d6590c338a2425922144483848dcf3677378c3d5bff05f4418d316d973d70
7
+ data.tar.gz: 8c2a28d46bd37562699a33e5a690c8cfd38cce492693bb08bde076ff2b06ce691f12e101d8f9f6f8bb913006524a598415259183c7d02520b7e17845b88d7f5c
data/.travis.yml CHANGED
@@ -5,11 +5,11 @@
5
5
  ---
6
6
  sudo: false
7
7
  rvm:
8
- - 2.1.5
8
+ - 2.3.0
9
9
  gemfile:
10
- - gemfiles/activerecord-4.2/Gemfile.mysql2
11
- - gemfiles/activerecord-4.2/Gemfile.postgresql
12
- - gemfiles/activerecord-4.2/Gemfile.sqlite3
10
+ - gemfiles/activerecord-5.0/Gemfile.mysql2
11
+ - gemfiles/activerecord-5.0/Gemfile.postgresql
12
+ - gemfiles/activerecord-5.0/Gemfile.sqlite3
13
13
  env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
14
14
  addons:
15
15
  postgresql: '9.4'
data/README.md CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  SchemaPlus::Core creates an internal extension API to ActiveRecord. The idea is that:
8
8
 
9
- * ShemaPlus::Core does the monkey-patching so clients don't have to know too much about the internal of ActiveRecord.
9
+ * SchemaPlus::Core does the monkey-patching so clients don't have to know too much about the internal of ActiveRecord.
10
10
 
11
11
  * SchemaPlus::Core's extension API is consistent across the various connection adapters, so clients don't have to figure out how to extend each connection adapter independently.
12
12
 
13
- * SchemPlus::Core's extension API intends to remain reasonably stable even as ActiveRecord changes.
13
+ * SchemaPlus::Core's extension API intends to remain reasonably stable even as ActiveRecord changes.
14
14
 
15
15
  By itself, SchemaPlus::Core does not change any behavior or add any external features to ActiveRecord. It just makes the API available to clients.
16
16
 
@@ -23,10 +23,19 @@ SchemaPlus::Core is tested on:
23
23
 
24
24
  <!-- SCHEMA_DEV: MATRIX - begin -->
25
25
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
26
- * ruby **2.1.5** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
26
+ * ruby **2.3.0** with activerecord **5.0**, using **mysql2**, **sqlite3** or **postgresql**
27
27
 
28
28
  <!-- SCHEMA_DEV: MATRIX - end -->
29
29
 
30
+ <aside class="warning">
31
+ As of version 2.0.0, `schema_plus_core` supports only ActiveRecord >= 5.0.
32
+ ActiveRecord 4.2.x is supported in version 1.x, maintained in the 1.x
33
+ branch.
34
+
35
+ ### Breaking changes in version 2.0 ###
36
+
37
+ * `SchemaPlus::Core::Schema::Tables` middleware was replaced by `SchemaPlus::Core::DataSources`. Parameters have also changed.
38
+ * `SchemaPlus::Core::Dumper::Indexes` middleware was removed; instead `SchemaPlus::Core::Dumper::Table` sets both columns and indexes on env.table.
30
39
 
31
40
  ## Installation
32
41
 
@@ -112,27 +121,23 @@ Stacks for general operations queries pertaining to the entire database schema:
112
121
 
113
122
  Wrapper around the `connection.indexes(table_name)` method. Env contains:
114
123
 
115
- Env Field | Description | Initial value
116
- --- | --- | ---
117
- `:index_definitions` | The result of the lookup | `[]`
118
- `:connection` | The current ActiveRecord connection | *context*
119
- `:table_name` | The name of the table to query | *arg*
120
- `:query_name` | Label sometimes used by ActiveRecord logging | *arg*
124
+ Env Field | Description | Initial value
125
+ -------------------- | -------------------------------------------- | -------------
126
+ `:index_definitions` | The result of the lookup | `[]`
127
+ `:connection` | The current ActiveRecord connection | *context*
128
+ `:table_name` | The name of the table to query | *arg*
129
+ `:query_name` | Label sometimes used by ActiveRecord logging | *arg*
121
130
 
122
131
  The base implementation appends its results to `env.index_definitions`
123
132
 
124
- * `Schema::Tables`
133
+ * `Schema::DataSources`
125
134
 
126
- Wrapper around the `connection.tables()` method. Env contains:
135
+ Wrapper around the `connection.data_sources()` method. Env contains:
127
136
 
128
- Env Field | Description | Initialized
129
- --- | --- | ---
130
- `:tables` | The result of the lookup | `[]`
131
- `:connection` | The current ActiveRecord connection | *context*
132
- `:table_name` | (SQlite3 only) | *arg*
133
- `:database` | (Mysql only) | *arg*
134
- `:like` | (Mysql only) | *arg*
135
- `:query_name` | Label sometimes used by ActiveRecord logging | *arg*
137
+ Env Field | Description | Initialized
138
+ --------------- | -------------------------------------------- | -----------
139
+ `:data_sources` | The result of the lookup | `[]`
140
+ `:connection` | The current ActiveRecord connection | *context*
136
141
 
137
142
  The base implementation appends its results to `env.tables`
138
143
 
@@ -393,12 +398,12 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
393
398
 
394
399
  Callback stack wraps the creation of initial statements for the dump.
395
400
 
396
- Env Field | Description | Initialized
397
- --- | --- | ---
398
- `:initial` | The initial statements | []
399
- `:dump` | The SchemaDump object | *context*
400
- `:dumper` | The current ActiveRecord::SchemaDumper instance| *context*
401
- `:connection` | The current ActiveRecord connection | *context*
401
+ Env Field | Description | Initialized
402
+ --- | --- | ---
403
+ `:initial` | The initial statements | []
404
+ `:dump` | The SchemaDump object | *context*
405
+ `:dumper` | The current ActiveRecord::SchemaDumper instance | *context*
406
+ `:connection` | The current ActiveRecord connection | *context*
402
407
 
403
408
  The base method appends initial statements to `env.initial`.
404
409
 
@@ -406,11 +411,11 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
406
411
 
407
412
  Callback stack wraps the dumping of all tables.
408
413
 
409
- Env Field | Description | Initialized
410
- --- | --- | ---
411
- `:dump` | The SchemaDump object | *context*
412
- `:dumper` | The current ActiveRecord::SchemaDumper instance| *context*
413
- `:connection` | The current ActiveRecord connection | *context*
414
+ Env Field | Description | Initialized
415
+ --- | --- | ---
416
+ `:dump` | The SchemaDump object | *context*
417
+ `:dumper` | The current ActiveRecord::SchemaDumper instance | *context*
418
+ `:connection` | The current ActiveRecord connection | *context*
414
419
 
415
420
  The base method iterates through all tables, dumping each.
416
421
 
@@ -419,33 +424,24 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
419
424
 
420
425
  Callback stack wraps the dumping of each table
421
426
 
422
- Env Field | Description | Initialized
423
- --- | --- | ---
424
- `:table` | A SchemaDump::Table object| `table.name` *only*
425
- `:dump` | The SchemaDump object | *context*
426
- `:dumper` | The current ActiveRecord::SchemaDumper instance| *context*
427
- `:connection` | The current ActiveRecord connection | *context*
427
+ Env Field | Description | Initialized
428
+ --- | --- | ---
429
+ `:table` | A SchemaDump::Table object | `table.name` *only*
430
+ `:dump` | The SchemaDump object | *context*
431
+ `:dumper` | The current ActiveRecord::SchemaDumper instance | *context*
432
+ `:connection` | The current ActiveRecord connection | *context*
428
433
 
429
434
  The base method iterates through all columns and indexes of the table, and *overwrites* the contents of `table`,
430
435
 
431
436
  Notes:
432
437
 
433
438
  1. When the stack is called, `env.dump.tables[env.table.name]` contains the `env.table` object.
434
-
435
- * `Dumper::Indexes`
436
-
437
- Callback stack wraps the dumping of the indexes of a table
438
-
439
- Env Field | Description | Initialized
440
- --- | --- | ---
441
- `:table` | A SchemaDump::Table object| *context*
442
- `:dump` | The SchemaDump object | *context*
443
- `:dumper` | The current ActiveRecord::SchemaDumper instance| *context*
444
- `:connection` | The current ActiveRecord connection | *context*
445
-
446
- The base method appends the collection of SchemaDump::Table::Index objects to `env.table.indexes`
439
+ 2. The base method sets *both* `env.table.columns` and `env.tables.indexes`.
447
440
 
448
441
  ## History
442
+
443
+ * 2.0.1 Tighten up AR dependency. Thanks to [@myabc](https://github.com/myabc).
444
+ * 2.0.0 Added AR5 support, removed AR4.2 support. Thanks to [@boazy](https://github.com/boazy).
449
445
  * 1.0.2 Missing require
450
446
  * 1.0.1 Explicit gem dependencies
451
447
  * 1.0.0 Clean up `SchemaDump::Table::Column` and `SchemaDump::Table::Index` API: `#options` is now a hash and `#comments` is now an array; no longer have `add_option` and `add_comment` methods.
@@ -1,3 +1,3 @@
1
1
  eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gem "activerecord", "~> 4.2.6"
3
+ gem "activerecord", ">= 5.0.0.beta1", "< 5.1"
@@ -2,7 +2,7 @@ require "pathname"
2
2
  eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
3
 
4
4
  platform :ruby do
5
- gem "mysql2", '>= 0.3.18', '< 0.5'
5
+ gem "mysql2"
6
6
  end
7
7
 
8
8
  platform :jruby do
@@ -34,10 +34,10 @@ module SchemaPlus
34
34
  }.index_definitions
35
35
  end
36
36
 
37
- def tables(query_name=nil, database=nil, like=nil)
38
- SchemaMonkey::Middleware::Schema::Tables.start(connection: self, query_name: query_name, database: database, like: like, tables: []) { |env|
39
- env.tables += super env.query_name, env.database, env.like
40
- }.tables
37
+ def data_sources
38
+ SchemaMonkey::Middleware::Schema::DataSources.start(connection: self, sources: []) { |env|
39
+ env.sources += super
40
+ }.sources
41
41
  end
42
42
 
43
43
  def select_rows(sql, name=nil, binds=[])
@@ -46,9 +46,9 @@ module SchemaPlus
46
46
  }.result
47
47
  end
48
48
 
49
- def exec_query(sql, name='SQL', binds=[])
50
- SchemaMonkey::Middleware::Query::Exec.start(connection: self, sql: sql, query_name: name, binds: binds) { |env|
51
- env.result = super env.sql, env.query_name, env.binds
49
+ def exec_query(sql, name='SQL', binds=[], prepare: false)
50
+ SchemaMonkey::Middleware::Query::Exec.start(connection: self, sql: sql, query_name: name, binds: binds, prepare: prepare) { |env|
51
+ env.result = super env.sql, env.query_name, env.binds, prepare: env.prepare
52
52
  }.result
53
53
  end
54
54
 
@@ -16,7 +16,7 @@ module SchemaPlus
16
16
  # expressions don't work well in AR anyway. (hence
17
17
  # schema_plus_default_expr )
18
18
  #
19
- def prepare_column_options(column, types) # :nodoc:
19
+ def prepare_column_options(column, *) # :nodoc:
20
20
  spec = super
21
21
  spec[:default] = "%q{#{column.default_function}}" if column.default_function
22
22
  spec
@@ -64,10 +64,10 @@ module SchemaPlus
64
64
  }.index_definitions
65
65
  end
66
66
 
67
- def tables(query_name=nil)
68
- SchemaMonkey::Middleware::Schema::Tables.start(connection: self, query_name: query_name, tables: []) { |env|
69
- env.tables += super env.query_name
70
- }.tables
67
+ def data_sources
68
+ SchemaMonkey::Middleware::Schema::DataSources.start(connection: self, sources: []) { |env|
69
+ env.sources += super
70
+ }.sources
71
71
  end
72
72
  end
73
73
  end
@@ -22,9 +22,9 @@ module SchemaPlus
22
22
  end
23
23
  end
24
24
 
25
- def exec_query(sql, name=nil, binds=[])
26
- SchemaMonkey::Middleware::Query::Exec.start(connection: self, sql: sql, query_name: name, binds: binds) { |env|
27
- env.result = super env.sql, env.query_name, env.binds
25
+ def exec_query(sql, name=nil, binds=[], prepare: false)
26
+ SchemaMonkey::Middleware::Query::Exec.start(connection: self, sql: sql, query_name: name, binds: binds, prepare: prepare) { |env|
27
+ env.result = super env.sql, env.query_name, env.binds, prepare: env.prepare
28
28
  }.result
29
29
  end
30
30
 
@@ -34,12 +34,11 @@ module SchemaPlus
34
34
  }.index_definitions
35
35
  end
36
36
 
37
- def tables(query_name=nil, table_name=nil)
38
- SchemaMonkey::Middleware::Schema::Tables.start(connection: self, query_name: query_name, table_name: table_name, tables: []) { |env|
39
- env.tables += super env.query_name, env.table_name
40
- }.tables
37
+ def data_sources
38
+ SchemaMonkey::Middleware::Schema::DataSources.start(connection: self, sources: []) { |env|
39
+ env.sources += super
40
+ }.sources
41
41
  end
42
-
43
42
  end
44
43
  end
45
44
  end
@@ -66,8 +66,9 @@ module SchemaPlus
66
66
  env.table.pname = m[:name]
67
67
  env.table.options = m[:options].strip
68
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{
69
+ table_objects = m[:columns].strip.split("\n").map { |col|
70
+ cs = col.strip
71
+ m = cs.match %r{
71
72
  ^
72
73
  t\.(?<type>\S+) \s*
73
74
  [:'"](?<name>[^"\s]+)[,"]? \s*
@@ -75,31 +76,32 @@ module SchemaPlus
75
76
  (?<options>.*)
76
77
  $
77
78
  }x
78
- SchemaDump::Table::Column.new name: m[:name], type: m[:type], options: eval("{" + m[:options] + "}"), comments: []
79
- }
79
+ if !m.nil?
80
+ SchemaDump::Table::Column.new name: m[:name], type: m[:type], options: eval("{" + m[:options] + "}"), comments: []
81
+ else
82
+ m = cs.match %r{
83
+ ^
84
+ t\.index \s*
85
+ \[(?<index_cols>.*?)\] \s*
86
+ , \s*
87
+ name\: \s* [:'"](?<name>[^"\s]+)[,"]? \s*
88
+ ,? \s*
89
+ (?<options>.*)
90
+ $
91
+ }x
92
+ if m.nil?
93
+ nil
94
+ else
95
+ index_cols = m[:index_cols].tr(%q{'":}, '').strip.split(/\s*,\s*/)
96
+ SchemaDump::Table::Index.new name: m[:name], columns: index_cols, options: eval("{#{m[:options]}}")
97
+ end
98
+ end
99
+ }.reject { |o| o.nil? }
100
+ env.table.columns = table_objects.select { |o| o.is_a? SchemaDump::Table::Column }
101
+ env.table.indexes = table_objects.select { |o| o.is_a? SchemaDump::Table::Index }
80
102
  end
81
103
  end
82
104
  end
83
-
84
- def indexes(table, _)
85
- SchemaMonkey::Middleware::Dumper::Indexes.start(dumper: self, connection: @connection, dump: @dump, table: @dump.tables[table]) do |env|
86
- stream = StringIO.new
87
- super env.table.name, stream
88
- env.table.indexes += stream.string.split("\n").map { |string|
89
- m = string.strip.match %r{
90
- ^
91
- add_index \s*
92
- [:'"](?<table>[^'"\s]+)['"]? \s* , \s*
93
- (?<columns>.*) \s*
94
- name: \s* [:'"](?<name>[^'"\s]+)['"]? \s*
95
- (, \s* (?<options>.*))?
96
- $
97
- }x
98
- columns = m[:columns].tr(%q{[]'":}, '').strip.split(/\s*,\s*/)
99
- SchemaDump::Table::Index.new name: m[:name], columns: columns, options: eval("{#{m[:options]}}")
100
- }
101
- end
102
- end
103
105
  end
104
106
  end
105
107
  end
@@ -3,7 +3,7 @@ module SchemaPlus
3
3
  module Middleware
4
4
  module Query
5
5
  module Exec
6
- ENV = [:connection, :sql, :query_name, :binds, :result]
6
+ ENV = [:connection, :sql, :query_name, :binds, :prepare, :result]
7
7
  end
8
8
  end
9
9
 
@@ -16,12 +16,9 @@ module SchemaPlus
16
16
  ENV = [:connection, :query_name, :table_name, :index_definitions]
17
17
  end
18
18
 
19
- module Tables
20
- # :database and :like are only for mysql
21
- # :table_name is only for sqlite3
22
- ENV = [:connection, :query_name, :table_name, :database, :like, :tables]
19
+ module DataSources
20
+ ENV = [:connection, :sources]
23
21
  end
24
-
25
22
  end
26
23
 
27
24
  module Migration
@@ -72,9 +69,6 @@ module SchemaPlus
72
69
  module Table
73
70
  ENV = [:dumper, :connection, :dump, :table]
74
71
  end
75
- module Indexes
76
- ENV = [:dumper, :connection, :dump, :table]
77
- end
78
72
  end
79
73
 
80
74
  module Model
@@ -63,20 +63,22 @@ module SchemaPlus
63
63
  stream.puts " do |t|"
64
64
  typelen = columns.map{|col| col.type.length}.max
65
65
  namelen = columns.map{|col| col.name.length}.max
66
+ indexes
66
67
  columns.each do |column|
67
68
  stream.write " "
68
69
  column.assemble(stream, typelen, namelen)
69
70
  stream.puts ""
70
71
  end
71
- statements.each do |statement|
72
- stream.puts " #{statement}"
73
- end
74
- stream.puts " end"
72
+ stream.puts "" unless indexes.empty?
75
73
  indexes.each do |index|
76
- stream.write " add_index #{pname.inspect}, "
74
+ stream.write " t.index "
77
75
  index.assemble(stream)
78
76
  stream.puts ""
79
77
  end
78
+ statements.each do |statement|
79
+ stream.puts " #{statement}"
80
+ end
81
+ stream.puts " end"
80
82
  trailer.each do |statement|
81
83
  stream.puts " #{statement}"
82
84
  end
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module Core
3
- VERSION = "1.0.2"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
@@ -9,7 +9,6 @@ module SchemaPlus
9
9
  DIR = Pathname.new(__FILE__).dirname + "core/active_record/connection_adapters"
10
10
  autoload :PostgresqlAdapter, DIR + "postgresql_adapter"
11
11
  autoload :Mysql2Adapter, DIR + "mysql2_adapter"
12
- autoload :AbstractMysqlAdapter, DIR + "abstract_mysql_adapter"
13
12
  autoload :Sqlite3Adapter, DIR + "sqlite3_adapter"
14
13
  end
15
14
  end
data/schema_dev.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  ruby:
2
- - 2.1.5
2
+ - 2.3.0
3
3
  activerecord:
4
- - 4.2
4
+ - 5.0
5
5
  db:
6
6
  - mysql2
7
7
  - sqlite3
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_dependency "activerecord", "~> 4.2"
21
+ gem.add_dependency "activerecord", "~> 5.0"
22
22
  gem.add_dependency "schema_monkey", "~> 2.1"
23
23
  gem.add_dependency "its-it", "~> 1.2"
24
24
 
@@ -26,7 +26,8 @@ Gem::Specification.new do |gem|
26
26
  gem.add_development_dependency "rake", "~> 10.0"
27
27
  gem.add_development_dependency "rspec", "~> 3.0.0"
28
28
  gem.add_development_dependency "rspec-given"
29
- gem.add_development_dependency "schema_dev", "~> 3.6"
29
+ gem.add_development_dependency "schema_dev", "~> 3.7"
30
30
  gem.add_development_dependency "simplecov"
31
31
  gem.add_development_dependency "simplecov-gem-profile"
32
+ gem.add_development_dependency "its-it"
32
33
  end
data/spec/column_spec.rb CHANGED
@@ -39,7 +39,7 @@ describe SchemaMonkey::Middleware::Migration::Column do
39
39
 
40
40
  context "when add ordinary column" do
41
41
  When { migration.create_table("things") { |t| t.integer "test_column" } }
42
- Then { expect(spy).to eq [
42
+ Then { expect(spy).to match_array [
43
43
  { column_name: "id", type: :primary_key, implements_reference: nil },
44
44
  { column_name: "test_column", type: :integer, implements_reference: nil }
45
45
  ] }
@@ -49,7 +49,7 @@ describe SchemaMonkey::Middleware::Migration::Column do
49
49
 
50
50
  context "when add reference using t.#{method}" do
51
51
  When { migration.create_table("things") { |t| t.send method, "test_reference" } }
52
- Then { expect(spy).to eq [
52
+ Then { expect(spy).to match_array [
53
53
  { column_name: "id", type: :primary_key, implements_reference: nil },
54
54
  { column_name: "test_reference_id", type: :reference, implements_reference: nil },
55
55
  { column_name: "test_reference_id", type: :integer, implements_reference: true }
@@ -58,7 +58,7 @@ describe SchemaMonkey::Middleware::Migration::Column do
58
58
 
59
59
  context "when add polymorphic reference using t.#{method}" do
60
60
  When { migration.create_table("things") { |t| t.send method, "test_reference", polymorphic: true } }
61
- Then { expect(spy).to eq [
61
+ Then { expect(spy).to match_array [
62
62
  { column_name: "id", type: :primary_key, implements_reference: nil },
63
63
  { column_name: "test_reference_id", type: :reference, implements_reference: nil },
64
64
  { column_name: "test_reference_id", type: :integer, implements_reference: true },
@@ -76,7 +76,7 @@ describe SchemaMonkey::Middleware::Migration::Column do
76
76
  context "when add reference using migration.add_reference" do
77
77
 
78
78
  When { migration.add_reference("things", "test_reference") }
79
- Then { expect(spy).to eq [
79
+ Then { expect(spy).to match_array [
80
80
  { column_name: "test_reference_id", type: :reference, implements_reference: nil },
81
81
  { column_name: "test_reference_id", type: :integer, implements_reference: true }
82
82
  ] }
@@ -87,7 +87,7 @@ describe SchemaMonkey::Middleware::Migration::Column do
87
87
  When {
88
88
  migration.add_reference("things", "test_reference", polymorphic: true)
89
89
  }
90
- Then { expect(spy).to eq [
90
+ Then { expect(spy).to match_array [
91
91
  { column_name: "test_reference_id", type: :reference, implements_reference: nil },
92
92
  { column_name: "test_reference_id", type: :integer, implements_reference: true },
93
93
  { column_name: "test_reference_type", type: :string, implements_reference: true }
data/spec/dumper_spec.rb CHANGED
@@ -27,18 +27,13 @@ module TestDumper
27
27
  column.options[:option] = middleware.to_s
28
28
  column.comments << "comment: #{middleware}"
29
29
  end
30
+ if index = env.table.indexes.first
31
+ index.options[:option] = middleware.to_s
32
+ end
30
33
  env.table.statements << "statement: #{middleware}"
31
34
  env.table.trailer << "trailer: #{middleware}"
32
35
  end
33
36
  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.options[:option] = middleware.to_s
40
- end
41
- end
42
37
  end
43
38
  end
44
39
  end
@@ -93,13 +88,9 @@ describe SchemaMonkey::Middleware::Dumper do
93
88
  Then { expect(dump).to match(/t[.]integer.*:option=>"#{middleware}" \# comment: #{middleware}/) }
94
89
  Then { expect(dump).to match(/statement: #{middleware}\s+end\s+(add_index.*)?\s+trailer: #{middleware}/) }
95
90
  Then { expect(dump).to match(/could not dump table.*custom_table.*unknown type.*custom_type/mi) } if TestCustomType
91
+ Then { expect(dump).to match(/t[.]index.*:option=>"#{middleware}"/) }
96
92
  end
97
93
 
98
- context TestDumper::Middleware::Dumper::Indexes do
99
- Then { expect(dump).to match(/add_index.*:option=>"#{middleware}"/) }
100
- end
101
-
102
-
103
94
  private
104
95
 
105
96
  def middleware
@@ -25,11 +25,12 @@ describe SchemaMonkey::Middleware do
25
25
  context SchemaMonkey::Middleware::Schema do
26
26
 
27
27
  context TestReporter::Middleware::Schema::Define do
28
+ ActiveRecord::Schema.define {}
28
29
  Then { expect_middleware { ActiveRecord::Schema.define { } } }
29
30
  end
30
31
 
31
- context TestReporter::Middleware::Schema::Tables do
32
- Then { expect_middleware { connection.tables() } }
32
+ context TestReporter::Middleware::Schema::DataSources do
33
+ Then { expect_middleware { connection.data_sources() } }
33
34
  end
34
35
 
35
36
  context TestReporter::Middleware::Schema::Indexes do
@@ -48,7 +49,7 @@ describe SchemaMonkey::Middleware do
48
49
  Then { expect_middleware(enable: {type: :reference}, env: {column_name: "ref_id"}) { migration.add_reference("things", "ref") } }
49
50
 
50
51
  Given(:change) {
51
- Class.new ::ActiveRecord::Migration do
52
+ Class.new ::ActiveRecord::Migration[5.0] do
52
53
  def change
53
54
  change_table("things") do |t|
54
55
  t.integer "column2"
@@ -136,16 +137,11 @@ describe SchemaMonkey::Middleware do
136
137
  Then { expect_middleware(env: {table: { name: "things"} }) { dump } }
137
138
  end
138
139
 
139
- context TestReporter::Middleware::Dumper::Indexes do
140
- Then { expect_middleware(env: {table: { name: "things"} }) { dump } }
141
- end
142
-
143
140
  private
144
141
 
145
142
  def dump
146
143
  ::ActiveRecord::SchemaDumper.dump(connection, StringIO.new)
147
144
  end
148
-
149
145
  end
150
146
 
151
147
  def table_statement(method, *args)
data/spec/spec_helper.rb CHANGED
@@ -22,7 +22,7 @@ RSpec.configure do |config|
22
22
  begin
23
23
  example.run
24
24
  ensure
25
- ActiveRecord::Base.connection.tables.each do |table|
25
+ ActiveRecord::Base.connection.data_sources.each do |table|
26
26
  ActiveRecord::Migration.drop_table table, force: :cascade
27
27
  end
28
28
  end
@@ -1,3 +1,5 @@
1
+ require "its-it"
2
+
1
3
  module Enableable
2
4
 
3
5
  def enabled_middleware(root, env)
@@ -27,7 +27,7 @@ module TestReporter
27
27
  module Schema
28
28
  module Define ; include Notify ; end
29
29
  module Indexes ; include Notify ; end
30
- module Tables ; include Notify ; end
30
+ module DataSources ; include Notify ; end
31
31
  end
32
32
 
33
33
  module Migration
@@ -56,7 +56,6 @@ module TestReporter
56
56
  module Initial ; include Notify ; end
57
57
  module Tables ; include Notify ; end
58
58
  module Table ; include Notify ; end
59
- module Indexes ; include Notify ; end
60
59
  end
61
60
  end
62
61
  end
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: 1.0.2
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: schema_monkey
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '3.6'
117
+ version: '3.7'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '3.6'
124
+ version: '3.7'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: its-it
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: Provides an internal extension API to ActiveRecord, in the form of middleware-style
154
168
  callback stacks
155
169
  email:
@@ -165,14 +179,13 @@ files:
165
179
  - README.md
166
180
  - Rakefile
167
181
  - gemfiles/Gemfile.base
168
- - gemfiles/activerecord-4.2/Gemfile.base
169
- - gemfiles/activerecord-4.2/Gemfile.mysql2
170
- - gemfiles/activerecord-4.2/Gemfile.postgresql
171
- - gemfiles/activerecord-4.2/Gemfile.sqlite3
182
+ - gemfiles/activerecord-5.0/Gemfile.base
183
+ - gemfiles/activerecord-5.0/Gemfile.mysql2
184
+ - gemfiles/activerecord-5.0/Gemfile.postgresql
185
+ - gemfiles/activerecord-5.0/Gemfile.sqlite3
172
186
  - lib/schema_plus/core.rb
173
187
  - lib/schema_plus/core/active_record/base.rb
174
188
  - lib/schema_plus/core/active_record/connection_adapters/abstract_adapter.rb
175
- - lib/schema_plus/core/active_record/connection_adapters/abstract_mysql_adapter.rb
176
189
  - lib/schema_plus/core/active_record/connection_adapters/mysql2_adapter.rb
177
190
  - lib/schema_plus/core/active_record/connection_adapters/postgresql_adapter.rb
178
191
  - lib/schema_plus/core/active_record/connection_adapters/sqlite3_adapter.rb
@@ -213,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
226
  version: '0'
214
227
  requirements: []
215
228
  rubyforge_project:
216
- rubygems_version: 2.2.2
229
+ rubygems_version: 2.5.1
217
230
  signing_key:
218
231
  specification_version: 4
219
232
  summary: Provides an internal extension API to ActiveRecord
@@ -1,17 +0,0 @@
1
- module SchemaPlus
2
- module Core
3
- module ActiveRecord
4
- module ConnectionAdapters
5
- module AbstractMysqlAdapter
6
- module SchemaCreation
7
- def visit_TableDefinition(o)
8
- SchemaMonkey::Middleware::Sql::Table.start(caller: self, connection: self.instance_variable_get('@conn'), table_definition: o, sql: SqlStruct::Table.new) { |env|
9
- env.sql.parse! super env.table_definition
10
- }.sql.assemble
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end