schema_plus 2.0.0.pre2 → 2.0.0.pre3
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 +4 -4
- data/.travis.yml +3 -3
- data/Gemfile +2 -0
- data/README.md +4 -4
- data/TODO.md +3 -10
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.base +1 -1
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.mysql2 +0 -0
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.postgresql +0 -0
- data/gemfiles/{rails-4.2 → activerecord-4.2}/Gemfile.sqlite3 +0 -0
- data/lib/schema_plus.rb +13 -121
- data/lib/schema_plus/version.rb +1 -1
- data/lib/schema_plus_columns.rb +7 -0
- data/lib/{schema_column_plus → schema_plus_columns}/active_record/connection_adapters/column.rb +1 -1
- data/lib/schema_plus_columns/middleware/model.rb +16 -0
- data/lib/schema_plus_db_default.rb +13 -0
- data/lib/{schema_db_default → schema_plus_db_default}/active_record/attribute.rb +4 -4
- data/lib/{schema_db_default → schema_plus_db_default}/db_default.rb +1 -1
- data/lib/schema_plus_db_default/middleware.rb +30 -0
- data/lib/{schema_default_expr.rb → schema_plus_default_expr.rb} +6 -6
- data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/mysql2_adapter.rb +1 -1
- data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/postgresql_adapter.rb +1 -1
- data/lib/{schema_default_expr → schema_plus_default_expr}/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
- data/lib/{schema_default_expr → schema_plus_default_expr}/middleware.rb +21 -19
- data/lib/schema_plus_enums.rb +6 -0
- data/lib/{schema_pg_enums → schema_plus_enums}/active_record.rb +1 -1
- data/lib/schema_plus_enums/middleware.rb +22 -0
- data/lib/schema_plus_foreign_keys.rb +96 -0
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/base.rb +2 -2
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/abstract_adapter.rb +7 -7
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/foreign_key_definition.rb +4 -4
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/mysql2_adapter.rb +9 -9
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/postgresql_adapter.rb +5 -5
- data/lib/schema_plus_foreign_keys/active_record/connection_adapters/schema_statements.rb +33 -0
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/sqlite3_adapter.rb +5 -5
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/connection_adapters/table_definition.rb +8 -8
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/migration/command_recorder.rb +5 -5
- data/lib/{schema_plus → schema_plus_foreign_keys}/active_record/schema.rb +7 -7
- data/lib/{schema_plus → schema_plus_foreign_keys}/middleware/dumper.rb +11 -26
- data/lib/{schema_plus → schema_plus_foreign_keys}/middleware/migration.rb +14 -15
- data/lib/schema_plus_foreign_keys/middleware/model.rb +15 -0
- data/lib/schema_plus_foreign_keys/version.rb +3 -0
- data/lib/schema_plus_views.rb +16 -0
- data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/abstract_adapter.rb +1 -1
- data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/mysql2_adapter.rb +1 -1
- data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/postgresql_adapter.rb +1 -1
- data/lib/{schema_views → schema_plus_views}/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
- data/lib/schema_plus_views/middleware.rb +49 -0
- data/schema_dev.yml +1 -1
- data/schema_plus.gemspec +3 -2
- data/spec/{schema_column_plus → schema_plus_columns}/column_spec.rb +0 -0
- data/spec/{schema_db_default → schema_plus_db_default}/column_spec.rb +1 -1
- data/spec/{schema_default_expr → schema_plus_default_expr}/column_default_spec.rb +0 -0
- data/spec/schema_plus_default_expr/migration_spec.rb +44 -0
- data/spec/{schema_default_expr → schema_plus_default_expr}/schema_dumper_spec.rb +2 -2
- data/spec/{schema_pg_enums → schema_plus_enums}/enum_spec.rb +0 -0
- data/spec/{schema_pg_enums → schema_plus_enums}/schema_dumper_spec.rb +0 -0
- data/spec/{foreign_key_definition_spec.rb → schema_plus_foreign_keys/foreign_key_definition_spec.rb} +0 -0
- data/spec/{foreign_key_spec.rb → schema_plus_foreign_keys/foreign_key_spec.rb} +2 -2
- data/spec/{migration_spec.rb → schema_plus_foreign_keys/migration_spec.rb} +13 -29
- data/spec/{named_schemas_spec.rb → schema_plus_foreign_keys/named_schemas_spec.rb} +0 -0
- data/spec/{schema_dumper_spec.rb → schema_plus_foreign_keys/schema_dumper_spec.rb} +2 -2
- data/spec/{schema_spec.rb → schema_plus_foreign_keys/schema_spec.rb} +7 -7
- data/spec/{schema_views → schema_plus_views}/named_schemas_spec.rb +7 -7
- data/spec/{schema_views → schema_plus_views}/views_spec.rb +0 -0
- data/spec/spec_helper.rb +3 -3
- metadata +102 -81
- data/init.rb +0 -1
- data/lib/schema_column_plus.rb +0 -7
- data/lib/schema_column_plus/middleware/model.rb +0 -22
- data/lib/schema_db_default.rb +0 -13
- data/lib/schema_db_default/middleware.rb +0 -30
- data/lib/schema_pg_enums.rb +0 -6
- data/lib/schema_pg_enums/middleware.rb +0 -23
- data/lib/schema_plus/active_record/connection_adapters/schema_statements.rb +0 -34
- data/lib/schema_plus/middleware/model.rb +0 -17
- data/lib/schema_views.rb +0 -16
- data/lib/schema_views/middleware.rb +0 -47
- data/spec/connection_spec.rb +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a80742e9f65732312bb80cd4adeb736affb95cd4
|
|
4
|
+
data.tar.gz: 89912fd50562d59cf9643e47b77a204b4444aa87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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/
|
|
12
|
-
- gemfiles/
|
|
13
|
-
- gemfiles/
|
|
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
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
|
|
72
|
-
* ruby **2.1.5** with
|
|
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
|
-
|
|
316
|
-
|
|
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
|
-
##
|
|
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
|
-
*
|
|
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
|
|
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?)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/lib/schema_plus.rb
CHANGED
|
@@ -1,133 +1,25 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require '
|
|
3
|
-
|
|
4
|
-
require '
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
125
|
-
|
|
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)
|
data/lib/schema_plus/version.rb
CHANGED
|
@@ -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
|
|
1
|
+
module SchemaPlusDbDefault
|
|
2
2
|
module ActiveRecord
|
|
3
3
|
module Attribute
|
|
4
4
|
def self.included(base)
|
|
5
|
-
base.alias_method_chain :original_value, :
|
|
5
|
+
base.alias_method_chain :original_value, :schema_plus_db_default
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
def
|
|
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
|
-
|
|
13
|
+
original_value_without_schema_plus_db_default
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
end
|
|
@@ -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 '
|
|
3
|
+
require_relative 'schema_plus_default_expr/middleware'
|
|
4
4
|
|
|
5
|
-
module
|
|
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, '
|
|
26
|
-
autoload :PostgresqlAdapter, '
|
|
27
|
-
autoload :Sqlite3Adapter, '
|
|
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(
|
|
32
|
+
SchemaMonkey.register(SchemaPlusDefaultExpr)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
module
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|