otr-activerecord 2.1.2 → 2.3.0
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/README.md +73 -35
- 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: ad7ebf92820c6a641db33cff1f766eee0b9ae04f860d4527a09107ab1f2a790c
|
4
|
+
data.tar.gz: 78ad3a77acdf73ec05b27ba3eb061ed0a76dd7f35c1fa8ff21b9c77a9feb69e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4261a73f71bdb6ee9e05ec6475341ce49053946f1db48d9584f6e50af97ad7c8f9d171eadcf03e60cd52d3166fadcaf294cff6d3b98afe7f952e258af47cee3
|
7
|
+
data.tar.gz: cd098419d947738bb08cd1f913c355d7e6653ebb98ef799855092b049d37ea1b55ff73845bd22210463eb104adea2ffdd78c17345969f921af96bb42c0c5c498
|
data/README.md
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
# otr-activerecord
|
2
2
|
|
3
|
-
An easy way to use ActiveRecord "off the rails." Works with Grape, Sinatra, plain old Rack, or even in a boring little script
|
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.1
|
5
6
|
* ActiveRecord 7.0 (new AR features, like encryption, not tested)
|
6
|
-
* ActiveRecord 6.
|
7
|
-
* ActiveRecord
|
8
|
-
* ActiveRecord 4.2
|
7
|
+
* ActiveRecord 6.1
|
8
|
+
* See older versions of this library for older versions of ActiveRecord
|
9
9
|
|
10
10
|
## How to use
|
11
11
|
|
12
12
|
#### 1. Add it to your Gemfile
|
13
13
|
|
14
|
-
|
14
|
+
```ruby
|
15
|
+
gem "otr-activerecord"
|
16
|
+
```
|
15
17
|
|
16
18
|
#### 2. Configure your database connection
|
17
19
|
|
18
|
-
After loading your gems, tell `OTR::ActiveRecord` about your database config using one of the following examples:
|
20
|
+
After loading your gems, tell `OTR::ActiveRecord` about your database config using *one* of the following examples:
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
```ruby
|
23
|
+
OTR::ActiveRecord.configure_from_file! "config/database.yml"
|
24
|
+
OTR::ActiveRecord.configure_from_url! ENV['DATABASE_URL'] # e.g. postgres://user:pass@host/db
|
25
|
+
OTR::ActiveRecord.configure_from_hash!(adapter: "postgresql", host: "localhost", database: "db", username: "user", password: "pass", encoding: "utf8", pool: 10, timeout: 5000)
|
26
|
+
```
|
23
27
|
|
24
28
|
**Important note**: `configure_from_file!` won't work as expected if you have already `DATABASE_URL` set as part of your environment variables.
|
25
29
|
This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration.
|
@@ -28,57 +32,91 @@ This is because in ActiveRecord when that env variable is set it will merge its
|
|
28
32
|
|
29
33
|
If you have a single database (most apps), use this helper:
|
30
34
|
|
31
|
-
|
35
|
+
```ruby
|
36
|
+
OTR::ActiveRecord.establish_connection!
|
37
|
+
```
|
32
38
|
|
33
39
|
If you're using multiple databases, call your base class(es) instead:
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
41
|
+
```ruby
|
42
|
+
MyBase.establish_connection :primary
|
43
|
+
MyBase.establish_connection :primary_replica
|
44
|
+
...
|
45
|
+
```
|
38
46
|
|
39
47
|
#### 4. Enable middleware for Rack apps
|
40
48
|
|
41
49
|
Add these middlewares in `config.ru`:
|
42
50
|
|
43
|
-
|
44
|
-
|
51
|
+
```ruby
|
52
|
+
# Clean up database connections after every request (required)
|
53
|
+
use OTR::ActiveRecord::ConnectionManagement
|
45
54
|
|
46
|
-
|
47
|
-
|
55
|
+
# Enable ActiveRecord's QueryCache for every request (optional)
|
56
|
+
use OTR::ActiveRecord::QueryCache
|
57
|
+
```
|
48
58
|
|
49
59
|
#### 5. Import ActiveRecord tasks into your Rakefile
|
50
60
|
|
51
61
|
This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.
|
52
62
|
|
53
|
-
|
54
|
-
|
63
|
+
```ruby
|
64
|
+
require "bundler/setup"
|
65
|
+
load "tasks/otr-activerecord.rake"
|
55
66
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
namespace :db do
|
68
|
+
# Some db tasks require your app code to be loaded; they'll expect to find it here
|
69
|
+
task :environment do
|
70
|
+
require_relative "app"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
62
74
|
|
63
75
|
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
76
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
Look under [/examples](https://github.com/jhollinger/otr-activerecord/tree/master/examples) for some example apps.
|
77
|
+
```bash
|
78
|
+
bundle exec rake db:create_migration[create_widgets]
|
79
|
+
```
|
70
80
|
|
71
81
|
## Advanced options
|
72
82
|
|
73
83
|
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
84
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
85
|
+
```ruby
|
86
|
+
OTR::ActiveRecord.db_dir = 'db'
|
87
|
+
OTR::ActiveRecord.migrations_paths = ['db/migrate']
|
88
|
+
OTR::ActiveRecord.fixtures_path = 'test/fixtures'
|
89
|
+
OTR::ActiveRecord.seed_file = 'seeds.rb'
|
90
|
+
```
|
91
|
+
|
92
|
+
## Testing
|
93
|
+
|
94
|
+
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).
|
95
|
+
|
96
|
+
```bash
|
97
|
+
# Run all tests
|
98
|
+
bin/testall
|
99
|
+
|
100
|
+
# Filter tests
|
101
|
+
bin/testall ruby-3.3
|
102
|
+
bin/testall ar-7.1
|
103
|
+
bin/testall ruby-3.3 ar-7.1
|
104
|
+
|
105
|
+
# Run one specific line from test/matrix
|
106
|
+
bin/test ruby-3.3 ar-7.1 sqlite3
|
107
|
+
|
108
|
+
# Run a specific file
|
109
|
+
bin/test ruby-3.3 ar-7.1 sqlite3 test/configure_test.rb
|
110
|
+
|
111
|
+
# Run a specific test
|
112
|
+
bin/test ruby-3.3 ar-7.1 sqlite3 N=test_configure_from_file
|
113
|
+
|
114
|
+
# Use podman
|
115
|
+
PODMAN=1 bin/testall
|
116
|
+
```
|
79
117
|
|
80
118
|
## License
|
81
119
|
|
82
120
|
Licensed under the MIT License
|
83
121
|
|
84
|
-
Copyright
|
122
|
+
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.3.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-07-25 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.2'
|
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.2'
|
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.4.
|
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
|