-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from rage-rb/standalone-db-2
Allow to preconfigure a database for new apps
- Loading branch information
Showing
19 changed files
with
328 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
begin | ||
require "standalone_migrations" | ||
rescue LoadError | ||
end | ||
|
||
class Rage::Tasks | ||
class << self | ||
def init | ||
load_db_tasks if defined?(StandaloneMigrations) | ||
end | ||
|
||
private | ||
|
||
def load_db_tasks | ||
StandaloneMigrations::Configurator.prepend(Module.new do | ||
def configuration_file | ||
@path ||= begin | ||
@__tempfile = Tempfile.new | ||
@__tempfile.write <<~YAML | ||
config: | ||
database: config/database.yml | ||
YAML | ||
@__tempfile.close | ||
|
||
@__tempfile.path | ||
end | ||
end | ||
end) | ||
|
||
StandaloneMigrations::Tasks.load_tasks | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require_relative "config/application" | ||
Rage.load_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
lib/rage/templates/db-templates/app-models-application_record.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ApplicationRecord < ActiveRecord::Base | ||
self.abstract_class = true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This file should ensure the existence of records required to run the application in every environment (production, | ||
# development, test). The code here should be idempotent so that it can be executed at any point in every environment. | ||
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). | ||
# | ||
# Example: | ||
# | ||
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| | ||
# MovieGenre.find_or_create_by!(name: genre_name) | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## | ||
# MySQL. Versions 5.5.8 and up are supported. | ||
# | ||
default: &default | ||
adapter: mysql2 | ||
encoding: utf8mb4 | ||
pool: <%%= ENV.fetch("DB_MAX_CONNECTIONS") { 5 } %> | ||
username: root | ||
password: | ||
socket: /tmp/mysql.sock | ||
|
||
development: | ||
<<: *default | ||
database: <%= @app_name %>_development | ||
|
||
test: | ||
<<: *default | ||
database: <%= @app_name %>_test | ||
|
||
production: | ||
<<: *default | ||
database: <%= @app_name %>_production | ||
username: <%= @app_name %> | ||
password: <%%= ENV["<%= @app_name.upcase %>_DATABASE_PASSWORD"] %> |
21 changes: 21 additions & 0 deletions
21
lib/rage/templates/db-templates/postgresql/config-database.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## | ||
# PostgreSQL. Versions 9.3 and up are supported. | ||
# | ||
default: &default | ||
adapter: postgresql | ||
encoding: unicode | ||
pool: <%%= ENV.fetch("DB_MAX_CONNECTIONS") { 5 } %> | ||
|
||
development: | ||
<<: *default | ||
database: <%= @app_name %>_development | ||
|
||
test: | ||
<<: *default | ||
database: <%= @app_name %>_test | ||
|
||
production: | ||
<<: *default | ||
database: <%= @app_name %>_production | ||
username: <%= @app_name %> | ||
password: <%%= ENV["<%= @app_name.upcase %>_DATABASE_PASSWORD"] %> |
Oops, something went wrong.