activerecord 4.0.0.beta1 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +573 -30
  3. data/README.rdoc +3 -3
  4. data/lib/active_record.rb +8 -2
  5. data/lib/active_record/associations.rb +16 -9
  6. data/lib/active_record/associations/association.rb +8 -6
  7. data/lib/active_record/associations/association_scope.rb +2 -1
  8. data/lib/active_record/associations/belongs_to_association.rb +2 -2
  9. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +1 -1
  10. data/lib/active_record/associations/builder/belongs_to.rb +37 -5
  11. data/lib/active_record/associations/collection_association.rb +38 -14
  12. data/lib/active_record/associations/collection_proxy.rb +18 -15
  13. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +3 -3
  14. data/lib/active_record/associations/has_many_association.rb +4 -3
  15. data/lib/active_record/associations/has_many_through_association.rb +1 -1
  16. data/lib/active_record/associations/has_one_association.rb +1 -1
  17. data/lib/active_record/associations/join_dependency.rb +29 -8
  18. data/lib/active_record/associations/join_dependency/join_association.rb +26 -6
  19. data/lib/active_record/associations/join_dependency/join_base.rb +2 -2
  20. data/lib/active_record/associations/join_dependency/join_part.rb +6 -6
  21. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +1 -1
  22. data/lib/active_record/associations/preloader/has_many_through.rb +6 -2
  23. data/lib/active_record/associations/through_association.rb +1 -1
  24. data/lib/active_record/attribute_assignment.rb +5 -5
  25. data/lib/active_record/attribute_methods.rb +20 -5
  26. data/lib/active_record/attribute_methods/dirty.rb +5 -1
  27. data/lib/active_record/attribute_methods/primary_key.rb +1 -1
  28. data/lib/active_record/attribute_methods/serialization.rb +9 -2
  29. data/lib/active_record/autosave_association.rb +19 -5
  30. data/lib/active_record/base.rb +3 -3
  31. data/lib/active_record/callbacks.rb +1 -1
  32. data/lib/active_record/coders/yaml_column.rb +8 -13
  33. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +3 -9
  34. data/lib/active_record/connection_adapters/abstract/database_limits.rb +1 -1
  35. data/lib/active_record/connection_adapters/abstract/database_statements.rb +2 -1
  36. data/lib/active_record/connection_adapters/abstract/quoting.rb +2 -8
  37. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +60 -61
  38. data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +13 -2
  39. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +291 -153
  40. data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -1
  41. data/lib/active_record/connection_adapters/abstract_adapter.rb +92 -1
  42. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +55 -29
  43. data/lib/active_record/connection_adapters/column.rb +4 -4
  44. data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
  45. data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -3
  46. data/lib/active_record/connection_adapters/mysql_adapter.rb +5 -5
  47. data/lib/active_record/connection_adapters/postgresql/cast.rb +22 -2
  48. data/lib/active_record/connection_adapters/postgresql/oid.rb +25 -6
  49. data/lib/active_record/connection_adapters/postgresql/quoting.rb +26 -13
  50. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +50 -9
  51. data/lib/active_record/connection_adapters/postgresql_adapter.rb +53 -24
  52. data/lib/active_record/connection_adapters/schema_cache.rb +35 -7
  53. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +13 -5
  54. data/lib/active_record/connection_handling.rb +7 -7
  55. data/lib/active_record/core.rb +43 -8
  56. data/lib/active_record/counter_cache.rb +2 -1
  57. data/lib/active_record/errors.rb +11 -10
  58. data/lib/active_record/explain.rb +9 -7
  59. data/lib/active_record/explain_registry.rb +30 -0
  60. data/lib/active_record/explain_subscriber.rb +3 -2
  61. data/lib/active_record/fixture_set/file.rb +1 -2
  62. data/lib/active_record/fixtures.rb +13 -7
  63. data/lib/active_record/inheritance.rb +12 -4
  64. data/lib/active_record/integration.rb +3 -3
  65. data/lib/active_record/locking/optimistic.rb +2 -2
  66. data/lib/active_record/log_subscriber.rb +2 -2
  67. data/lib/active_record/migration.rb +69 -21
  68. data/lib/active_record/model_schema.rb +1 -1
  69. data/lib/active_record/nested_attributes.rb +98 -46
  70. data/lib/active_record/persistence.rb +3 -3
  71. data/lib/active_record/querying.rb +1 -1
  72. data/lib/active_record/railtie.rb +18 -4
  73. data/lib/active_record/railties/console_sandbox.rb +3 -2
  74. data/lib/active_record/railties/controller_runtime.rb +2 -1
  75. data/lib/active_record/railties/databases.rake +38 -80
  76. data/lib/active_record/reflection.rb +36 -3
  77. data/lib/active_record/relation.rb +18 -8
  78. data/lib/active_record/relation/calculations.rb +10 -5
  79. data/lib/active_record/relation/delegation.rb +3 -5
  80. data/lib/active_record/relation/finder_methods.rb +27 -14
  81. data/lib/active_record/relation/merger.rb +30 -2
  82. data/lib/active_record/relation/predicate_builder.rb +1 -6
  83. data/lib/active_record/relation/query_methods.rb +113 -16
  84. data/lib/active_record/runtime_registry.rb +17 -0
  85. data/lib/active_record/schema_dumper.rb +5 -1
  86. data/lib/active_record/schema_migration.rb +8 -5
  87. data/lib/active_record/scoping.rb +56 -2
  88. data/lib/active_record/scoping/default.rb +12 -11
  89. data/lib/active_record/scoping/named.rb +7 -3
  90. data/lib/active_record/serialization.rb +1 -1
  91. data/lib/active_record/statement_cache.rb +26 -0
  92. data/lib/active_record/tasks/database_tasks.rb +55 -10
  93. data/lib/active_record/tasks/firebird_database_tasks.rb +56 -0
  94. data/lib/active_record/tasks/mysql_database_tasks.rb +7 -2
  95. data/lib/active_record/tasks/oracle_database_tasks.rb +45 -0
  96. data/lib/active_record/tasks/sqlserver_database_tasks.rb +48 -0
  97. data/lib/active_record/timestamp.rb +6 -0
  98. data/lib/active_record/transactions.rb +7 -3
  99. data/lib/active_record/validations.rb +1 -2
  100. data/lib/active_record/validations/uniqueness.rb +7 -3
  101. data/lib/active_record/version.rb +7 -6
  102. data/lib/rails/generators/active_record/migration/migration_generator.rb +9 -2
  103. data/lib/rails/generators/active_record/{model/templates/migration.rb → migration/templates/create_table_migration.rb} +4 -0
  104. data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
  105. data/lib/rails/generators/active_record/model/templates/model.rb +4 -1
  106. metadata +17 -12
  107. data/examples/associations.png +0 -0
@@ -13,18 +13,21 @@ module ActiveRecord
13
13
  "#{Base.table_name_prefix}unique_schema_migrations#{Base.table_name_suffix}"
14
14
  end
15
15
 
16
- def self.create_table
16
+ def self.create_table(limit=nil)
17
17
  unless connection.table_exists?(table_name)
18
- connection.create_table(table_name, :id => false) do |t|
19
- t.column :version, :string, :null => false
18
+ version_options = {null: false}
19
+ version_options[:limit] = limit if limit
20
+
21
+ connection.create_table(table_name, id: false) do |t|
22
+ t.column :version, :string, version_options
20
23
  end
21
- connection.add_index table_name, :version, :unique => true, :name => index_name
24
+ connection.add_index table_name, :version, unique: true, name: index_name
22
25
  end
23
26
  end
24
27
 
25
28
  def self.drop_table
26
29
  if connection.table_exists?(table_name)
27
- connection.remove_index table_name, :name => index_name
30
+ connection.remove_index table_name, name: index_name
28
31
  connection.drop_table(table_name)
29
32
  end
30
33
  end
@@ -1,3 +1,5 @@
1
+ require 'active_support/per_thread_registry'
2
+
1
3
  module ActiveRecord
2
4
  module Scoping
3
5
  extend ActiveSupport::Concern
@@ -9,11 +11,11 @@ module ActiveRecord
9
11
 
10
12
  module ClassMethods
11
13
  def current_scope #:nodoc:
12
- Thread.current["#{self}_current_scope"]
14
+ ScopeRegistry.value_for(:current_scope, base_class.to_s)
13
15
  end
14
16
 
15
17
  def current_scope=(scope) #:nodoc:
16
- Thread.current["#{self}_current_scope"] = scope
18
+ ScopeRegistry.set_value_for(:current_scope, base_class.to_s, scope)
17
19
  end
18
20
  end
19
21
 
@@ -24,5 +26,57 @@ module ActiveRecord
24
26
  send("#{att}=", value) if respond_to?("#{att}=")
25
27
  end
26
28
  end
29
+
30
+ # This class stores the +:current_scope+ and +:ignore_default_scope+ values
31
+ # for different classes. The registry is stored as a thread local, which is
32
+ # accessed through +ScopeRegistry.current+.
33
+ #
34
+ # This class allows you to store and get the scope values on different
35
+ # classes and different types of scopes. For example, if you are attempting
36
+ # to get the current_scope for the +Board+ model, then you would use the
37
+ # following code:
38
+ #
39
+ # registry = ActiveRecord::Scoping::ScopeRegistry
40
+ # registry.set_value_for(:current_scope, "Board", some_new_scope)
41
+ #
42
+ # Now when you run:
43
+ #
44
+ # registry.value_for(:current_scope, "Board")
45
+ #
46
+ # You will obtain whatever was defined in +some_new_scope+. The +value_for+
47
+ # and +set_value_for+ methods are delegated to the current +ScopeRegistry+
48
+ # object, so the above example code can also be called as:
49
+ #
50
+ # ActiveRecord::Scoping::ScopeRegistry.set_value_for(:current_scope,
51
+ # "Board", some_new_scope)
52
+ class ScopeRegistry # :nodoc:
53
+ extend ActiveSupport::PerThreadRegistry
54
+
55
+ VALID_SCOPE_TYPES = [:current_scope, :ignore_default_scope]
56
+
57
+ def initialize
58
+ @registry = Hash.new { |hash, key| hash[key] = {} }
59
+ end
60
+
61
+ # Obtains the value for a given +scope_name+ and +variable_name+.
62
+ def value_for(scope_type, variable_name)
63
+ raise_invalid_scope_type!(scope_type)
64
+ @registry[scope_type][variable_name]
65
+ end
66
+
67
+ # Sets the +value+ for a given +scope_type+ and +variable_name+.
68
+ def set_value_for(scope_type, variable_name, value)
69
+ raise_invalid_scope_type!(scope_type)
70
+ @registry[scope_type][variable_name] = value
71
+ end
72
+
73
+ private
74
+
75
+ def raise_invalid_scope_type!(scope_type)
76
+ if !VALID_SCOPE_TYPES.include?(scope_type)
77
+ raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. Scope types must be included in VALID_SCOPE_TYPES"
78
+ end
79
+ end
80
+ end
27
81
  end
28
82
  end
@@ -5,8 +5,17 @@ module ActiveRecord
5
5
 
6
6
  included do
7
7
  # Stores the default scope for the class.
8
- class_attribute :default_scopes, instance_writer: false
8
+ class_attribute :default_scopes, instance_writer: false, instance_predicate: false
9
+
9
10
  self.default_scopes = []
11
+
12
+ def self.default_scopes?
13
+ ActiveSupport::Deprecation.warn(
14
+ "#default_scopes? is deprecated. Do something like #default_scopes.empty? instead."
15
+ )
16
+
17
+ !!self.default_scopes
18
+ end
10
19
  end
11
20
 
12
21
  module ClassMethods
@@ -27,14 +36,6 @@ module ActiveRecord
27
36
  # Post.unscoped {
28
37
  # Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10"
29
38
  # }
30
- #
31
- # It is recommended that you use the block form of unscoped because
32
- # chaining unscoped with +scope+ does not work. Assuming that
33
- # +published+ is a +scope+, the following two statements
34
- # are equal: the +default_scope+ is applied on both.
35
- #
36
- # Post.unscoped.published
37
- # Post.published
38
39
  def unscoped
39
40
  block_given? ? relation.scoping { yield } : relation
40
41
  end
@@ -119,11 +120,11 @@ module ActiveRecord
119
120
  end
120
121
 
121
122
  def ignore_default_scope? # :nodoc:
122
- Thread.current["#{self}_ignore_default_scope"]
123
+ ScopeRegistry.value_for(:ignore_default_scope, self)
123
124
  end
124
125
 
125
126
  def ignore_default_scope=(ignore) # :nodoc:
126
- Thread.current["#{self}_ignore_default_scope"] = ignore
127
+ ScopeRegistry.set_value_for(:ignore_default_scope, self, ignore)
127
128
  end
128
129
 
129
130
  # The ignore_default_scope flag is used to prevent an infinite recursion
@@ -159,10 +159,14 @@ module ActiveRecord
159
159
  end
160
160
 
161
161
  singleton_class.send(:define_method, name) do |*args|
162
- options = body.respond_to?(:call) ? unscoped { body.call(*args) } : body
163
- relation = all.merge(options)
162
+ if body.respond_to?(:call)
163
+ scope = all.scoping { body.call(*args) }
164
+ scope = scope.extending(extension) if extension
165
+ else
166
+ scope = body
167
+ end
164
168
 
165
- extension ? relation.extending(extension) : relation
169
+ scope || all
166
170
  end
167
171
  end
168
172
  end
@@ -5,7 +5,7 @@ module ActiveRecord #:nodoc:
5
5
  include ActiveModel::Serializers::JSON
6
6
 
7
7
  included do
8
- self.include_root_in_json = true
8
+ self.include_root_in_json = false
9
9
  end
10
10
 
11
11
  def serializable_hash(options = nil)
@@ -0,0 +1,26 @@
1
+ module ActiveRecord
2
+
3
+ # Statement cache is used to cache a single statement in order to avoid creating the AST again.
4
+ # Initializing the cache is done by passing the statement in the initialization block:
5
+ #
6
+ # cache = ActiveRecord::StatementCache.new do
7
+ # Book.where(name: "my book").limit(100)
8
+ # end
9
+ #
10
+ # The cached statement is executed by using the +execute+ method:
11
+ #
12
+ # cache.execute
13
+ #
14
+ # The relation returned by the block is cached, and for each +execute+ call the cached relation gets duped.
15
+ # Database is queried when +to_a+ is called on the relation.
16
+ class StatementCache
17
+ def initialize
18
+ @relation = yield
19
+ raise ArgumentError.new("Statement cannot be nil") if @relation.nil?
20
+ end
21
+
22
+ def execute
23
+ @relation.dup.to_a
24
+ end
25
+ end
26
+ end
@@ -3,10 +3,41 @@ module ActiveRecord
3
3
  class DatabaseAlreadyExists < StandardError; end # :nodoc:
4
4
  class DatabaseNotSupported < StandardError; end # :nodoc:
5
5
 
6
- module DatabaseTasks # :nodoc:
6
+ # <tt>ActiveRecord::Tasks::DatabaseTasks</tt> is a utility class, which encapsulates
7
+ # logic behind common tasks used to manage database and migrations.
8
+ #
9
+ # The tasks defined here are used in rake tasks provided by Active Record.
10
+ #
11
+ # In order to use DatabaseTasks, a few config values need to be set. All the needed
12
+ # config values are set by Rails already, so it's necessary to do it only if you
13
+ # want to change the defaults or when you want to use Active Record outside of Rails
14
+ # (in such case after configuring the database tasks, you can also use the rake tasks
15
+ # defined in Active Record).
16
+ #
17
+ #
18
+ # The possible config values are:
19
+ #
20
+ # * +env+: current environment (like Rails.env).
21
+ # * +database_configuration+: configuration of your databases (as in +config/database.yml+).
22
+ # * +db_dir+: your +db+ directory.
23
+ # * +fixtures_path+: a path to fixtures directory.
24
+ # * +migrations_paths+: a list of paths to directories with migrations.
25
+ # * +seed_loader+: an object which will load seeds, it needs to respond to the +load_seed+ method.
26
+ #
27
+ # Example usage of +DatabaseTasks+ outside Rails could look as such:
28
+ #
29
+ # include ActiveRecord::Tasks
30
+ # DatabaseTasks.database_configuration = YAML.load(File.read('my_database_config.yml'))
31
+ # DatabaseTasks.db_dir = 'db'
32
+ # # other settings...
33
+ #
34
+ # DatabaseTasks.create_current('production')
35
+ module DatabaseTasks
7
36
  extend self
8
37
 
9
38
  attr_writer :current_config
39
+ attr_accessor :database_configuration, :migrations_paths, :seed_loader, :db_dir,
40
+ :fixtures_path, :env
10
41
 
11
42
  LOCAL_HOSTS = ['127.0.0.1', 'localhost']
12
43
 
@@ -15,12 +46,16 @@ module ActiveRecord
15
46
  @tasks[pattern] = task
16
47
  end
17
48
 
18
- register_task(/mysql/, ActiveRecord::Tasks::MySQLDatabaseTasks)
19
- register_task(/postgresql/, ActiveRecord::Tasks::PostgreSQLDatabaseTasks)
20
- register_task(/sqlite/, ActiveRecord::Tasks::SQLiteDatabaseTasks)
49
+ register_task(/mysql/, ActiveRecord::Tasks::MySQLDatabaseTasks)
50
+ register_task(/postgresql/, ActiveRecord::Tasks::PostgreSQLDatabaseTasks)
51
+ register_task(/sqlite/, ActiveRecord::Tasks::SQLiteDatabaseTasks)
52
+
53
+ register_task(/firebird/, ActiveRecord::Tasks::FirebirdDatabaseTasks)
54
+ register_task(/sqlserver/, ActiveRecord::Tasks::SqlserverDatabaseTasks)
55
+ register_task(/(oci|oracle)/, ActiveRecord::Tasks::OracleDatabaseTasks)
21
56
 
22
57
  def current_config(options = {})
23
- options.reverse_merge! :env => Rails.env
58
+ options.reverse_merge! :env => env
24
59
  if options.has_key?(:config)
25
60
  @current_config = options[:config]
26
61
  else
@@ -46,7 +81,7 @@ module ActiveRecord
46
81
  each_local_configuration { |configuration| create configuration }
47
82
  end
48
83
 
49
- def create_current(environment = Rails.env)
84
+ def create_current(environment = env)
50
85
  each_current_configuration(environment) { |configuration|
51
86
  create configuration
52
87
  }
@@ -69,7 +104,7 @@ module ActiveRecord
69
104
  each_local_configuration { |configuration| drop configuration }
70
105
  end
71
106
 
72
- def drop_current(environment = Rails.env)
107
+ def drop_current(environment = env)
73
108
  each_current_configuration(environment) { |configuration|
74
109
  drop configuration
75
110
  }
@@ -79,7 +114,7 @@ module ActiveRecord
79
114
  drop database_url_config
80
115
  end
81
116
 
82
- def charset_current(environment = Rails.env)
117
+ def charset_current(environment = env)
83
118
  charset ActiveRecord::Base.configurations[environment]
84
119
  end
85
120
 
@@ -88,7 +123,7 @@ module ActiveRecord
88
123
  class_for_adapter(configuration['adapter']).new(*arguments).charset
89
124
  end
90
125
 
91
- def collation_current(environment = Rails.env)
126
+ def collation_current(environment = env)
92
127
  collation ActiveRecord::Base.configurations[environment]
93
128
  end
94
129
 
@@ -113,6 +148,16 @@ module ActiveRecord
113
148
  class_for_adapter(configuration['adapter']).new(*arguments).structure_load(filename)
114
149
  end
115
150
 
151
+ def load_seed
152
+ if seed_loader
153
+ seed_loader.load_seed
154
+ else
155
+ raise "You tried to load seed data, but no seed loader is specified. Please specify seed " +
156
+ "loader with ActiveRecord::Tasks::DatabaseTasks.seed_loader = your_seed_loader\n" +
157
+ "Seed loader should respond to load_seed method"
158
+ end
159
+ end
160
+
116
161
  private
117
162
 
118
163
  def database_url_config
@@ -130,7 +175,7 @@ module ActiveRecord
130
175
 
131
176
  def each_current_configuration(environment)
132
177
  environments = [environment]
133
- environments << 'test' if environment.development?
178
+ environments << 'test' if environment == 'development'
134
179
 
135
180
  configurations = ActiveRecord::Base.configurations.values_at(*environments)
136
181
  configurations.compact.each do |configuration|
@@ -0,0 +1,56 @@
1
+ module ActiveRecord
2
+ module Tasks # :nodoc:
3
+ class FirebirdDatabaseTasks # :nodoc:
4
+ delegate :connection, :establish_connection, to: ActiveRecord::Base
5
+
6
+ def initialize(configuration)
7
+ ActiveSupport::Deprecation.warn "This database tasks were deprecated, because this tasks should be served by the 3rd party adapter."
8
+ @configuration = configuration
9
+ end
10
+
11
+ def create
12
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
13
+ end
14
+
15
+ def drop
16
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
17
+ end
18
+
19
+ def purge
20
+ establish_connection(:test)
21
+ connection.recreate_database!
22
+ end
23
+
24
+ def charset
25
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
26
+ end
27
+
28
+ def structure_dump(filename)
29
+ set_firebird_env(configuration)
30
+ db_string = firebird_db_string(configuration)
31
+ Kernel.system "isql -a #{db_string} > #{filename}"
32
+ end
33
+
34
+ def structure_load(filename)
35
+ set_firebird_env(configuration)
36
+ db_string = firebird_db_string(configuration)
37
+ Kernel.system "isql -i #{filename} #{db_string}"
38
+ end
39
+
40
+ private
41
+
42
+ def set_firebird_env(config)
43
+ ENV['ISC_USER'] = config['username'].to_s if config['username']
44
+ ENV['ISC_PASSWORD'] = config['password'].to_s if config['password']
45
+ end
46
+
47
+ def firebird_db_string(config)
48
+ FireRuby::Database.db_string_for(config.symbolize_keys)
49
+ end
50
+
51
+ def configuration
52
+ @configuration
53
+ end
54
+ end
55
+ end
56
+ end
@@ -26,7 +26,9 @@ module ActiveRecord
26
26
  $stdout.print error.error
27
27
  establish_connection root_configuration_without_database
28
28
  connection.create_database configuration['database'], creation_options
29
- connection.execute grant_statement.gsub(/\s+/, ' ').strip
29
+ if configuration['username'] != 'root'
30
+ connection.execute grant_statement.gsub(/\s+/, ' ').strip
31
+ end
30
32
  establish_connection configuration
31
33
  else
32
34
  $stderr.puts "Couldn't create database for #{configuration.inspect}, #{creation_options.inspect}"
@@ -57,7 +59,10 @@ module ActiveRecord
57
59
  args.concat(["--result-file", "#{filename}"])
58
60
  args.concat(["--no-data"])
59
61
  args.concat(["#{configuration['database']}"])
60
- Kernel.system(*args)
62
+ unless Kernel.system(*args)
63
+ $stderr.puts "Could not dump the database structure. "\
64
+ "Make sure `mysqldump` is in your PATH and check the command output for warnings."
65
+ end
61
66
  end
62
67
 
63
68
  def structure_load(filename)
@@ -0,0 +1,45 @@
1
+ module ActiveRecord
2
+ module Tasks # :nodoc:
3
+ class OracleDatabaseTasks # :nodoc:
4
+ delegate :connection, :establish_connection, to: ActiveRecord::Base
5
+
6
+ def initialize(configuration)
7
+ ActiveSupport::Deprecation.warn "This database tasks were deprecated, because this tasks should be served by the 3rd party adapter."
8
+ @configuration = configuration
9
+ end
10
+
11
+ def create
12
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
13
+ end
14
+
15
+ def drop
16
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
17
+ end
18
+
19
+ def purge
20
+ establish_connection(:test)
21
+ connection.structure_drop.split(";\n\n").each { |ddl| connection.execute(ddl) }
22
+ end
23
+
24
+ def charset
25
+ $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
26
+ end
27
+
28
+ def structure_dump(filename)
29
+ establish_connection(configuration)
30
+ File.open(filename, "w:utf-8") { |f| f << connection.structure_dump }
31
+ end
32
+
33
+ def structure_load(filename)
34
+ establish_connection(configuration)
35
+ IO.read(filename).split(";\n\n").each { |ddl| connection.execute(ddl) }
36
+ end
37
+
38
+ private
39
+
40
+ def configuration
41
+ @configuration
42
+ end
43
+ end
44
+ end
45
+ end