otr-activerecord 2.2.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +73 -34
- data/lib/otr-activerecord/activerecord.rb +29 -36
- data/lib/otr-activerecord/middleware/connection_management.rb +4 -4
- data/lib/otr-activerecord/middleware/query_cache.rb +6 -19
- data/lib/otr-activerecord/{compatibility_6.rb → shim/v6.rb} +2 -6
- data/lib/otr-activerecord/{compatibility_5.rb → shim/v7.rb} +4 -8
- data/lib/otr-activerecord/version.rb +1 -1
- data/lib/otr-activerecord.rb +9 -3
- data/lib/tasks/otr-activerecord.rake +4 -4
- metadata +10 -13
- data/lib/otr-activerecord/compatibility_4.rb +0 -34
- data/lib/otr-activerecord/compatibility_7.rb +0 -11
- data/lib/otr-activerecord/defaults.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0bc6ffa0d49d91364fb651969e0806f1fdedb42d2c4d00cc47e47af4e41bb33
|
4
|
+
data.tar.gz: 9ecc2f541f28771bee096d3ebde083cdbb7274132e2ccb764d13df32da570f83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36c0b8a6088067f5f816779277d857af8fce627da9c0141339c38589dde36ccaf75e2271fd227726cb493bd4a42dcf9b7120d92377c395570bfa0e05589c4d58
|
7
|
+
data.tar.gz: 4e1723531212fd09ab669a29a69cdaa6d3041574db13837d6962743ccb30d66cd14786f22635df9d1db8721da55056270983c652896232c6394a72486ec57ad9
|
data/README.md
CHANGED
@@ -2,24 +2,29 @@
|
|
2
2
|
|
3
3
|
An easy way to use ActiveRecord "off the rails." Works with Grape, Sinatra, plain old Rack, or even in a boring little script! The defaults are all very Railsy (`config/database.yml`, `db/seeds.rb`, `db/migrate`, etc.), but you can easily change them. (Formerly known as `grape-activerecord`.) Supports:
|
4
4
|
|
5
|
+
* ActiveRecord 7.2
|
6
|
+
* ActiveRecord 7.1
|
5
7
|
* ActiveRecord 7.0 (new AR features, like encryption, not tested)
|
6
|
-
* ActiveRecord 6.
|
7
|
-
* ActiveRecord
|
8
|
-
* ActiveRecord 4.2
|
8
|
+
* ActiveRecord 6.1
|
9
|
+
* See older versions of this library for older versions of ActiveRecord
|
9
10
|
|
10
11
|
## How to use
|
11
12
|
|
12
13
|
#### 1. Add it to your Gemfile
|
13
14
|
|
14
|
-
|
15
|
+
```ruby
|
16
|
+
gem "otr-activerecord"
|
17
|
+
```
|
15
18
|
|
16
19
|
#### 2. Configure your database connection
|
17
20
|
|
18
|
-
After loading your gems, tell `OTR::ActiveRecord` about your database config using one of the following examples:
|
21
|
+
After loading your gems, tell `OTR::ActiveRecord` about your database config using *one* of the following examples:
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
```ruby
|
24
|
+
OTR::ActiveRecord.configure_from_file! "config/database.yml"
|
25
|
+
OTR::ActiveRecord.configure_from_url! ENV['DATABASE_URL'] # e.g. postgres://user:pass@host/db
|
26
|
+
OTR::ActiveRecord.configure_from_hash!(adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "pass", encoding: "utf8", pool: 10, timeout: 5000)
|
27
|
+
```
|
23
28
|
|
24
29
|
**Important note**: `configure_from_file!` won't work as expected if you have already `DATABASE_URL` set as part of your environment variables.
|
25
30
|
This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration.
|
@@ -28,57 +33,91 @@ This is because in ActiveRecord when that env variable is set it will merge its
|
|
28
33
|
|
29
34
|
If you have a single database (most apps), use this helper:
|
30
35
|
|
31
|
-
|
36
|
+
```ruby
|
37
|
+
OTR::ActiveRecord.establish_connection!
|
38
|
+
```
|
32
39
|
|
33
40
|
If you're using multiple databases, call your base class(es) instead:
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
42
|
+
```ruby
|
43
|
+
MyBase.establish_connection :primary
|
44
|
+
MyBase.establish_connection :primary_replica
|
45
|
+
...
|
46
|
+
```
|
38
47
|
|
39
48
|
#### 4. Enable middleware for Rack apps
|
40
49
|
|
41
50
|
Add these middlewares in `config.ru`:
|
42
51
|
|
43
|
-
|
44
|
-
|
52
|
+
```ruby
|
53
|
+
# Clean up database connections after every request (required)
|
54
|
+
use OTR::ActiveRecord::ConnectionManagement
|
45
55
|
|
46
|
-
|
47
|
-
|
56
|
+
# Enable ActiveRecord's QueryCache for every request (optional)
|
57
|
+
use OTR::ActiveRecord::QueryCache
|
58
|
+
```
|
48
59
|
|
49
60
|
#### 5. Import ActiveRecord tasks into your Rakefile
|
50
61
|
|
51
62
|
This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.
|
52
63
|
|
53
|
-
|
54
|
-
|
64
|
+
```ruby
|
65
|
+
require "bundler/setup"
|
66
|
+
load "tasks/otr-activerecord.rake"
|
55
67
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
68
|
+
namespace :db do
|
69
|
+
# Some db tasks require your app code to be loaded; they'll expect to find it here
|
70
|
+
task :environment do
|
71
|
+
require_relative "app"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
62
75
|
|
63
76
|
Unlike in Rails, creating a new migration is also a rake task. Run `bundle exec rake -T` to get a full list of tasks.
|
64
77
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
Look under [/examples](https://github.com/jhollinger/otr-activerecord/tree/master/examples) for some example apps.
|
78
|
+
```bash
|
79
|
+
bundle exec rake db:create_migration[create_widgets]
|
80
|
+
```
|
70
81
|
|
71
82
|
## Advanced options
|
72
83
|
|
73
84
|
The defaults for db-related files like migrations, seeds, and fixtures are the same as Rails. If you want to override them, use the following options in your `Rakefile`:
|
74
85
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
86
|
+
```ruby
|
87
|
+
OTR::ActiveRecord.db_dir = 'db'
|
88
|
+
OTR::ActiveRecord.migrations_paths = ['db/migrate']
|
89
|
+
OTR::ActiveRecord.fixtures_path = 'test/fixtures'
|
90
|
+
OTR::ActiveRecord.seed_file = 'seeds.rb'
|
91
|
+
```
|
92
|
+
|
93
|
+
## Testing
|
94
|
+
|
95
|
+
Testing is fully scripted under the `bin/` directory. Appraisal is used to test against various ActiveRecord versions, and Docker or Podman is used to test against various Ruby versions. The combinations to test are defined in [test/matrix](https://github.com/jhollinger/otr-activerecord/blob/main/test/matrix).
|
96
|
+
|
97
|
+
```bash
|
98
|
+
# Run all tests
|
99
|
+
bin/testall
|
100
|
+
|
101
|
+
# Filter tests
|
102
|
+
bin/testall ruby-3.3
|
103
|
+
bin/testall ar-7.1
|
104
|
+
bin/testall ruby-3.3 ar-7.1
|
105
|
+
|
106
|
+
# Run one specific line from test/matrix
|
107
|
+
bin/test ruby-3.3 ar-7.1 sqlite3
|
108
|
+
|
109
|
+
# Run a specific file
|
110
|
+
bin/test ruby-3.3 ar-7.1 sqlite3 test/configure_test.rb
|
111
|
+
|
112
|
+
# Run a specific test
|
113
|
+
bin/test ruby-3.3 ar-7.1 sqlite3 N=test_configure_from_file
|
114
|
+
|
115
|
+
# Use podman
|
116
|
+
PODMAN=1 bin/testall
|
117
|
+
```
|
79
118
|
|
80
119
|
## License
|
81
120
|
|
82
121
|
Licensed under the MIT License
|
83
122
|
|
84
|
-
Copyright
|
123
|
+
Copyright 2024 Jordan Hollinger
|
@@ -1,13 +1,19 @@
|
|
1
1
|
require 'erb'
|
2
|
+
require 'uri'
|
3
|
+
require 'yaml'
|
2
4
|
|
3
5
|
# "Off the Rails" ActiveRecord configuration/integration for Grape, Sinatra, Rack, and any other kind of app
|
4
6
|
module OTR
|
5
7
|
# ActiveRecord configuration module
|
6
8
|
module ActiveRecord
|
7
|
-
autoload :
|
8
|
-
autoload :
|
9
|
-
autoload :
|
10
|
-
|
9
|
+
autoload :ConnectionManagement, 'otr-activerecord/middleware/connection_management'
|
10
|
+
autoload :QueryCache, 'otr-activerecord/middleware/query_cache'
|
11
|
+
autoload :Shim,
|
12
|
+
case ::ActiveRecord::VERSION::MAJOR
|
13
|
+
when 6 then 'otr-activerecord/shim/v6'
|
14
|
+
when 7 then 'otr-activerecord/shim/v7'
|
15
|
+
else raise "Unsupported ActiveRecord version"
|
16
|
+
end
|
11
17
|
|
12
18
|
class << self
|
13
19
|
# Relative path to the "db" dir
|
@@ -19,19 +25,17 @@ module OTR
|
|
19
25
|
# Name of the seeds file in db_dir
|
20
26
|
attr_accessor :seed_file
|
21
27
|
# Internal compatibility layer across different major versions of AR
|
22
|
-
attr_accessor :
|
28
|
+
attr_accessor :shim
|
23
29
|
end
|
24
30
|
|
25
31
|
# Connect to database with a Hash. Example:
|
26
32
|
# {adapter: 'postgresql', host: 'localhost', database: 'db', username: 'user', password: 'pass', encoding: 'utf8', pool: 10, timeout: 5000}
|
27
33
|
def self.configure_from_hash!(spec)
|
28
|
-
|
29
|
-
::ActiveRecord::Base.configurations = {rack_env.to_s => config}
|
34
|
+
::ActiveRecord::Base.configurations = transform_config({rack_env.to_s => spec})
|
30
35
|
end
|
31
36
|
|
32
37
|
# Connect to database with a DB URL. Example: "postgres://user:pass@localhost/db"
|
33
38
|
def self.configure_from_url!(url)
|
34
|
-
require 'uri'
|
35
39
|
uri = URI(url)
|
36
40
|
spec = {"adapter" => uri.scheme}
|
37
41
|
|
@@ -57,17 +61,9 @@ module OTR
|
|
57
61
|
|
58
62
|
# Connect to database with a yml file. Example: "config/database.yml"
|
59
63
|
def self.configure_from_file!(path)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
result.each do |_env, config|
|
64
|
-
if config.all? { |_, v| v.is_a?(Hash) }
|
65
|
-
config.each { |_, v| append_migration_path(v) }
|
66
|
-
else
|
67
|
-
append_migration_path(config)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
64
|
+
yaml = ERB.new(File.read(path)).result
|
65
|
+
spec = YAML.safe_load(yaml, aliases: true) || {}
|
66
|
+
::ActiveRecord::Base.configurations = transform_config spec
|
71
67
|
end
|
72
68
|
|
73
69
|
# Establish a connection to the given db (defaults to current rack env)
|
@@ -75,29 +71,26 @@ module OTR
|
|
75
71
|
::ActiveRecord::Base.establish_connection(db)
|
76
72
|
end
|
77
73
|
|
78
|
-
def self.append_migration_path(config)
|
79
|
-
config['migrations_paths'] = ::OTR::ActiveRecord.migrations_paths unless config.key?('migrations_paths')
|
80
|
-
config
|
81
|
-
end
|
82
|
-
|
83
74
|
# The current Rack environment
|
84
75
|
def self.rack_env
|
85
76
|
(ENV['RACK_ENV'] || ENV['RAILS_ENV'] || ENV['APP_ENV'] || ENV['OTR_ENV'] || 'development').to_sym
|
86
77
|
end
|
87
78
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
79
|
+
def self.transform_config(spec)
|
80
|
+
fixup = ->(config) {
|
81
|
+
config = config.stringify_keys
|
82
|
+
config["migrations_paths"] ||= migrations_paths
|
83
|
+
config
|
84
|
+
}
|
85
|
+
spec.stringify_keys.transform_values { |config|
|
86
|
+
if config.all? { |_, v| v.is_a? Hash }
|
87
|
+
config.transform_values { |v| fixup.(v) }
|
88
|
+
else
|
89
|
+
fixup.(config)
|
90
|
+
end
|
91
|
+
}
|
99
92
|
end
|
100
93
|
|
101
|
-
private_class_method :
|
94
|
+
private_class_method :transform_config
|
102
95
|
end
|
103
96
|
end
|
@@ -13,13 +13,13 @@ module OTR
|
|
13
13
|
|
14
14
|
resp = @app.call env
|
15
15
|
resp[2] = ::Rack::BodyProxy.new resp[2] do
|
16
|
-
::ActiveRecord::Base.clear_active_connections! unless testing
|
16
|
+
::ActiveRecord::Base.connection_handler.clear_active_connections! unless testing
|
17
17
|
end
|
18
18
|
resp
|
19
19
|
|
20
|
-
rescue
|
21
|
-
::ActiveRecord::Base.clear_active_connections! unless testing
|
22
|
-
raise
|
20
|
+
rescue => e
|
21
|
+
::ActiveRecord::Base.connection_handler.clear_active_connections! unless testing
|
22
|
+
raise e
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -5,28 +5,15 @@ module OTR
|
|
5
5
|
#
|
6
6
|
class QueryCache
|
7
7
|
def initialize(app)
|
8
|
-
@
|
9
|
-
when 4 then ::ActiveRecord::QueryCache.new(app)
|
10
|
-
when 5, 6, 7 then ActionDispatchHandler.new(app)
|
11
|
-
end
|
8
|
+
@app = app
|
12
9
|
end
|
13
10
|
|
14
11
|
def call(env)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@app = app
|
21
|
-
end
|
22
|
-
|
23
|
-
def call(env)
|
24
|
-
state = nil
|
25
|
-
state = ::ActiveRecord::QueryCache.run
|
26
|
-
@app.call(env)
|
27
|
-
ensure
|
28
|
-
::ActiveRecord::QueryCache.complete(state) if state
|
29
|
-
end
|
12
|
+
state = nil
|
13
|
+
state = ::ActiveRecord::QueryCache.run
|
14
|
+
@app.call(env)
|
15
|
+
ensure
|
16
|
+
::ActiveRecord::QueryCache.complete(state) if state
|
30
17
|
end
|
31
18
|
end
|
32
19
|
end
|
@@ -1,12 +1,8 @@
|
|
1
1
|
module OTR
|
2
2
|
module ActiveRecord
|
3
3
|
# Compatibility layer for ActiveRecord 6
|
4
|
-
class
|
5
|
-
attr_reader :major_version
|
6
|
-
|
7
|
-
# Compatibility layer for ActiveRecord 6
|
4
|
+
class Shim
|
8
5
|
def initialize
|
9
|
-
@major_version = 6
|
10
6
|
::ActiveRecord::Base.default_timezone = :utc
|
11
7
|
end
|
12
8
|
|
@@ -22,7 +18,7 @@ module OTR
|
|
22
18
|
|
23
19
|
# Basename of migration classes
|
24
20
|
def migration_base_class_name
|
25
|
-
version = "
|
21
|
+
version = "6.#{::ActiveRecord::VERSION::MINOR}"
|
26
22
|
"ActiveRecord::Migration[#{version}]"
|
27
23
|
end
|
28
24
|
|
@@ -1,13 +1,9 @@
|
|
1
1
|
module OTR
|
2
2
|
module ActiveRecord
|
3
|
-
# Compatibility layer for ActiveRecord
|
4
|
-
class
|
5
|
-
attr_reader :major_version
|
6
|
-
|
7
|
-
# Compatibility layer for ActiveRecord 5
|
3
|
+
# Compatibility layer for ActiveRecord 7
|
4
|
+
class Shim
|
8
5
|
def initialize
|
9
|
-
|
10
|
-
::ActiveRecord::Base.default_timezone = :utc
|
6
|
+
::ActiveRecord.default_timezone = :utc
|
11
7
|
end
|
12
8
|
|
13
9
|
# All db migration dir paths
|
@@ -22,7 +18,7 @@ module OTR
|
|
22
18
|
|
23
19
|
# Basename of migration classes
|
24
20
|
def migration_base_class_name
|
25
|
-
version = "
|
21
|
+
version = "7.#{::ActiveRecord::VERSION::MINOR}"
|
26
22
|
"ActiveRecord::Migration[#{version}]"
|
27
23
|
end
|
28
24
|
|
data/lib/otr-activerecord.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'hashie-forbidden_attributes'
|
3
|
+
|
3
4
|
require 'otr-activerecord/version'
|
4
5
|
require 'otr-activerecord/activerecord'
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
ENV["DISABLE_DATABASE_ENVIRONMENT_CHECK"] ||= "true"
|
8
|
+
|
9
|
+
OTR::ActiveRecord.db_dir = 'db'
|
10
|
+
OTR::ActiveRecord.migrations_paths = %w(db/migrate)
|
11
|
+
OTR::ActiveRecord.fixtures_path = 'test/fixtures'
|
12
|
+
OTR::ActiveRecord.seed_file = 'seeds.rb'
|
13
|
+
OTR::ActiveRecord.shim = OTR::ActiveRecord::Shim.new
|
@@ -53,13 +53,13 @@ namespace :db do
|
|
53
53
|
task :environment do
|
54
54
|
ENV['RACK_ENV'] = 'test'
|
55
55
|
end
|
56
|
-
end if OTR::ActiveRecord.
|
56
|
+
end if OTR::ActiveRecord.shim.force_db_test_env?
|
57
57
|
|
58
58
|
desc "Create a migration"
|
59
59
|
task :create_migration, [:name] do |_, args|
|
60
60
|
name, version = args[:name], Time.now.utc.strftime("%Y%m%d%H%M%S")
|
61
61
|
|
62
|
-
OTR::ActiveRecord.
|
62
|
+
OTR::ActiveRecord.shim.migrations_paths.each do |directory|
|
63
63
|
next unless File.exist?(directory)
|
64
64
|
|
65
65
|
migration_files = Pathname(directory).children
|
@@ -69,12 +69,12 @@ namespace :db do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
filename = "#{version}_#{name}.rb"
|
72
|
-
dirname = OTR::ActiveRecord.
|
72
|
+
dirname = OTR::ActiveRecord.shim.migrations_path
|
73
73
|
path = File.join(dirname, filename)
|
74
74
|
|
75
75
|
FileUtils.mkdir_p(dirname)
|
76
76
|
File.write path, <<-MIGRATION.strip_heredoc
|
77
|
-
class #{name.camelize} < #{OTR::ActiveRecord.
|
77
|
+
class #{name.camelize} < #{OTR::ActiveRecord.shim.migration_base_class_name}
|
78
78
|
def change
|
79
79
|
end
|
80
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: otr-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '7.
|
22
|
+
version: '7.3'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '7.
|
32
|
+
version: '7.3'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: hashie-forbidden_attributes
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,13 +55,10 @@ files:
|
|
55
55
|
- README.md
|
56
56
|
- lib/otr-activerecord.rb
|
57
57
|
- lib/otr-activerecord/activerecord.rb
|
58
|
-
- lib/otr-activerecord/compatibility_4.rb
|
59
|
-
- lib/otr-activerecord/compatibility_5.rb
|
60
|
-
- lib/otr-activerecord/compatibility_6.rb
|
61
|
-
- lib/otr-activerecord/compatibility_7.rb
|
62
|
-
- lib/otr-activerecord/defaults.rb
|
63
58
|
- lib/otr-activerecord/middleware/connection_management.rb
|
64
59
|
- lib/otr-activerecord/middleware/query_cache.rb
|
60
|
+
- lib/otr-activerecord/shim/v6.rb
|
61
|
+
- lib/otr-activerecord/shim/v7.rb
|
65
62
|
- lib/otr-activerecord/version.rb
|
66
63
|
- lib/tasks/otr-activerecord.rake
|
67
64
|
homepage: https://github.com/jhollinger/otr-activerecord
|
@@ -76,14 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
73
|
requirements:
|
77
74
|
- - ">="
|
78
75
|
- !ruby/object:Gem::Version
|
79
|
-
version:
|
76
|
+
version: 3.0.0
|
80
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
78
|
requirements:
|
82
79
|
- - ">="
|
83
80
|
- !ruby/object:Gem::Version
|
84
81
|
version: '0'
|
85
82
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
83
|
+
rubygems_version: 3.4.19
|
87
84
|
signing_key:
|
88
85
|
specification_version: 4
|
89
86
|
summary: 'Off The Rails: Use ActiveRecord with Grape, Sinatra, Rack, or anything else!'
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module OTR
|
2
|
-
module ActiveRecord
|
3
|
-
# Compatibility layer for ActiveRecord 4
|
4
|
-
class Compatibility4
|
5
|
-
attr_reader :major_version
|
6
|
-
|
7
|
-
# Compatibility layer for ActiveRecord 4
|
8
|
-
def initialize
|
9
|
-
@major_version = 4
|
10
|
-
::ActiveRecord::Base.default_timezone = :utc
|
11
|
-
end
|
12
|
-
|
13
|
-
# All db migration dir paths
|
14
|
-
def migrations_paths
|
15
|
-
OTR::ActiveRecord.migrations_paths
|
16
|
-
end
|
17
|
-
|
18
|
-
# The dir in which to put new migrations
|
19
|
-
def migrations_path
|
20
|
-
OTR::ActiveRecord.migrations_paths[0]
|
21
|
-
end
|
22
|
-
|
23
|
-
# Basename of migration classes
|
24
|
-
def migration_base_class_name
|
25
|
-
'ActiveRecord::Migration'
|
26
|
-
end
|
27
|
-
|
28
|
-
# Force RACK_ENV/RAILS_ENV to be 'test' when running any db:test:* tasks
|
29
|
-
def force_db_test_env?
|
30
|
-
true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
ENV["DISABLE_DATABASE_ENVIRONMENT_CHECK"] ||= "true"
|
2
|
-
|
3
|
-
OTR::ActiveRecord.db_dir = 'db'
|
4
|
-
OTR::ActiveRecord.migrations_paths = %w(db/migrate)
|
5
|
-
OTR::ActiveRecord.fixtures_path = 'test/fixtures'
|
6
|
-
OTR::ActiveRecord.seed_file = 'seeds.rb'
|
7
|
-
OTR::ActiveRecord._normalizer =
|
8
|
-
case ::ActiveRecord::VERSION::MAJOR
|
9
|
-
when 4 then OTR::ActiveRecord::Compatibility4.new
|
10
|
-
when 5 then OTR::ActiveRecord::Compatibility5.new
|
11
|
-
when 6 then OTR::ActiveRecord::Compatibility6.new
|
12
|
-
when 7 then OTR::ActiveRecord::Compatibility7.new
|
13
|
-
end
|