schema_plus 2.0.0.pre2 → 2.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/Gemfile +2 -0
  4. data/README.md +4 -4
  5. data/TODO.md +3 -10
  6. data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.base +1 -1
  7. data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.mysql2 +0 -0
  8. data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.postgresql +0 -0
  9. data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.sqlite3 +0 -0
  10. data/lib/schema_plus.rb +13 -121
  11. data/lib/schema_plus/version.rb +1 -1
  12. data/lib/schema_plus_columns.rb +7 -0
  13. data/lib/{schema_column_plus → schema_plus_columns}/active_record/connection_adapters/column.rb +1 -1
  14. data/lib/schema_plus_columns/middleware/model.rb +16 -0
  15. data/lib/schema_plus_db_default.rb +13 -0
  16. data/lib/{schema_db_default → schema_plus_db_default}/active_record/attribute.rb +4 -4
  17. data/lib/{schema_db_default → schema_plus_db_default}/db_default.rb +1 -1
  18. data/lib/schema_plus_db_default/middleware.rb +30 -0
  19. data/lib/{schema_default_expr.rb → schema_plus_default_expr.rb} +6 -6
  20. data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/mysql2_adapter.rb +1 -1
  21. data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/postgresql_adapter.rb +1 -1
  22. data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
  23. data/lib/{schema_default_expr → schema_plus_default_expr}/middleware.rb +21 -19
  24. data/lib/schema_plus_enums.rb +6 -0
  25. data/lib/{schema_pg_enums → schema_plus_enums}/active_record.rb +1 -1
  26. data/lib/schema_plus_enums/middleware.rb +22 -0
  27. data/lib/schema_plus_foreign_keys.rb +96 -0
  28. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/base.rb +2 -2
  29. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/abstract_adapter.rb +7 -7
  30. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/foreign_key_definition.rb +4 -4
  31. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/mysql2_adapter.rb +9 -9
  32. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/postgresql_adapter.rb +5 -5
  33. data/lib/schema_plus_foreign_keys/active_record/connection_adapters/schema_statements.rb +33 -0
  34. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/sqlite3_adapter.rb +5 -5
  35. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/table_definition.rb +8 -8
  36. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/migration/command_recorder.rb +5 -5
  37. data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/schema.rb +7 -7
  38. data/lib/{schema_plus → schema_plus_foreign_keys}/middleware/dumper.rb +11 -26
  39. data/lib/{schema_plus → schema_plus_foreign_keys}/middleware/migration.rb +14 -15
  40. data/lib/schema_plus_foreign_keys/middleware/model.rb +15 -0
  41. data/lib/schema_plus_foreign_keys/version.rb +3 -0
  42. data/lib/schema_plus_views.rb +16 -0
  43. data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/abstract_adapter.rb +1 -1
  44. data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/mysql2_adapter.rb +1 -1
  45. data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/postgresql_adapter.rb +1 -1
  46. data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
  47. data/lib/schema_plus_views/middleware.rb +49 -0
  48. data/schema_dev.yml +1 -1
  49. data/schema_plus.gemspec +3 -2
  50. data/spec/{schema_column_plus → schema_plus_columns}/column_spec.rb +0 -0
  51. data/spec/{schema_db_default → schema_plus_db_default}/column_spec.rb +1 -1
  52. data/spec/{schema_default_expr → schema_plus_default_expr}/column_default_spec.rb +0 -0
  53. data/spec/schema_plus_default_expr/migration_spec.rb +44 -0
  54. data/spec/{schema_default_expr → schema_plus_default_expr}/schema_dumper_spec.rb +2 -2
  55. data/spec/{schema_pg_enums → schema_plus_enums}/enum_spec.rb +0 -0
  56. data/spec/{schema_pg_enums → schema_plus_enums}/schema_dumper_spec.rb +0 -0
  57. data/spec/{foreign_key_definition_spec.rb → schema_plus_foreign_keys/foreign_key_definition_spec.rb} +0 -0
  58. data/spec/{foreign_key_spec.rb → schema_plus_foreign_keys/foreign_key_spec.rb} +2 -2
  59. data/spec/{migration_spec.rb → schema_plus_foreign_keys/migration_spec.rb} +13 -29
  60. data/spec/{named_schemas_spec.rb → schema_plus_foreign_keys/named_schemas_spec.rb} +0 -0
  61. data/spec/{schema_dumper_spec.rb → schema_plus_foreign_keys/schema_dumper_spec.rb} +2 -2
  62. data/spec/{schema_spec.rb → schema_plus_foreign_keys/schema_spec.rb} +7 -7
  63. data/spec/{schema_views → schema_plus_views}/named_schemas_spec.rb +7 -7
  64. data/spec/{schema_views → schema_plus_views}/views_spec.rb +0 -0
  65. data/spec/spec_helper.rb +3 -3
  66. metadata +102 -81
  67. data/init.rb +0 -1
  68. data/lib/schema_column_plus.rb +0 -7
  69. data/lib/schema_column_plus/middleware/model.rb +0 -22
  70. data/lib/schema_db_default.rb +0 -13
  71. data/lib/schema_db_default/middleware.rb +0 -30
  72. data/lib/schema_pg_enums.rb +0 -6
  73. data/lib/schema_pg_enums/middleware.rb +0 -23
  74. data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +0 -34
  75. data/lib/schema_plus/middleware/model.rb +0 -17
  76. data/lib/schema_views.rb +0 -16
  77. data/lib/schema_views/middleware.rb +0 -47
  78. data/spec/connection_spec.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b7cafb63e57f4fa258f90908feff00e0e2b7dc0
4
- data.tar.gz: 64c3b8e806e0ea043cf452f0b4e76cf29284d86c
3
+ metadata.gz: a80742e9f65732312bb80cd4adeb736affb95cd4
4
+ data.tar.gz: 89912fd50562d59cf9643e47b77a204b4444aa87
5
5
  SHA512:
6
- metadata.gz: c30f67be8321db51e354b2f143dfd80b7f07fdb09f4dd61545e52e62d55586b8a91cc473d33dd55236c44a73155285681ab918fc36fc81038e3f285768eb84e7
7
- data.tar.gz: 0fe7149f1e8dcf69ff94b80966da3227f765ca2df725883b40af5f224b39ebc58c443bdb95acc44c08bbf6c7324fb41b1e4634a111249a17359d40a828420706
6
+ metadata.gz: 29653f610f9e22ade23744e9ff9178111f3cb22afbe46c28cf557c38339e8498339ba719b525456d930361e5af4ff69bb7ab4112b627fc27d449360d9408e07f
7
+ data.tar.gz: 1ca7e5dfbc8be73af6535bc26c423541f8a3ab0d7ae49806d6d400bf1b4e0e84b05c63871c2c8b50c8b9e146d929cdc5e93a89e323ddc3ab47607c5ef28b9b3d
data/.travis.yml CHANGED
@@ -8,9 +8,9 @@ rvm:
8
8
  - 1.9.3
9
9
  - 2.1.5
10
10
  gemfile:
11
- - gemfiles/rails-4.2/Gemfile.mysql2
12
- - gemfiles/rails-4.2/Gemfile.postgresql
13
- - gemfiles/rails-4.2/Gemfile.sqlite3
11
+ - gemfiles/activerecord-4.2/Gemfile.mysql2
12
+ - gemfiles/activerecord-4.2/Gemfile.postgresql
13
+ - gemfiles/activerecord-4.2/Gemfile.sqlite3
14
14
  env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
15
15
  addons:
16
16
  postgresql: '9.3'
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ File.exist?(gemfile_local = File.expand_path('../Gemfile.local', __FILE__)) and eval File.read(gemfile_local), binding, gemfile_local
data/README.md CHANGED
@@ -68,8 +68,8 @@ SchemaPlus 2.x is tested against all combinations of:
68
68
 
69
69
  <!-- SCHEMA_DEV: MATRIX - begin -->
70
70
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
71
- * ruby **1.9.3** with rails **4.2**, using **mysql2**, **sqlite3** or **postgresql**
72
- * ruby **2.1.5** with rails **4.2**, using **mysql2**, **sqlite3** or **postgresql**
71
+ * ruby **1.9.3** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
72
+ * ruby **2.1.5** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
73
73
 
74
74
  <!-- SCHEMA_DEV: MATRIX - end -->
75
75
 
@@ -312,8 +312,8 @@ your schema.rb file by hand, and would like to take advantage of auto-creation
312
312
  of foreign key constraints, you can re-enable it:
313
313
 
314
314
  ActiveRecord::Schema.define do
315
- SchemaPlus.config.foreign_keys.auto_create = true
316
- SchemaPlus.config.foreign_keys.auto_index = true
315
+ SchemaPlusForeignKeys.config.auto_create = true
316
+ SchemaPlusForeignKeys.config.auto_index = true
317
317
 
318
318
  create_table ...etc...
319
319
  end
data/TODO.md CHANGED
@@ -1,7 +1,6 @@
1
1
  ## ALL
2
2
 
3
3
  * ideally get rid of all uses of alias_method_chain outside schema_monkey (create middleware)
4
- * rename everything to schema_plus_* (except schema_monkey and schema_plus)
5
4
 
6
5
  ## schema_plus_tables
7
6
 
@@ -12,9 +11,7 @@
12
11
  ## schema_plus_index
13
12
  * remove index specs that are testing things now handled by AR. (then see if coverage is still 100%)
14
13
 
15
- ## schema_plus
16
- * deprecate config => SchemaForeignKeys config
17
- * move fk stuff into schema_foreign_keys
14
+ ## schema_plus_foreign_keys
18
15
  * add specs to cover the deprecations
19
16
  * just do fk enhancements rather than replace AR's add_foreign_key and remove_foreign_key methods and foreign key lookups
20
17
 
@@ -31,7 +28,7 @@
31
28
  * @dump should include the header for consistency
32
29
  * specs for schema_monkey
33
30
  * README to document it -- the conventions and internal API
34
- * (try it on AR 4.1? nah)
31
+ * pull out schema_monkey_rails into its own gem
35
32
 
36
33
  ## general
37
34
  * rename schema_pg_enum to just schema_enum?
@@ -40,12 +37,8 @@
40
37
 
41
38
  ## schema_dev things:
42
39
 
43
- * boilerplate in README regarding the schema_plus family?
44
- * boilerplate in README regarding test matrix?
45
- * default 'rspec'
40
+ * boilerplate in README regarding installation, especially if schema_monkey_rails gets pulled out
46
41
  * don't bother changing ruby if it's the current version anyway.
47
- * rename 'refresh' to 'freshen'; get rid of the individual travis & gem commands
48
42
  * have a .schema_dev file with current settings
49
43
  * make it obvious and easy to override
50
44
  * auto update .gitignore to ignore it?
51
- * log files should go in log/ not in tmp/ (auto update .gitignore to ignore it?)
@@ -1,3 +1,3 @@
1
1
  eval File.read File.expand_path('../../Gemfile.base', __FILE__)
2
2
 
3
- gem "rails", "~> 4.2.0"
3
+ gem "activerecord", "~> 4.2.0"
data/lib/schema_plus.rb CHANGED
@@ -1,133 +1,25 @@
1
- require 'active_record'
2
- require 'valuable'
3
-
4
- require 'schema_monkey'
1
+ require 'schema_monkey_rails'
2
+ require 'schema_plus_columns'
3
+ require 'schema_plus_db_default'
4
+ require 'schema_plus_default_expr'
5
+ require 'schema_plus_enums'
6
+ require 'schema_plus_foreign_keys'
5
7
  require 'schema_plus_indexes'
6
8
  require 'schema_plus_pg_indexes'
7
-
8
- require 'schema_column_plus'
9
- require 'schema_db_default'
10
- require 'schema_default_expr'
11
- require 'schema_pg_enums'
12
- require 'schema_views'
13
9
  require 'schema_plus_tables'
10
+ require 'schema_plus_views'
14
11
 
15
- require 'schema_plus/version'
16
- require 'schema_plus/active_record/base'
17
- require 'schema_plus/active_record/connection_adapters/abstract_adapter'
18
- require 'schema_plus/active_record/connection_adapters/table_definition'
19
- require 'schema_plus/active_record/connection_adapters/schema_statements'
20
- require 'schema_plus/active_record/schema'
21
- require 'schema_plus/active_record/connection_adapters/foreign_key_definition'
22
- require 'schema_plus/active_record/migration/command_recorder'
23
- require 'schema_plus/middleware/dumper'
24
- require 'schema_plus/middleware/migration'
25
- require 'schema_plus/middleware/model'
12
+ require_relative 'schema_plus/version'
26
13
 
27
14
  module SchemaPlus
28
- module ActiveRecord
29
-
30
- module ConnectionAdapters
31
- autoload :Mysql2Adapter, 'schema_plus/active_record/connection_adapters/mysql2_adapter'
32
- autoload :PostgresqlAdapter, 'schema_plus/active_record/connection_adapters/postgresql_adapter'
33
- autoload :Sqlite3Adapter, 'schema_plus/active_record/connection_adapters/sqlite3_adapter'
15
+ class DeprecatedConfig
16
+ def foreign_keys
17
+ SchemaPlusForeignKeys.config
34
18
  end
35
19
  end
36
20
 
37
- # This global configuation options for SchemaPlus.
38
- # Set them in +config/initializers/schema_plus.rb+ using:
39
- #
40
- # SchemaPlus.setup do |config|
41
- # ...
42
- # end
43
- #
44
- # The options are grouped into subsets based on area of functionality.
45
- # See Config::ForeignKeys
46
- #
47
- class Config < Valuable
48
-
49
- # This set of configuration options control SchemaPlus's foreign key
50
- # constraint behavior. Set them in
51
- # +config/initializers/schema_plus.rb+ using:
52
- #
53
- # SchemaPlus.setup do |config|
54
- # config.foreign_keys.auto_create = ...
55
- # end
56
- #
57
- class ForeignKeys < Valuable
58
- ##
59
- # :attr_accessor: auto_create
60
- #
61
- # Whether to automatically create foreign key constraints for columns
62
- # suffixed with +_id+. Boolean, default is +true+.
63
- has_value :auto_create, :klass => :boolean, :default => true
64
-
65
- ##
66
- # :attr_accessor: auto_index
67
- #
68
- # Whether to automatically create indexes when creating foreign key constraints for columns.
69
- # Boolean, default is +true+.
70
- has_value :auto_index, :klass => :boolean, :default => true
71
-
72
- ##
73
- # :attr_accessor: on_update
74
- #
75
- # The default value for +:on_update+ when creating foreign key
76
- # constraints for columns. Valid values are as described in
77
- # ForeignKeyDefinition, or +nil+ to let the database connection use
78
- # its own default. Default is +nil+.
79
- has_value :on_update
80
-
81
- ##
82
- # :attr_accessor: on_delete
83
- #
84
- # The default value for +:on_delete+ when creating foreign key
85
- # constraints for columns. Valid values are as described in
86
- # ForeignKeyDefinition, or +nil+ to let the database connection use
87
- # its own default. Default is +nil+.
88
- has_value :on_delete
89
- end
90
- has_value :foreign_keys, :klass => ForeignKeys, :default => ForeignKeys.new
91
-
92
- def dup #:nodoc:
93
- self.class.new(Hash[attributes.collect{ |key, val| [key, Valuable === val ? val.class.new(val.attributes) : val] }])
94
- end
95
-
96
- def update_attributes(opts)#:nodoc:
97
- opts = opts.dup
98
- opts.keys.each { |key| self.send(key).update_attributes(opts.delete(key)) if self.class.attributes.include? key and Hash === opts[key] }
99
- super(opts)
100
- self
101
- end
102
-
103
- def merge(opts)#:nodoc:
104
- dup.update_attributes(opts)
105
- end
106
-
107
- end
108
-
109
- # Returns the global configuration, i.e., the singleton instance of Config
110
- def self.config
111
- @config ||= Config.new
112
- end
113
-
114
- # Initialization block is passed a global Config instance that can be
115
- # used to configure SchemaPlus behavior. E.g., if you want to disable
116
- # automation creation of foreign key constraints for columns name *_id,
117
- # put the following in config/initializers/schema_plus.rb :
118
- #
119
- # SchemaPlus.setup do |config|
120
- # config.foreign_keys.auto_create = false
121
- # end
122
- #
123
21
  def self.setup # :yields: config
124
- yield config
125
- end
126
-
127
- def self.insert #:nodoc:
128
- SchemaMonkey.include_once ::ActiveRecord::ConnectionAdapters::AbstractAdapter::SchemaCreation, SchemaPlus::ActiveRecord::ConnectionAdapters::AbstractAdapter::VisitTableDefinition
22
+ ActiveSupport::Deprecation.warning "SchemaPlus.setup is deprecated. Use SchemaPlusForeignKeys.setup instead"
23
+ yield DeprecatedConfig.new
129
24
  end
130
-
131
25
  end
132
-
133
- SchemaMonkey.register(SchemaPlus)
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "2.0.0.pre2"
2
+ VERSION = "2.0.0.pre3"
3
3
  end
@@ -0,0 +1,7 @@
1
+ require 'schema_monkey'
2
+ require 'schema_plus_indexes'
3
+
4
+ require_relative 'schema_plus_columns/active_record/connection_adapters/column'
5
+ require_relative 'schema_plus_columns/middleware/model'
6
+
7
+ SchemaMonkey.register(SchemaPlusColumns)
@@ -1,4 +1,4 @@
1
- module SchemaColumnPlus
1
+ module SchemaPlusColumns
2
2
  module ActiveRecord
3
3
  module ConnectionAdapters
4
4
 
@@ -0,0 +1,16 @@
1
+ module SchemaPlusColumns
2
+ module Middleware
3
+ module Model
4
+
5
+ module Columns
6
+
7
+ def after(env)
8
+ env.columns.each do |column|
9
+ column.model = env.model
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require 'schema_monkey'
2
+
3
+ require_relative 'schema_plus_db_default/active_record/attribute'
4
+ require_relative 'schema_plus_db_default/db_default'
5
+ require_relative 'schema_plus_db_default/middleware'
6
+
7
+ module SchemaPlusDbDefault
8
+ def self.insert
9
+ ::ActiveRecord.const_set(:DB_DEFAULT, SchemaPlusDbDefault::DB_DEFAULT)
10
+ end
11
+ end
12
+
13
+ SchemaMonkey.register(SchemaPlusDbDefault)
@@ -1,16 +1,16 @@
1
- module SchemaDbDefault
1
+ module SchemaPlusDbDefault
2
2
  module ActiveRecord
3
3
  module Attribute
4
4
  def self.included(base)
5
- base.alias_method_chain :original_value, :schema_db_default
5
+ base.alias_method_chain :original_value, :schema_plus_db_default
6
6
  end
7
7
 
8
- def original_value_with_schema_db_default
8
+ def original_value_with_schema_plus_db_default
9
9
  # prevent attempts to cast DB_DEFAULT to the attributes type.
10
10
  # We want to keep it as DB_DEFAULT so that we can handle it when
11
11
  # generating the sql.
12
12
  return DB_DEFAULT if value_before_type_cast.equal? DB_DEFAULT
13
- original_value_without_schema_db_default
13
+ original_value_without_schema_plus_db_default
14
14
  end
15
15
 
16
16
  end
@@ -1,6 +1,6 @@
1
1
  require 'singleton'
2
2
 
3
- module SchemaDbDefault
3
+ module SchemaPlusDbDefault
4
4
  class DbDefault
5
5
  include Singleton
6
6
  def to_s
@@ -0,0 +1,30 @@
1
+ module SchemaPlusDbDefault
2
+ module Middleware
3
+
4
+ module Query
5
+ module ExecCache
6
+
7
+ module Postgresql
8
+
9
+ # Middleware to replace each ActiveRecord::DB_DEFAULT with a literal
10
+ # DEFAULT in the sql string, for postgresql. The underlying pg gem provides no
11
+ # way to bind a value that will replace $n with DEFAULT.
12
+ def before(env)
13
+ if env.binds.any?{ |col, val| val.equal? ::ActiveRecord::DB_DEFAULT}
14
+ j = 0
15
+ env.binds.each_with_index do |(col, val), i|
16
+ if val.equal? ::ActiveRecord::DB_DEFAULT
17
+ env.sql = env.sql.sub(/\$#{i+1}/, 'DEFAULT')
18
+ else
19
+ env.sql = env.sql.sub(/\$#{i+1}/, "$#{j+1}") if i != j
20
+ j += 1
21
+ end
22
+ end
23
+ env.binds = env.binds.reject{|col, val| val.equal? ::ActiveRecord::DB_DEFAULT}
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,8 +1,8 @@
1
1
  require 'schema_monkey'
2
2
 
3
- require_relative 'schema_default_expr/middleware'
3
+ require_relative 'schema_plus_default_expr/middleware'
4
4
 
5
- module SchemaDefaultExpr
5
+ module SchemaPlusDefaultExpr
6
6
  module ActiveRecord
7
7
  module ConnectionAdapters
8
8
  #
@@ -22,11 +22,11 @@ module SchemaDefaultExpr
22
22
  # Currently, the only function to support is :now, which should
23
23
  # return a DATETIME object for the current time.
24
24
  #
25
- autoload :Mysql2Adapter, 'schema_default_expr/active_record/connection_adapters/mysql2_adapter'
26
- autoload :PostgresqlAdapter, 'schema_default_expr/active_record/connection_adapters/postgresql_adapter'
27
- autoload :Sqlite3Adapter, 'schema_default_expr/active_record/connection_adapters/sqlite3_adapter'
25
+ autoload :Mysql2Adapter, 'schema_plus_default_expr/active_record/connection_adapters/mysql2_adapter'
26
+ autoload :PostgresqlAdapter, 'schema_plus_default_expr/active_record/connection_adapters/postgresql_adapter'
27
+ autoload :Sqlite3Adapter, 'schema_plus_default_expr/active_record/connection_adapters/sqlite3_adapter'
28
28
  end
29
29
  end
30
30
  end
31
31
 
32
- SchemaMonkey.register(SchemaDefaultExpr)
32
+ SchemaMonkey.register(SchemaPlusDefaultExpr)
@@ -1,4 +1,4 @@
1
- module SchemaDefaultExpr
1
+ module SchemaPlusDefaultExpr
2
2
  module ActiveRecord
3
3
  module ConnectionAdapters
4
4
  module Mysql2Adapter
@@ -1,4 +1,4 @@
1
- module SchemaDefaultExpr
1
+ module SchemaPlusDefaultExpr
2
2
  module ActiveRecord
3
3
  module ConnectionAdapters
4
4
  module PostgresqlAdapter
@@ -1,4 +1,4 @@
1
- module SchemaDefaultExpr
1
+ module SchemaPlusDefaultExpr
2
2
  module ActiveRecord
3
3
  module ConnectionAdapters
4
4
 
@@ -1,14 +1,14 @@
1
- module SchemaDefaultExpr
1
+ module SchemaPlusDefaultExpr
2
2
  module Middleware
3
- def self.insert
4
- SchemaMonkey::Middleware::Migration::ColumnOptionsSql.prepend DefaultExprOptions
5
- SchemaMonkey::Middleware::Dumper::Table.append DumpDefaultExpressions
6
- end
7
3
 
8
- class DefaultExprOptions < ::SchemaMonkey::Middleware::Base
9
- def call(env)
10
- options = env.options
11
- if env.caller.options_include_default?(options)
4
+ module Migration
5
+ module ColumnOptionsSql
6
+
7
+ # Add options for default expressions
8
+ def before(env)
9
+ options = env.options
10
+ return unless env.caller.options_include_default?(options)
11
+
12
12
  default = options[:default]
13
13
 
14
14
  if default.is_a? Hash and [[:expr], [:value]].include?(default.keys)
@@ -32,19 +32,21 @@ module SchemaDefaultExpr
32
32
  options[:default] = value
33
33
  end
34
34
  end
35
- continue env
36
35
  end
37
36
  end
38
37
 
39
- class DumpDefaultExpressions < SchemaMonkey::Middleware::Base
40
- def call(env)
41
- continue env
42
- env.connection.columns(env.table.name).each do |column|
43
- if !column.default_function.nil?
44
- if col = env.table.columns.find{|col| col.name == column.name}
45
- options = "default: { expr: #{column.default_function.inspect} }"
46
- options += ", #{col.options}" unless col.options.blank?
47
- col.options = options
38
+ module Dumper
39
+ module Table
40
+
41
+ # Emit default expression options in dump
42
+ def after(env)
43
+ env.connection.columns(env.table.name).each do |column|
44
+ if !column.default_function.nil?
45
+ if col = env.table.columns.find{|col| col.name == column.name}
46
+ options = "default: { expr: #{column.default_function.inspect} }"
47
+ options += ", #{col.options}" unless col.options.blank?
48
+ col.options = options
49
+ end
48
50
  end
49
51
  end
50
52
  end