Module: BridgetownPluginNano::Commands::Nano::DatabaseHelpers

Included in:
BridgetownPluginNano::Commands::Nano
Defined in:
lib/bridgetown-plugin-nano/command_helpers/database_helpers.rb

Instance Method Summary collapse

Instance Method Details

#finish_database_setupObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bridgetown-plugin-nano/command_helpers/database_helpers.rb', line 22

def finish_database_setup
  self.destination_root = File.expand_path(folder_name)

  append_to_file(
    "config/base_classes.rb",
    "\n" + File.read("#{self.class.source_root}/base_classes/application_record.rb")
  )
  inject_into_file "config/application.rb",
                   "require \"active_record/railtie\"\n",
                   after: "require \"action_controller/railtie\"\n"

  say_status :nano, "Database configuration complete!"
  say_status :nano, "You will need a RAILS_ENV environment variable set,"
  say_status :nano, "then run `bundle install`."
  say_status :nano, "Afterwards, you can now run commands like" \
                    " `bridgetown nano exec db:setup` to create your database."
end

#setup_postgresqlObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bridgetown-plugin-nano/command_helpers/database_helpers.rb', line 7

def setup_postgresql
  template "databases/postgresql.yml", "#{folder_name}/config/database.yml"

  create_file "#{folder_name}/db/.keep", ""

  append_to_file "Gemfile" do
    <<~RUBY

      if ENV["RAILS_ENV"]
        gem "pg"
      end
    RUBY
  end
end