-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridgetown.automation.rb
72 lines (56 loc) · 1.91 KB
/
bridgetown.automation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
add_gem "bridgetown-activerecord"
add_gem "annotate", group: :development
# TODO:
#dboptions = ["postgresql", "mysql", "vanilla"]
#dbadapter = ask("Which adapter should be used for your database?", limited_to: dboptions)
dbadapter = "postgresql"
dbprefix = ask("What identifier should be used for your database prefix?", default: "bt_demo")
# TODO: use Rails DB templates
#rails_db_tmpl_url = "https://github.com/rails/rails/blob/7-0-stable/railties/lib/rails/generators/rails/app/templates/config/databases/"
create_file "config/database.yml" do
<<~YML
default: &default
adapter: #{dbadapter}
encoding: unicode
pool: 5
development:
<<: *default
database: #{dbprefix}_development
test: &test
<<: *default
database: #{dbprefix}_test
production:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
database: #{dbprefix}_production
YML
end
create_file "models/application_record.rb" do
<<~RUBY
require "active_record"
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
RUBY
end
create_file ".standalone_migrations" do
<<~YML
config:
database: config/database.yml
YML
end
insert_into_file "Rakefile", "require \"bridgetown-activerecord\"\nBridgetownActiveRecord.load_tasks\n", :after => "Bridgetown.load_tasks\n"
ruby_configure "Support for autoloading models" do
<<~RUBY
config.autoload_paths << {
path: "models",
eager: true
}
config.autoloader_collapsed_paths << "models/concerns"
RUBY
end
add_initializer :"bridgetown-activerecord"
say_status :active_record, "The plugin has been configured. For usage help visit:"
say_status :active_record, "https://github.com/bridgetownrb/bridgetown-activerecord/blob/main/README.md"
say_status :active_record, "Don't forget to add a specific database adapter to your Gemfile! For example:"
say_status :active_record, "$ bundle add pg".bold