bridgetown-activerecord 1.0.0 → 2.0.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/CHANGELOG.md +4 -2
- data/README.md +69 -1
- data/bridgetown-activerecord.gemspec +1 -1
- data/bridgetown.automation.rb +3 -1
- data/lib/bridgetown-activerecord/initializer.rb +27 -0
- data/lib/bridgetown-activerecord/version.rb +1 -1
- data/lib/bridgetown-activerecord.rb +1 -1
- data/lib/tasks/database.rake +11 -8
- metadata +5 -5
- data/lib/bridgetown-activerecord/builder.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccfd8d0b6032758ade7b72ece8ff373552c3257d84a35cab4a34e98c88789fb3
|
4
|
+
data.tar.gz: 244806f70399573021e39162d2aca78e634a8e41279c3e23c85cf42f8d1fa176
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db2527fb6c3ca7da3f67678bbb75d845a01d310ab762ec05661b688650a19b203c400bbfd8de4c1c86f2fdbd143e8383cda37142a751904c27368ea04612a17b
|
7
|
+
data.tar.gz: fea781ad77051b5018687ba9199a40839bbfc00926810170942309cdb0c5ec5e772589214d31b04731778d57aa25e8430e9518b51c2f3766b05de652c7b78af6
|
data/CHANGELOG.md
CHANGED
@@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## Unreleased
|
9
9
|
|
10
|
-
-
|
10
|
+
## [2.0.0] - 2022-10-08
|
11
11
|
|
12
|
-
|
12
|
+
- Upgrade to initializers system in Bridgetown 1.2
|
13
|
+
|
14
|
+
## 1.0.0 - 2022-04-11
|
13
15
|
|
14
16
|
- First version
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Bridgetown ActiveRecord plugin
|
2
2
|
|
3
|
+
**NOTE:** currently waiting on a bugfix in Bridgetown itself before getting the green light…coming very soon!
|
4
|
+
|
3
5
|
## Installation
|
4
6
|
|
5
7
|
It's recommended you run our automation script to set up your project to support ActiveRecord and DB models:
|
@@ -24,7 +26,73 @@ $ bundle add pg
|
|
24
26
|
|
25
27
|
## Usage
|
26
28
|
|
27
|
-
|
29
|
+
Let's create a simple Movie model to load and save our favorite movies. Add the file `models/movie.rb`:
|
30
|
+
|
31
|
+
```rb
|
32
|
+
class Movie < ApplicationRecord
|
33
|
+
validates :title, presence: true, uniqueness: { case_insensitive: true }
|
34
|
+
|
35
|
+
def uppercase_title
|
36
|
+
title.upcase
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
Then add a new migration for the Movie model.
|
42
|
+
|
43
|
+
```sh
|
44
|
+
$ bin/bridgetown db:new_migration name=create_movies
|
45
|
+
```
|
46
|
+
|
47
|
+
That will create a new migration file in `db/migrate`. Edit the file so it looks like this:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
class CreateMovies < ActiveRecord::Migration[7.0]
|
51
|
+
def change
|
52
|
+
create_table :movies do |t|
|
53
|
+
t.string :title, null: false
|
54
|
+
t.string :director
|
55
|
+
t.integer :year
|
56
|
+
|
57
|
+
t.timestamps
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
Awesome, now let's create the database and run the migration!
|
64
|
+
|
65
|
+
```sh
|
66
|
+
$ bin/bridgetown db:create
|
67
|
+
$ bin/bridgetown db:migrate
|
68
|
+
```
|
69
|
+
|
70
|
+
If all goes well, the database should be created, the migration run, a new `db/schema.rb` saved, and schema annotations added to the top of `models/movie.rb`!
|
71
|
+
|
72
|
+
Let's try it out in the Bridgetown console.
|
73
|
+
|
74
|
+
```sh
|
75
|
+
$ bin/bridgetown console
|
76
|
+
```
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
> Movie.count
|
80
|
+
0
|
81
|
+
> Movie.create(title: "Free Guy", director: "Shawn Levy", year: "2021")
|
82
|
+
> Movie.count
|
83
|
+
1
|
84
|
+
> Movie.last
|
85
|
+
#<Movie:0x0000000109e26378> {
|
86
|
+
:id => 1,
|
87
|
+
:title => "Free Guy",
|
88
|
+
:director => "Shawn Levy",
|
89
|
+
:year => 2021,
|
90
|
+
:created_at => 2022-03-12 23:24:28.98137 UTC,
|
91
|
+
:updated_at => 2022-03-12 23:24:28.98137 UTC
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
You're ready to roll to take full advantage of ActiveRecord database models in your Bridgetown site!
|
28
96
|
|
29
97
|
## Testing
|
30
98
|
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
|
18
18
|
spec.required_ruby_version = ">= 2.7.0"
|
19
19
|
|
20
|
-
spec.add_dependency "bridgetown", ">= 1.0", "< 2.0"
|
20
|
+
spec.add_dependency "bridgetown", ">= 1.2.0.beta2", "< 2.0"
|
21
21
|
spec.add_dependency "activerecord", "~> 7.0"
|
22
22
|
spec.add_dependency "standalone_migrations", "~> 7.0"
|
23
23
|
|
data/bridgetown.automation.rb
CHANGED
@@ -62,7 +62,9 @@ append_to_file "bridgetown.config.yml" do
|
|
62
62
|
YML
|
63
63
|
end
|
64
64
|
|
65
|
-
insert_into_file "Rakefile", "
|
65
|
+
insert_into_file "Rakefile", "require \"bridgetown-activerecord\"\nBridgetownActiveRecord.load_tasks\n", :after => "Bridgetown.load_tasks\n"
|
66
|
+
|
67
|
+
# TODO: add to initializer !!!
|
66
68
|
|
67
69
|
say_status :active_record, "The plugin has been configured. For usage help visit:"
|
68
70
|
say_status :active_record, "https://github.com/bridgetownrb/bridgetown-activerecord/blob/main/README.md"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ENV["RAILS_ENV"] = Bridgetown.environment
|
4
|
+
|
5
|
+
require "active_record"
|
6
|
+
require "active_support/configuration_file"
|
7
|
+
|
8
|
+
module BridgetownActiveRecord
|
9
|
+
def self.load_tasks
|
10
|
+
load File.expand_path("../tasks/database.rake", __dir__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.db_configuration(config)
|
14
|
+
ActiveSupport::ConfigurationFile.parse(File.join(config.root_dir, "config", "database.yml"))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.log_writer
|
18
|
+
Bridgetown::LogWriter.new.tap(&:enable_prefix)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Bridgetown.initializer :"bridgetown-activerecord" do |config|
|
23
|
+
ActiveRecord::Base.establish_connection(
|
24
|
+
BridgetownActiveRecord.db_configuration(config)[Bridgetown.environment]
|
25
|
+
)
|
26
|
+
ActiveRecord::Base.logger = BridgetownActiveRecord.log_writer
|
27
|
+
end
|
data/lib/tasks/database.rake
CHANGED
@@ -5,14 +5,17 @@ ENV["SCHEMA"] = File.join(Dir.pwd, "db", "schema.rb")
|
|
5
5
|
require "standalone_migrations"
|
6
6
|
StandaloneMigrations::Tasks.load_tasks
|
7
7
|
|
8
|
-
# Setup Annotate so it runs on db:migrate, etc.
|
9
|
-
require "annotate"
|
10
8
|
require "./models/application_record"
|
11
|
-
|
12
|
-
Annotate
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
|
10
|
+
# Setup Annotate so it runs on db:migrate, etc.
|
11
|
+
if Bridgetown.environment.development?
|
12
|
+
require "annotate"
|
13
|
+
ENV["model_dir"] = "models"
|
14
|
+
Annotate::Helpers.class_eval do
|
15
|
+
# We need to redefine this because our custom model_dir shortcircuits the migration task enhancement
|
16
|
+
def self.include_models?
|
17
|
+
true
|
18
|
+
end
|
16
19
|
end
|
20
|
+
Annotate.load_tasks
|
17
21
|
end
|
18
|
-
Annotate.load_tasks
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridgetown-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bridgetown
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.2.0.beta2
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '2.0'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.2.0.beta2
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2.0'
|
@@ -116,7 +116,7 @@ files:
|
|
116
116
|
- bridgetown-activerecord.gemspec
|
117
117
|
- bridgetown.automation.rb
|
118
118
|
- lib/bridgetown-activerecord.rb
|
119
|
-
- lib/bridgetown-activerecord/
|
119
|
+
- lib/bridgetown-activerecord/initializer.rb
|
120
120
|
- lib/bridgetown-activerecord/version.rb
|
121
121
|
- lib/tasks/database.rake
|
122
122
|
homepage: https://github.com/bridgetownrb/bridgetown-activerecord
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
ENV["RAILS_ENV"] = Bridgetown.environment
|
4
|
-
|
5
|
-
require "active_record"
|
6
|
-
require "active_support/configuration_file"
|
7
|
-
|
8
|
-
module BridgetownActiveRecord
|
9
|
-
def self.load_tasks
|
10
|
-
load File.expand_path("../tasks/database.rake", __dir__)
|
11
|
-
end
|
12
|
-
|
13
|
-
class Builder < Bridgetown::Builder
|
14
|
-
def self.db_configuration(site)
|
15
|
-
ActiveSupport::ConfigurationFile.parse(site.in_root_dir("config", "database.yml"))
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.log_writer
|
19
|
-
Bridgetown::LogWriter.new.tap(&:enable_prefix)
|
20
|
-
end
|
21
|
-
|
22
|
-
Bridgetown::Hooks.register_one :site, :after_init, reloadable: false do |site|
|
23
|
-
ActiveRecord::Base.establish_connection db_configuration(site)[Bridgetown.environment]
|
24
|
-
ActiveRecord::Base.logger = log_writer
|
25
|
-
end
|
26
|
-
|
27
|
-
# no-op
|
28
|
-
def build; end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
BridgetownActiveRecord::Builder.register
|