schema_plus_core 0.6.2 → 1.0.0

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: 5d71c54452ec75e70a08f2147dee0399dd7d5254
4
- data.tar.gz: 894a9d00c4de01e2e2d6a4b0c9f023ebd8c6fd0b
3
+ metadata.gz: 931e01737ac5749b51d990bfa8114372d6c2d136
4
+ data.tar.gz: af03d82fa6dbd69359cd92a85ddb2d0f074a3ac5
5
5
  SHA512:
6
- metadata.gz: 6fdffd10cc18ba2031dba7b03aaccd6db5ad2744c24ae17caf8bd474196f68dc4d1a33fe1e7912085c8913f01c4cb19b6ffd5dad7d60f3915e0e742bdd4bc60e
7
- data.tar.gz: 8d8dbcb1d7bee92a34e4e65156f56d25f2004ce8819235d368c5f22c8e3a29ce7f4375cadd80ca02bd81ce4bff9f3135190a7fc5c504ea7df0f625f1640d0902
6
+ metadata.gz: 39cdbc108fffe0448e25985532abe46ae8ba94297990fdd4a59893d3977c72227d479832136a3471785dc0b5713cb9ac29a0aeb58d6dc896e693a3c99d0156e5
7
+ data.tar.gz: 57f38c4464a784504498225f021346e3aeb1226100e7e7deccef7d622d11f8015a504d0d94aa955991cdcc6d0d70958d29320052243a6d656f4ee2a8ed77d0d8
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  /pkg
4
4
  /Gemfile.local
5
5
 
6
+ .byebug_history
6
7
  *.lock
7
8
  *.log
8
9
  *.sqlite3
data/README.md CHANGED
@@ -101,7 +101,7 @@ Stacks for general operations queries pertaining to the entire database schema:
101
101
  * `Schema::Define`
102
102
 
103
103
  Wrapper around the `ActiveRecord::Schema.define` method loads a dumped schema file (`schema.rb`).
104
-
104
+
105
105
  Env Field | Description | Initial value
106
106
  --- | --- | ---
107
107
  `:info` | Schema information hash | *args*
@@ -377,10 +377,8 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
377
377
 
378
378
  * `column.name` - the column name
379
379
  * `column.type` - the column type (i.e., what comes after `"t."`)
380
- * `column.options` - an optional string containing the options for the column
381
- * `column.comments` - an optional string containing a comment to put in the schema dump
382
- * `column.add_option(option)` - adds an option to the current string, separating with a "," if the current set isn't blank
383
- * `column.add_comment(comment)` - adds an option to the current string, separating with a ";" if the current string isn't blank
380
+ * `column.options` - a hash containing the options for the column
381
+ * `column.comments` - an array of comment strings for the column
384
382
 
385
383
  * `Class SchemaPlus::Core::SchemaDump::Table::Index`
386
384
 
@@ -388,8 +386,7 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
388
386
 
389
387
  * `index.name` - the index name
390
388
  * `index.columns` - the columns that are in the index
391
- * `index.options` - an optional string containing the options for the index
392
- * `index.add_option(option)` - adds an option to the current string, separating with a "," if the current set isn't blank
389
+ * `index.options` - a hash containing the options for the column
393
390
 
394
391
  #### Schema Dump Middleware stacks
395
392
 
@@ -450,14 +447,15 @@ SchemaPlus::Core provides a state object and of callbacks to various phases of t
450
447
  The base method appends the collection of SchemaDump::Table::Index objects to `env.table.indexes`
451
448
 
452
449
  ## History
450
+ * 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.
453
451
  * 0.6.2 Bug fix: don't choke on INHERITANCE in table definition (#7). Thanks to [@ADone](https://github.com/ADone).
454
452
  * 0.6.1 Make sure to require pathname (#5)
455
453
  * 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
456
- * 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
+ * 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)
457
455
  * 0.5.0 Added `Migration::DropTable`
458
456
  * 0.4.0 Added `implements_reference` to `Migration::Column` stack env
459
- * 0.3.1 Pass along (undocumented) return values from association declarations ([#2](https://github.com/SchemaPlus/schema_plus_core/pull/2)). Thanks to [@lowjoel](https://github.com/lowjoel)
460
- * 0.3.0 Added `Model::Association::Declaration` ([#1](https://github.com/SchemaPlus/schema_plus_core/pull/1)). Thanks to [@lowjoel](https://github.com/lowjoel).
457
+ * 0.3.1 Pass along (undocumented) return values from association declarations ([#2](https://github.com/SchemaPlus/schema_plus_core/pull/2)). Thanks to [@lowjoel](https://github.com/lowjoel)
458
+ * 0.3.0 Added `Model::Association::Declaration` ([#1](https://github.com/SchemaPlus/schema_plus_core/pull/1)). Thanks to [@lowjoel](https://github.com/lowjoel).
461
459
  * 0.2.1 Added `Migration::CreateTable` and `Schema::Define`; removed dependency on (defunct) `schema_monkey_rails` gem. [Oops, this should have been a minor version bump]
462
460
  * 0.2.0 Added `Migration::DropTable`
463
461
  * 0.1.0 Initial release
@@ -1,3 +1,3 @@
1
1
  eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gem "activerecord", "~> 4.2.0"
3
+ gem "activerecord", "~> 4.2.6"
@@ -2,9 +2,9 @@ require "pathname"
2
2
  eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
3
 
4
4
  platform :ruby do
5
- gem "mysql2"
5
+ gem "mysql2", '>= 0.3.18', '< 0.5'
6
6
  end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcmysql-adapter'
10
- end
10
+ end
@@ -4,6 +4,24 @@ module SchemaPlus
4
4
  module ConnectionAdapters
5
5
  module PostgresqlAdapter
6
6
 
7
+ # quick hack fix quoting of column default functions to allow eval() when we
8
+ # capture the stream.
9
+ #
10
+ # AR's PostgresqlAdapter#prepare_column_options wraps the
11
+ # function in double quotes, which doesn't work because the
12
+ # function itself may have doublequotes in it which don't get
13
+ # escaped properly.
14
+ #
15
+ # Arguably that's a bug in AR, but then again default function
16
+ # expressions don't work well in AR anyway. (hence
17
+ # schema_plus_default_expr )
18
+ #
19
+ def prepare_column_options(column, types) # :nodoc:
20
+ spec = super
21
+ spec[:default] = "%q{#{column.default_function}}" if column.default_function
22
+ spec
23
+ end
24
+
7
25
  def change_column(table_name, name, type, options = {})
8
26
  SchemaMonkey::Middleware::Migration::Column.start(caller: self, operation: :change, table_name: table_name, column_name: name, type: type, options: options.deep_dup) do |env|
9
27
  super env.table_name, env.column_name, env.type, env.options
@@ -75,7 +75,7 @@ module SchemaPlus
75
75
  (?<options>.*)
76
76
  $
77
77
  }x
78
- SchemaDump::Table::Column.new(name: m[:name], type: m[:type], options: m[:options])
78
+ SchemaDump::Table::Column.new name: m[:name], type: m[:type], options: eval("{" + m[:options] + "}"), comments: []
79
79
  }
80
80
  end
81
81
  end
@@ -96,7 +96,7 @@ module SchemaPlus
96
96
  $
97
97
  }x
98
98
  columns = m[:columns].tr(%q{[]'":}, '').strip.split(/\s*,\s*/)
99
- SchemaDump::Table::Index.new name: m[:name], columns: columns, options: m[:options]
99
+ SchemaDump::Table::Index.new name: m[:name], columns: columns, options: eval("{#{m[:options]}}")
100
100
  }
101
101
  end
102
102
  end
@@ -85,41 +85,25 @@ module SchemaPlus
85
85
 
86
86
  class Column < KeyStruct[:name, :type, :options, :comments]
87
87
 
88
- def add_option(option)
89
- self.options = [options, option].reject(&:blank?).join(', ')
90
- end
91
-
92
- def add_comment(comment)
93
- self.comments = [comments, comment].reject(&:blank?).join('; ')
94
- end
95
-
96
88
  def assemble(stream, typelen, namelen)
97
89
  stream.write "t.%-#{typelen}s " % type
98
90
  if options.blank? && comments.blank?
99
91
  stream.write name.inspect
100
92
  else
101
93
  pr = name.inspect
102
- pr += "," unless options.blank?
94
+ pr += ',' unless options.blank?
103
95
  stream.write "%-#{namelen+3}s " % pr
104
96
  end
105
- stream.write "#{options}" unless options.blank?
106
- stream.write " " unless options.blank? or comments.blank?
107
- stream.write "# #{comments}" unless comments.blank?
97
+ stream.write options.to_s.sub(/^{(.*)}$/, '\1') unless options.blank?
98
+ stream.write ' ' unless options.blank? or comments.blank?
99
+ stream.write '# ' + comments.join('; ') unless comments.blank?
108
100
  end
109
101
  end
110
102
 
111
103
  class Index < KeyStruct[:name, :columns, :options]
112
104
 
113
- def add_option(option)
114
- self.options = [options, option].reject(&:blank?).join(', ')
115
- end
116
-
117
105
  def assemble(stream)
118
- stream.write [
119
- columns.inspect,
120
- "name: #{name.inspect}",
121
- options
122
- ].reject(&:blank?).join(", ")
106
+ stream.write columns.inspect + ", " + {name: name}.merge(options).to_s.sub(/^{(.*)}$/, '\1')
123
107
  end
124
108
  end
125
109
  end
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module Core
3
- VERSION = "0.6.2"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
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.3"
28
+ gem.add_development_dependency "schema_dev", "~> 3.6"
29
29
  gem.add_development_dependency "simplecov"
30
30
  gem.add_development_dependency "simplecov-gem-profile"
31
31
  end
@@ -24,8 +24,8 @@ module TestDumper
24
24
  def after(env)
25
25
  return unless middleware = enabled_middleware(TestDumper, env)
26
26
  if column = env.table.columns.first
27
- column.add_option "option: #{middleware}"
28
- column.add_comment "comment: #{middleware}"
27
+ column.options[:option] = middleware.to_s
28
+ column.comments << "comment: #{middleware}"
29
29
  end
30
30
  env.table.statements << "statement: #{middleware}"
31
31
  env.table.trailer << "trailer: #{middleware}"
@@ -36,7 +36,7 @@ module TestDumper
36
36
  def after(env)
37
37
  return unless env.table.indexes.any?
38
38
  return unless middleware = enabled_middleware(TestDumper, env)
39
- env.table.indexes.first.add_option middleware.to_s
39
+ env.table.indexes.first.options[:option] = middleware.to_s
40
40
  end
41
41
  end
42
42
  end
@@ -72,6 +72,15 @@ describe SchemaMonkey::Middleware::Dumper do
72
72
  migration.execute "CREATE TABLE custom_table ( my_column custom_type DEFAULT 'a'::custom_type NOT NULL)" if TestCustomType
73
73
  end
74
74
 
75
+ context "column default expressions", postgresql: :only do
76
+
77
+ before(:each) do
78
+ migration.execute %Q{ALTER TABLE "things" ADD "defexpr" character varying DEFAULT substring((random())::text, 3, 6)}
79
+ end
80
+
81
+ Then { expect(dump use_middleware: false).to match(/\\"substring\\"\(\(random/) }
82
+ end
83
+
75
84
  context TestDumper::Middleware::Dumper::Initial do
76
85
  Then { expect(dump).to match(/Schema[.]define.*do\s+#{middleware}/) }
77
86
  end
@@ -81,13 +90,13 @@ describe SchemaMonkey::Middleware::Dumper do
81
90
  end
82
91
 
83
92
  context TestDumper::Middleware::Dumper::Table do
84
- Then { expect(dump).to match(/t[.]integer.*option: #{middleware} \# comment: #{middleware}/) }
93
+ Then { expect(dump).to match(/t[.]integer.*:option=>"#{middleware}" \# comment: #{middleware}/) }
85
94
  Then { expect(dump).to match(/statement: #{middleware}\s+end\s+(add_index.*)?\s+trailer: #{middleware}/) }
86
95
  Then { expect(dump).to match(/could not dump table.*custom_table.*unknown type.*custom_type/mi) } if TestCustomType
87
96
  end
88
97
 
89
98
  context TestDumper::Middleware::Dumper::Indexes do
90
- Then { expect(dump).to match(/add_index.*#{middleware}/) }
99
+ Then { expect(dump).to match(/add_index.*:option=>"#{middleware}"/) }
91
100
  end
92
101
 
93
102
 
@@ -97,14 +106,14 @@ describe SchemaMonkey::Middleware::Dumper do
97
106
  described_class
98
107
  end
99
108
 
100
- def dump
109
+ def dump(use_middleware: true)
101
110
  begin
102
- middleware.enable once:false
111
+ middleware.enable once:false if use_middleware
103
112
  stream = StringIO.new
104
113
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
105
114
  return stream.string
106
115
  ensure
107
- middleware.disable
116
+ middleware.disable if use_middleware
108
117
  end
109
118
  end
110
119
 
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.6.2
4
+ version: 1.0.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: 2016-01-16 00:00:00.000000000 Z
11
+ date: 2016-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '3.3'
103
+ version: '3.6'
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.3'
110
+ version: '3.6'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement