ardb 0.27.3 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/Gemfile +4 -5
- data/README.md +252 -3
- data/ardb.gemspec +8 -8
- data/bin/ardb +1 -1
- data/lib/ardb.rb +155 -72
- data/lib/ardb/adapter/base.rb +67 -47
- data/lib/ardb/adapter/mysql.rb +3 -19
- data/lib/ardb/adapter/postgresql.rb +33 -37
- data/lib/ardb/adapter/sqlite.rb +7 -16
- data/lib/ardb/adapter_spy.rb +58 -92
- data/lib/ardb/cli.rb +18 -226
- data/lib/ardb/{clirb.rb → cli/clirb.rb} +16 -18
- data/lib/ardb/cli/commands.rb +365 -0
- data/lib/ardb/db_tests.rb +2 -4
- data/lib/ardb/default_order_by.rb +3 -13
- data/lib/ardb/migration.rb +18 -20
- data/lib/ardb/record_spy.rb +7 -26
- data/lib/ardb/relation_spy.rb +0 -6
- data/lib/ardb/require_autoloaded_active_record_files.rb +103 -58
- data/lib/ardb/test_helpers.rb +2 -5
- data/lib/ardb/use_db_default.rb +4 -15
- data/lib/ardb/version.rb +1 -1
- data/script/determine_autoloaded_active_record_files.rb +11 -8
- data/test/helper.rb +9 -6
- data/test/support/factory.rb +17 -2
- data/test/support/fake_schema.rb +5 -0
- data/test/support/postgresql/migrations/.keep +0 -0
- data/test/support/postgresql/schema.rb +2 -0
- data/test/support/postgresql/setup_test_db.rb +51 -0
- data/test/support/relative_require_test_db_file.rb +2 -0
- data/test/support/require_test_db_file.rb +1 -0
- data/test/system/.keep +0 -0
- data/test/unit/adapter/base_tests.rb +163 -75
- data/test/unit/adapter/mysql_tests.rb +4 -20
- data/test/unit/adapter/postgresql_tests.rb +20 -28
- data/test/unit/adapter/sqlite_tests.rb +9 -12
- data/test/unit/adapter_spy_tests.rb +48 -71
- data/test/unit/ardb_tests.rb +338 -38
- data/test/unit/cli_tests.rb +334 -225
- data/test/unit/db_tests_tests.rb +3 -6
- data/test/unit/default_order_by_tests.rb +4 -8
- data/test/unit/migration_tests.rb +20 -17
- data/test/unit/record_spy_tests.rb +18 -23
- data/test/unit/relation_spy_tests.rb +17 -46
- data/test/unit/test_helpers_tests.rb +5 -20
- data/test/unit/use_db_default_tests.rb +9 -13
- metadata +111 -100
- data/lib/ardb/has_slug.rb +0 -107
- data/lib/ardb/migration_helpers.rb +0 -77
- data/lib/ardb/root_path.rb +0 -15
- data/test/unit/config_tests.rb +0 -58
- data/test/unit/has_slug_tests.rb +0 -341
- data/test/unit/migration_helpers_tests.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 81b830715964b5aace51929da208df3bf357a35c42e5c38aea50b4d98d625d96
|
4
|
+
data.tar.gz: f4014e705ae352722d6a16f08061767d31c5851b7c3e0cdc5c6592abcd74d034
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '08a7091251f11c2969aae47148185eae17efe0996b7dd0d79f63ac9648ba13c7d60694fe6b3f46ef43e77924e928f209d0f13cdbdbbd249578e143fc3f6d18a9'
|
7
|
+
data.tar.gz: 77f04eda98916783b4c1fb076a7bc461fd71f114547d62030f2379be7c5687219e2c5b3e3e925d42ead55d5e8b5e1a6651c0841710665d3313888b3c96935adc
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,265 @@
|
|
1
1
|
# Ardb
|
2
2
|
|
3
|
-
|
3
|
+
Tools for using ActiveRecord with or without Rails.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
|
7
|
+
Given configured database connection parameters, Ardb provides a CLI and assorted tools for working with an ActiveRecord database. Ardb is designed to be used with or without Rails.
|
8
|
+
|
9
|
+
### Configuration
|
10
|
+
|
11
|
+
By default, Ardb looks for database configuration in the `config/db.rb` file. You can override this using the `ENV["ARDB_DB_FILE"]` env var.
|
12
|
+
|
13
|
+
The configuration includes typical database configuration parameters:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# in config/db.rb
|
17
|
+
require "ardb"
|
18
|
+
|
19
|
+
Ardb.configure do |c|
|
20
|
+
c.logger Logger.new($stdout)
|
21
|
+
c.root_path File.expand_path("../..", __FILE__)
|
22
|
+
|
23
|
+
c.db.adapter "postgresql"
|
24
|
+
c.db.encoding "unicode"
|
25
|
+
c.db.min_messages "WARNING"
|
26
|
+
c.db.url "localhost:5432"
|
27
|
+
c.db.username "testuser"
|
28
|
+
c.db.password "secret"
|
29
|
+
c.db.database "testdb"
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
#### Rails configuration
|
34
|
+
|
35
|
+
If using Ardb with Rails, add a `config/db.rb` file to have Ardb use Rails's configuration settings:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# in config/db.rb
|
39
|
+
require_relative "./environment"
|
40
|
+
require "ardb"
|
41
|
+
|
42
|
+
# This Ardb configuration matches Rails's settings.
|
43
|
+
Ardb.configure do |c|
|
44
|
+
rails_db_config = Rails.application.config_for("database")
|
45
|
+
c.root_path = Rails.root
|
46
|
+
c.logger = Rails.logger
|
47
|
+
c.schema_format = Rails.application.config.active_record.schema_format || :ruby
|
48
|
+
c.default_timezone = :utc
|
49
|
+
c.adapter = rails_db_config["adapter"]
|
50
|
+
c.host = rails_db_config["host"]
|
51
|
+
c.port = rails_db_config["port"]
|
52
|
+
c.username = rails_db_config["username"]
|
53
|
+
c.password = rails_db_config["password"]
|
54
|
+
c.database = rails_db_config["database"]
|
55
|
+
c.encoding = rails_db_config["encoding"]
|
56
|
+
c.min_messages = rails_db_config["min_messages"]
|
57
|
+
|
58
|
+
c.migrations_path = "db/migrate"
|
59
|
+
c.schema_path = "db/schema"
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
### CLI
|
64
|
+
|
65
|
+
```
|
66
|
+
$ ardb --help
|
67
|
+
Usage: ardb [COMMAND] [options]
|
68
|
+
|
69
|
+
Options:
|
70
|
+
--version
|
71
|
+
--help
|
72
|
+
|
73
|
+
Commands:
|
74
|
+
connect Connect to the configured DB
|
75
|
+
create Create the configured DB
|
76
|
+
drop Drop the configured DB
|
77
|
+
generate-migration Generate a MIGRATION-NAME migration file
|
78
|
+
migrate Migrate the configured DB
|
79
|
+
migrate-up Migrate the configured DB up
|
80
|
+
migrate-down Migrate the configured DB down
|
81
|
+
migrate-forward Migrate the configured DB forward
|
82
|
+
migrate-backward Migrate the configured DB backward
|
83
|
+
```
|
84
|
+
|
85
|
+
#### `connect` command
|
86
|
+
|
87
|
+
```
|
88
|
+
$ ardb connect --help
|
89
|
+
Usage: ardb connect [options]
|
90
|
+
|
91
|
+
Options:
|
92
|
+
--version
|
93
|
+
--help
|
94
|
+
|
95
|
+
Description:
|
96
|
+
Connect to the configured DB
|
97
|
+
$ ardb connect
|
98
|
+
error: database "some_database" does not exist
|
99
|
+
$ ardb create
|
100
|
+
created postgresql db "some_database"
|
101
|
+
$ ardb connect
|
102
|
+
connected to postgresql db "some_database"
|
103
|
+
```
|
104
|
+
|
105
|
+
Use this command to verify the connection parameter configuration is correct.
|
106
|
+
|
107
|
+
#### `create` command
|
108
|
+
|
109
|
+
```
|
110
|
+
$ ardb create --help
|
111
|
+
Usage: ardb create [options]
|
112
|
+
|
113
|
+
Options:
|
114
|
+
--version
|
115
|
+
--help
|
116
|
+
|
117
|
+
Description:
|
118
|
+
Create the configured DB
|
119
|
+
$ ardb create
|
120
|
+
created postgresql db "some_database"
|
121
|
+
$ ardb create
|
122
|
+
error: database "some_database" already exists
|
123
|
+
```
|
124
|
+
|
125
|
+
#### `drop` command
|
126
|
+
|
127
|
+
```
|
128
|
+
$ ardb drop --help
|
129
|
+
Usage: ardb drop [options]
|
130
|
+
|
131
|
+
Options:
|
132
|
+
--version
|
133
|
+
--help
|
134
|
+
|
135
|
+
Description:
|
136
|
+
Drop the configured DB
|
137
|
+
$ ardb drop
|
138
|
+
dropped postgresql db "some_database"
|
139
|
+
$ ardb drop
|
140
|
+
error: database "some_database" does not exist
|
141
|
+
```
|
142
|
+
|
143
|
+
#### `generate-migration` command
|
144
|
+
|
145
|
+
```
|
146
|
+
$ ardb generate-migration add_projects --help
|
147
|
+
Usage: ardb generate-migration MIGRATION-NAME [options]
|
148
|
+
|
149
|
+
Options:
|
150
|
+
--version
|
151
|
+
--help
|
152
|
+
|
153
|
+
Description:
|
154
|
+
Generate a MIGRATION-NAME migration file
|
155
|
+
$ ardb generate-migration add_projects
|
156
|
+
generated /path/to/app/db/migrate/20191222074043_add_projects.rb
|
157
|
+
```
|
158
|
+
|
159
|
+
#### `migrate` command
|
160
|
+
|
161
|
+
```
|
162
|
+
$ ardb migrate --help
|
163
|
+
Usage: ardb migrate [options]
|
164
|
+
|
165
|
+
Options:
|
166
|
+
--version
|
167
|
+
--help
|
168
|
+
|
169
|
+
Description:
|
170
|
+
Migrate the configured DB
|
171
|
+
$ ardb migrate
|
172
|
+
== 20191222074043 AddProjects: migrating ======================================
|
173
|
+
-- create_table(:projects)
|
174
|
+
-> 0.0276s
|
175
|
+
== 20191222074043 AddProjects: migrated (0.0277s) =============================
|
176
|
+
```
|
177
|
+
|
178
|
+
#### `migrate-up` command
|
179
|
+
|
180
|
+
```
|
181
|
+
$ ardb migrate-up --help
|
182
|
+
Usage: ardb migrate-up [options]
|
183
|
+
|
184
|
+
Options:
|
185
|
+
-t, --target-version VALUE version to migrate to
|
186
|
+
--version
|
187
|
+
--help
|
188
|
+
|
189
|
+
Description:
|
190
|
+
Migrate the configured DB up
|
191
|
+
$ ardb migrate-up
|
192
|
+
== 20191222074043 AddProjects: migrating ======================================
|
193
|
+
-- create_table(:projects)
|
194
|
+
-> 0.0510s
|
195
|
+
== 20191222074043 AddProjects: migrated (0.0511s) =============================
|
196
|
+
```
|
197
|
+
|
198
|
+
#### `migrate-down` command
|
199
|
+
|
200
|
+
```
|
201
|
+
$ ardb migrate-down --help
|
202
|
+
Usage: ardb migrate-down [options]
|
203
|
+
|
204
|
+
Options:
|
205
|
+
-t, --target-version VALUE version to migrate to
|
206
|
+
--version
|
207
|
+
--help
|
208
|
+
|
209
|
+
Description:
|
210
|
+
Migrate the configured DB down
|
211
|
+
$ ardb migrate-down
|
212
|
+
== 20191222074043 AddProjects: reverting ======================================
|
213
|
+
-- drop_table(:projects)
|
214
|
+
-> 0.0092s
|
215
|
+
== 20191222074043 AddProjects: reverted (0.0132s) =============================
|
216
|
+
```
|
217
|
+
|
218
|
+
#### `migrate-forward` command
|
219
|
+
|
220
|
+
```
|
221
|
+
$ ardb migrate-forward --help
|
222
|
+
Usage: ardb migrate-forward [options]
|
223
|
+
|
224
|
+
Options:
|
225
|
+
-s, --steps VALUE number of migrations to migrate
|
226
|
+
--version
|
227
|
+
--help
|
228
|
+
|
229
|
+
Description:
|
230
|
+
Migrate the configured DB forward
|
231
|
+
$ ardb migrate-forward
|
232
|
+
== 20191222074043 AddProjects: migrating ======================================
|
233
|
+
-- create_table(:projects)
|
234
|
+
-> 0.0510s
|
235
|
+
== 20191222074043 AddProjects: migrated (0.0511s) =============================
|
236
|
+
```
|
237
|
+
|
238
|
+
#### `migrate-backward` command
|
239
|
+
|
240
|
+
```
|
241
|
+
$ ardb migrate-backward --help
|
242
|
+
Usage: ardb migrate-backward [options]
|
243
|
+
|
244
|
+
Options:
|
245
|
+
-s, --steps VALUE number of migrations to migrate
|
246
|
+
--version
|
247
|
+
--help
|
248
|
+
|
249
|
+
Description:
|
250
|
+
Migrate the configured DB backward
|
251
|
+
$ ardb migrate-backward
|
252
|
+
== 20191222074043 AddProjects: reverting ======================================
|
253
|
+
-- drop_table(:projects)
|
254
|
+
-> 0.0092s
|
255
|
+
== 20191222074043 AddProjects: reverted (0.0132s) =============================
|
256
|
+
```
|
8
257
|
|
9
258
|
## Installation
|
10
259
|
|
11
260
|
Add this line to your application's Gemfile:
|
12
261
|
|
13
|
-
gem
|
262
|
+
gem "ardb"
|
14
263
|
|
15
264
|
And then execute:
|
16
265
|
|
data/ardb.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require "ardb/version"
|
5
5
|
|
@@ -11,19 +11,19 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.summary = %q{Activerecord database tools.}
|
12
12
|
gem.description = %q{Activerecord database tools.}
|
13
13
|
gem.homepage = "http://github.com/redding/ardb"
|
14
|
-
gem.license =
|
14
|
+
gem.license = "MIT"
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.
|
21
|
+
gem.required_ruby_version = "~> 2.4"
|
22
22
|
|
23
|
-
gem.
|
24
|
-
gem.add_dependency('activesupport', ["~> 3.2"])
|
25
|
-
gem.add_dependency('much-plugin', ["~> 0.1.0"])
|
26
|
-
gem.add_dependency('ns-options', ["~> 1.1.6"])
|
27
|
-
gem.add_dependency('scmd', ["~> 3.0.1"])
|
23
|
+
gem.add_development_dependency("assert", ["~> 2.18.1"])
|
28
24
|
|
25
|
+
gem.add_dependency("activerecord", ["> 5.0", "< 7.0"])
|
26
|
+
gem.add_dependency("activesupport", ["> 5.0", "< 7.0"])
|
27
|
+
gem.add_dependency("much-plugin", ["~> 0.2.1"])
|
28
|
+
gem.add_dependency("scmd", ["~> 3.0.3"])
|
29
29
|
end
|
data/bin/ardb
CHANGED
data/lib/ardb.rb
CHANGED
@@ -1,115 +1,198 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'active_record'
|
4
|
-
require 'ns-options'
|
1
|
+
require "active_record"
|
2
|
+
require "logger"
|
5
3
|
|
6
|
-
require
|
7
|
-
require 'ardb/root_path'
|
4
|
+
require "ardb/version"
|
8
5
|
|
9
|
-
ENV[
|
6
|
+
ENV["ARDB_DB_FILE"] ||= "config/db"
|
10
7
|
|
11
8
|
module Ardb
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def self.configure(&block); Config.define(&block); end
|
9
|
+
def self.config
|
10
|
+
@config ||= Config.new
|
11
|
+
end
|
16
12
|
|
17
|
-
def self.
|
13
|
+
def self.configure(&block)
|
14
|
+
self.config.tap(&block)
|
15
|
+
end
|
18
16
|
|
19
|
-
def self.
|
20
|
-
|
21
|
-
raise NotConfiguredError, "missing required configs"
|
22
|
-
end
|
17
|
+
def self.adapter
|
18
|
+
@adapter || raise(NotInitializedError.new(caller))
|
23
19
|
end
|
24
20
|
|
21
|
+
def self.reset_adapter; @adapter = nil; end
|
22
|
+
|
25
23
|
def self.init(establish_connection = true)
|
26
|
-
require
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
require "ardb/require_autoloaded_active_record_files"
|
25
|
+
begin
|
26
|
+
require_db_file
|
27
|
+
rescue InvalidDBFileError => exception
|
28
|
+
exception.set_backtrace(caller)
|
29
|
+
raise exception
|
30
|
+
end
|
31
|
+
|
32
|
+
self.config.validate!
|
33
|
+
@adapter = Adapter.new(self.config)
|
30
34
|
|
31
35
|
# setup AR
|
36
|
+
ActiveRecord::Base.default_timezone = self.config.default_timezone
|
32
37
|
ActiveRecord::Base.logger = self.config.logger
|
33
|
-
if establish_connection
|
34
|
-
ActiveRecord::Base.establish_connection(self.config.db_settings)
|
35
|
-
end
|
38
|
+
self.adapter.connect_db if establish_connection
|
36
39
|
end
|
37
40
|
|
38
41
|
def self.escape_like_pattern(pattern, escape_char = nil)
|
39
42
|
self.adapter.escape_like_pattern(pattern, escape_char)
|
43
|
+
rescue NotInitializedError => exception
|
44
|
+
exception.set_backtrace(caller)
|
45
|
+
raise exception
|
40
46
|
end
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
option :username, String, :required => false
|
52
|
-
option :password, String, :required => false
|
53
|
-
option :pool, Integer, :required => false
|
54
|
-
option :checkout_timeout, Integer, :required => false
|
48
|
+
private
|
49
|
+
|
50
|
+
# try requiring the db file via the load path or as an absolute path, if
|
51
|
+
# that fails it tries requiring relative to the current working directory
|
52
|
+
def self.require_db_file
|
53
|
+
begin
|
54
|
+
require ENV["ARDB_DB_FILE"]
|
55
|
+
rescue LoadError
|
56
|
+
require File.expand_path(ENV["ARDB_DB_FILE"], ENV["PWD"])
|
55
57
|
end
|
58
|
+
rescue LoadError
|
59
|
+
raise InvalidDBFileError, "can't require `#{ENV["ARDB_DB_FILE"]}`, " \
|
60
|
+
"check that the ARDB_DB_FILE env var is set to " \
|
61
|
+
"the file path of your db file"
|
62
|
+
end
|
56
63
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
class Config
|
65
|
+
ACTIVERECORD_ATTRS = [
|
66
|
+
:adapter,
|
67
|
+
:database,
|
68
|
+
:encoding,
|
69
|
+
:host,
|
70
|
+
:port,
|
71
|
+
:username,
|
72
|
+
:password,
|
73
|
+
:pool,
|
74
|
+
:checkout_timeout,
|
75
|
+
:min_messages
|
76
|
+
].freeze
|
77
|
+
|
78
|
+
DEFAULT_MIGRATIONS_PATH = "db/migrations".freeze
|
79
|
+
DEFAULT_SCHEMA_PATH = "db/schema".freeze
|
80
|
+
RUBY_SCHEMA_FORMAT = :ruby.freeze
|
81
|
+
SQL_SCHEMA_FORMAT = :sql.freeze
|
82
|
+
VALID_SCHEMA_FORMATS = [RUBY_SCHEMA_FORMAT, SQL_SCHEMA_FORMAT].freeze
|
83
|
+
|
84
|
+
attr_accessor(*ACTIVERECORD_ATTRS)
|
85
|
+
attr_accessor :default_timezone, :logger, :root_path
|
86
|
+
attr_reader :schema_format
|
87
|
+
attr_writer :migrations_path, :schema_path
|
88
|
+
|
89
|
+
def initialize
|
90
|
+
@default_timezone = :utc
|
91
|
+
@logger = Logger.new(STDOUT)
|
92
|
+
@root_path = ENV["PWD"]
|
93
|
+
@migrations_path = DEFAULT_MIGRATIONS_PATH
|
94
|
+
@schema_path = DEFAULT_SCHEMA_PATH
|
95
|
+
@schema_format = RUBY_SCHEMA_FORMAT
|
69
96
|
end
|
70
97
|
|
71
|
-
|
98
|
+
def migrations_path
|
99
|
+
File.expand_path(@migrations_path.to_s, @root_path.to_s)
|
100
|
+
end
|
72
101
|
|
73
|
-
|
74
|
-
|
102
|
+
def schema_path
|
103
|
+
File.expand_path(@schema_path.to_s, @root_path.to_s)
|
104
|
+
end
|
75
105
|
|
76
|
-
|
106
|
+
def schema_format=(new_value)
|
107
|
+
@schema_format = begin
|
108
|
+
new_value.to_sym
|
109
|
+
rescue NoMethodError
|
110
|
+
raise ArgumentError, "schema format must be a `Symbol`", caller
|
111
|
+
end
|
112
|
+
end
|
77
113
|
|
78
|
-
def
|
79
|
-
|
114
|
+
def activerecord_connect_hash
|
115
|
+
ACTIVERECORD_ATTRS.inject({}) do |h, attr_name|
|
116
|
+
value = self.send(attr_name)
|
117
|
+
!value.nil? ? h.merge!(attr_name.to_s => value) : h
|
118
|
+
end
|
80
119
|
end
|
81
120
|
|
82
|
-
def
|
83
|
-
|
121
|
+
def validate!
|
122
|
+
if self.adapter.to_s.empty? || self.database.to_s.empty?
|
123
|
+
raise ConfigurationError, "an adapter and database must be provided"
|
124
|
+
end
|
125
|
+
|
126
|
+
if !VALID_SCHEMA_FORMATS.include?(self.schema_format)
|
127
|
+
raise ConfigurationError, "schema format must be one of: " \
|
128
|
+
"#{VALID_SCHEMA_FORMATS.join(", ")}"
|
129
|
+
end
|
130
|
+
|
131
|
+
true
|
84
132
|
end
|
85
133
|
|
86
|
-
def
|
87
|
-
|
88
|
-
|
134
|
+
def ==(other)
|
135
|
+
if other.kind_of?(self.class)
|
136
|
+
self.activerecord_connect_hash == other.activerecord_connect_hash &&
|
137
|
+
self.default_timezone == other.default_timezone &&
|
138
|
+
self.logger == other.logger &&
|
139
|
+
self.root_path == other.root_path &&
|
140
|
+
self.schema_format == other.schema_format &&
|
141
|
+
self.migrations_path == other.migrations_path &&
|
142
|
+
self.schema_path == other.schema_path
|
143
|
+
else
|
144
|
+
super
|
145
|
+
end
|
89
146
|
end
|
90
|
-
|
147
|
+
end
|
91
148
|
|
92
|
-
|
93
|
-
|
94
|
-
|
149
|
+
module Adapter
|
150
|
+
VALID_ADAPTERS = [
|
151
|
+
"sqlite",
|
152
|
+
"sqlite3",
|
153
|
+
"postgresql",
|
154
|
+
"postgres",
|
155
|
+
"mysql",
|
156
|
+
"mysql2"
|
157
|
+
].freeze
|
158
|
+
|
159
|
+
def self.new(config)
|
160
|
+
if !VALID_ADAPTERS.include?(config.adapter)
|
161
|
+
raise InvalidAdapterError, "invalid adapter: `#{config.adapter}`"
|
162
|
+
end
|
163
|
+
self.send(config.adapter, config)
|
95
164
|
end
|
96
165
|
|
97
|
-
def
|
98
|
-
require
|
99
|
-
Adapter::
|
166
|
+
def self.sqlite(config)
|
167
|
+
require "ardb/adapter/sqlite"
|
168
|
+
Adapter::Sqlite.new(config)
|
100
169
|
end
|
101
|
-
alias_method :mysql2, :mysql
|
102
170
|
|
103
|
-
|
171
|
+
def self.sqlite3(config); self.sqlite(config); end
|
104
172
|
|
105
|
-
def self.
|
106
|
-
|
173
|
+
def self.postgresql(config)
|
174
|
+
require "ardb/adapter/postgresql"
|
175
|
+
Adapter::Postgresql.new(config)
|
107
176
|
end
|
108
177
|
|
109
|
-
def self.
|
110
|
-
|
178
|
+
def self.postgres(config); self.postgresql(config); end
|
179
|
+
|
180
|
+
def self.mysql(config)
|
181
|
+
require "ardb/adapter/mysql"
|
182
|
+
Adapter::Mysql.new(config)
|
111
183
|
end
|
112
184
|
|
185
|
+
def self.mysql2(config); self.mysql(config); end
|
113
186
|
end
|
114
187
|
|
188
|
+
InvalidDBFileError = Class.new(ArgumentError)
|
189
|
+
ConfigurationError = Class.new(ArgumentError)
|
190
|
+
InvalidAdapterError = Class.new(RuntimeError)
|
191
|
+
|
192
|
+
class NotInitializedError < RuntimeError
|
193
|
+
def initialize(backtrace)
|
194
|
+
super("ardb hasn't been initialized yet, run `Ardb.init`")
|
195
|
+
set_backtrace(backtrace)
|
196
|
+
end
|
197
|
+
end
|
115
198
|
end
|