schema_plus_core 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: be82dc70c1337ef9fec4f7bcc88ad9011455bf86
4
- data.tar.gz: fb4f3f8aa09a494fc535b8c4e337f08ef43994c4
3
+ metadata.gz: 7c429be6c02483276cfb59a812bb4cc5f25b2177
4
+ data.tar.gz: 72cc5ab39f8876bf2d334c21f6ea6daa0198ba1f
5
5
  SHA512:
6
- metadata.gz: 59e8ed21ad18ee6dfbed44d4d70b2700a9617044a96d87746c61b8ca3d54aa4911d7c3c147fd7afa38ff8da0ee6242d9f5f0570b25aed6c1593d5db186768e49
7
- data.tar.gz: 53e646d5d164ce111e58b137dd0c4e07b129429699de0c913a638971ca94ad53076725ac9e2f28f266b6fe48a6b258bcbbcde384d1b3d0f23bc66bb9efe5693e
6
+ metadata.gz: f840686e345770edaa13e50ae1aa6eddf6a921020567bb8b0ef5edce4f3006a33cb4975d58ca9350e9772889e31900a18f8981ca3282558a868548d1214b944a
7
+ data.tar.gz: 6886022c5232b16f8e6700ff5eee18ac9c09041ef2e28a68a66eed27468811be321d48e0900a23fa2167bad15d3f620cf2d1aa7bbdfeae54a74badef38cea47c
data/README.md CHANGED
@@ -40,14 +40,6 @@ gem "schema_plus_core" # in a Gemfile
40
40
  gem.add_dependency "schema_plus_core" # in a .gemspec
41
41
  ```
42
42
 
43
- To use with a rails app, also include
44
-
45
- ```ruby
46
- gem "schema_monkey_rails"
47
- ```
48
-
49
- which creates a Railtie to that will insert SchemaPlus::Core appropriately into the rails stack. To use with Padrino, see [schema_monkey_padrino](https://github.com/SchemaPlus/schema_monkey_padrino).
50
-
51
43
  <!-- SCHEMA_DEV: TEMPLATE INSTALLATION - end -->
52
44
 
53
45
 
@@ -104,7 +96,18 @@ For organizational clarity, the SchemaPlus::Core stacks are grouped into modules
104
96
 
105
97
  ### Schema
106
98
 
107
- Stacks for general queries pertaining to the entire database schema:
99
+ Stacks for general operations queries pertaining to the entire database schema:
100
+
101
+ * `Schema::Define`
102
+
103
+ Wrapper around the `ActiveRecord::Schema.define` method loads a dumped schema file (`schema.rb`).
104
+
105
+ Env Field | Description | Initial value
106
+ --- | --- | ---
107
+ `:info` | Schema information hash | *args*
108
+ `:block` | The proc containing the schema definition statements | *args*
109
+
110
+ The base implementation calls the block to define the schema.
108
111
 
109
112
  * `Schema::Indexes`
110
113
 
@@ -191,6 +194,19 @@ Stacks for operations that change the schema. In some cases the operation immed
191
194
 
192
195
  3. ActiveRecord's base implementation may make nested calls to column creation. For example: References result in a nested call to create an integer column; Polymorphic references nest calls to create two columns; Sqlite3 implements `:change` by a nested call to a new table definition. SchemaPlus::Core doesn't attempt to normalize or suppress these; each such nested call will result in its own `Migration::Column` stack execution.
193
196
 
197
+ * `Migration::CreateTable`
198
+
199
+ Creates a new table
200
+
201
+ Env Field | Description | Initialized
202
+ --- | --- | ---
203
+ `:caller` | The ActiveRecord instance responsible for creating the table | *context*
204
+ `:table_name` | The name of the table | *arg*
205
+ `:options` | Create table options | *arg*
206
+ `:block` | Proc containing table definition statements | *arg*
207
+
208
+ The base implementation creates the table, yielding a `table_definition` instance to the block (if a block is given).
209
+
194
210
  * `Migration::DropTable`
195
211
 
196
212
  Drops a table from the database
@@ -199,7 +215,7 @@ Stacks for operations that change the schema. In some cases the operation immed
199
215
  --- | --- | ---
200
216
  `:connection` | The current ActiveRecord connection | *context*
201
217
  `:table_name` | The name of the table | *arg*
202
- `:options` | The index options | *arg*
218
+ `:options` | Drop table options | *arg*
203
219
 
204
220
  The base implementation drops the table. No value is returned.
205
221
 
@@ -439,6 +455,5 @@ Some things to know about to help you develop and test:
439
455
  [schema_monkey](https://github.com/SchemaPlus/schema_monkey) client,
440
456
  using [schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s
441
457
  convention-based protocols for extending ActiveRecord and using middleware stacks.
442
- For more information see [schema_monkey](https://github.com/SchemaPlus/schema_monkey)'s README.
443
458
 
444
459
  <!-- SCHEMA_DEV: TEMPLATE USES SCHEMA_MONKEY - end -->
@@ -18,6 +18,7 @@ require_relative "core/active_record/base"
18
18
  require_relative "core/active_record/connection_adapters/abstract_adapter"
19
19
  require_relative "core/active_record/connection_adapters/table_definition"
20
20
  require_relative "core/active_record/migration/command_recorder"
21
+ require_relative "core/active_record/schema"
21
22
  require_relative "core/active_record/schema_dumper"
22
23
  require_relative "core/middleware"
23
24
  require_relative "core/schema_dump"
@@ -10,24 +10,30 @@ module SchemaPlus
10
10
  end
11
11
  end
12
12
 
13
+ def add_index_options(table_name, column_names, options={})
14
+ SchemaMonkey::Middleware::Sql::IndexComponents.start(connection: self, table_name: table_name, column_names: Array.wrap(column_names), options: options.deep_dup, sql: SqlStruct::IndexComponents.new) { |env|
15
+ env.sql.name, env.sql.type, env.sql.columns, env.sql.options, env.sql.algorithm, env.sql.using = super env.table_name, env.column_names, env.options
16
+ }.sql.to_hash.values
17
+ end
18
+
13
19
  def add_reference(table_name, name, options = {})
14
20
  SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :add, table_name: table_name, column_name: "#{name}_id", type: :reference, options: options.deep_dup) do |env|
15
21
  super env.table_name, env.column_name.sub(/_id$/, ''), env.options
16
22
  end
17
23
  end
18
24
 
25
+ def create_table(table_name, options={}, &block)
26
+ SchemaMonkey::Middleware::Migration::CreateTable.start(connection: self, table_name: table_name, options: options.deep_dup, block: block) do |env|
27
+ super env.table_name, env.options, &env.block
28
+ end
29
+ end
30
+
19
31
  def drop_table(table_name, options={})
20
32
  SchemaMonkey::Middleware::Migration::DropTable.start(connection: self, table_name: table_name, options: options.dup) do |env|
21
33
  super env.table_name, env.options
22
34
  end
23
35
  end
24
36
 
25
- def add_index_options(table_name, column_names, options={})
26
- SchemaMonkey::Middleware::Sql::IndexComponents.start(connection: self, table_name: table_name, column_names: Array.wrap(column_names), options: options.deep_dup, sql: SqlStruct::IndexComponents.new) { |env|
27
- env.sql.name, env.sql.type, env.sql.columns, env.sql.options, env.sql.algorithm, env.sql.using = super env.table_name, env.column_names, env.options
28
- }.sql.to_hash.values
29
- end
30
-
31
37
  module SchemaCreation
32
38
 
33
39
  def add_column_options!(sql, options)
@@ -0,0 +1,13 @@
1
+ module SchemaPlus::Core
2
+ module ActiveRecord
3
+ module Schema
4
+ module ClassMethods
5
+ def define(info={}, &block)
6
+ SchemaMonkey::Middleware::Schema::Define.start(info: info, block: block) do |env|
7
+ super env.info, &env.block
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -8,16 +8,20 @@ module SchemaPlus
8
8
  end
9
9
 
10
10
  module Schema
11
- module Tables
12
- # :database and :like are only for mysql
13
- # :table_name is only for sqlite3
14
- ENV = [:connection, :query_name, :table_name, :database, :like, :tables]
11
+ module Define
12
+ ENV = [:info, :block]
15
13
  end
16
14
 
17
15
  module Indexes
18
16
  ENV = [:connection, :query_name, :table_name, :index_definitions]
19
17
  end
20
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]
23
+ end
24
+
21
25
  end
22
26
 
23
27
  module Migration
@@ -25,14 +29,19 @@ module SchemaPlus
25
29
  ENV = [:caller, :operation, :table_name, :column_name, :type, :options]
26
30
  end
27
31
 
28
- module Index
29
- ENV = [:caller, :operation, :table_name, :column_names, :options]
32
+ module CreateTable
33
+ ENV = [:connection, :table_name, :options, :block]
30
34
  end
31
35
 
32
36
  module DropTable
33
37
  ENV = [:connection, :table_name, :options]
34
38
  end
35
39
 
40
+ module Index
41
+ ENV = [:caller, :operation, :table_name, :column_names, :options]
42
+ end
43
+
44
+
36
45
  end
37
46
 
38
47
  module Sql
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module Core
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -19,13 +19,13 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_dependency "activerecord", "~> 4.2"
22
- gem.add_dependency "schema_monkey", "~> 2.0"
22
+ gem.add_dependency "schema_monkey", "~> 2.1"
23
23
 
24
24
  gem.add_development_dependency "bundler", "~> 1.7"
25
25
  gem.add_development_dependency "rake", "~> 10.0"
26
26
  gem.add_development_dependency "rspec", "~> 3.0.0"
27
27
  gem.add_development_dependency "rspec-given"
28
- gem.add_development_dependency "schema_dev", "~> 3.1"
28
+ gem.add_development_dependency "schema_dev", "~> 3.3"
29
29
  gem.add_development_dependency "simplecov"
30
30
  gem.add_development_dependency "simplecov-gem-profile"
31
31
  end
@@ -24,6 +24,10 @@ describe SchemaMonkey::Middleware do
24
24
 
25
25
  context SchemaMonkey::Middleware::Schema do
26
26
 
27
+ context TestReporter::Middleware::Schema::Define do
28
+ Then { expect_middleware { ActiveRecord::Schema.define { } } }
29
+ end
30
+
27
31
  context TestReporter::Middleware::Schema::Tables do
28
32
  Then { expect_middleware { connection.tables() } }
29
33
  end
@@ -59,6 +63,10 @@ describe SchemaMonkey::Middleware do
59
63
  Then { expect_middleware(enable: {type: :reference}, env: {operation: :define, column_name: "ref_id"}) { table_statement(:belongs_to, "ref") } }
60
64
  end
61
65
 
66
+ context TestReporter::Middleware::Migration::CreateTable do
67
+ Then { expect_middleware { connection.create_table "other" } }
68
+ end
69
+
62
70
  context TestReporter::Middleware::Migration::DropTable do
63
71
  Then { expect_middleware { connection.drop_table "things" } }
64
72
  end
@@ -25,14 +25,16 @@ module TestReporter
25
25
  end
26
26
 
27
27
  module Schema
28
- module Tables ; include Notify ; end
28
+ module Define ; include Notify ; end
29
29
  module Indexes ; include Notify ; end
30
+ module Tables ; include Notify ; end
30
31
  end
31
32
 
32
33
  module Migration
33
34
  module Column ; include Notify ; end
34
- module Index ; include Notify ; end
35
+ module CreateTable ; include Notify ; end
35
36
  module DropTable ; include Notify ; end
37
+ module Index ; include Notify ; end
36
38
  end
37
39
 
38
40
  module Sql
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.2.0
4
+ version: 0.2.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: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '3.1'
103
+ version: '3.3'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '3.1'
110
+ version: '3.3'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +164,7 @@ files:
164
164
  - lib/schema_plus/core/active_record/connection_adapters/sqlite3_adapter.rb
165
165
  - lib/schema_plus/core/active_record/connection_adapters/table_definition.rb
166
166
  - lib/schema_plus/core/active_record/migration/command_recorder.rb
167
+ - lib/schema_plus/core/active_record/schema.rb
167
168
  - lib/schema_plus/core/active_record/schema_dumper.rb
168
169
  - lib/schema_plus/core/middleware.rb
169
170
  - lib/schema_plus/core/schema_dump.rb