-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix postgresql database naming convention #332
Merged
eliasjpr
merged 9 commits into
amberframework:master
from
marksiemers:fix-postgres-naming
Oct 31, 2017
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
91b05ff
Add test for generating and app with postgres
marksiemers ce93cc4
Add test for database url in environment yaml files
marksiemers 57002a9
Add tests for database urls and names generated for docker-compose.yml
marksiemers 3e93f9d
Replace '-' with '_' for postgresql database names
marksiemers 2d33f38
Switch default postgresql username to postgres in database.yml
marksiemers 3353eb8
Name databases consistently for pg, mysql, sqlite
marksiemers ed49003
Test Amber::CLI::App directly for database naming
marksiemers 14ff578
Use 'database_name_base' property in all parts of docker-compose.yml
marksiemers dbe4912
Merge branch 'master' into fix-postgres-naming
drujensen File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "../../../spec_helper" | ||
|
||
module Amber::CLI | ||
describe App do | ||
pg_app = App.new("sample-app") | ||
mysql_app = App.new("sample-app", "mysql") | ||
sqlite_app = App.new("sample-app", "sqlite") | ||
|
||
describe "#database_name_base" do | ||
it "should return a postgres compatible name" do | ||
pg_app.database_name_base.should_not contain "-" | ||
end | ||
|
||
it "should return a consistent name for all db types" do | ||
mysql_app.database_name_base.should eq pg_app.database_name_base | ||
sqlite_app.database_name_base.should eq pg_app.database_name_base | ||
end | ||
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ ENV["AMBER_ENV"] = "test" | |
TEST_PATH = "spec/support/sample" | ||
PUBLIC_PATH = TEST_PATH + "/public" | ||
VIEWS_PATH = TEST_PATH + "/views" | ||
TEST_APP_NAME = "test_app" | ||
TEST_APP_NAME = "sample-app" | ||
TESTING_APP = "./tmp/#{TEST_APP_NAME}" | ||
APP_TPL_PATH = "./src/amber/cli/templates/app" | ||
CURRENT_DIR = Dir.current | ||
|
@@ -30,6 +30,15 @@ module Amber::CLI::Spec | |
gen_dirs.map { |dir| dir[(app.size + 1)..-1] } | ||
end | ||
|
||
def db_name(db_url : String) : String | ||
db_name(URI.parse(db_url)) | ||
end | ||
|
||
def db_name(db_uri : URI) : String | ||
path = db_uri.path | ||
path ? path.split('/').last : "" | ||
end | ||
|
||
def db_yml | ||
YAML.parse(File.read("#{TESTING_APP}/config/database.yml")) | ||
end | ||
|
@@ -42,6 +51,26 @@ module Amber::CLI::Spec | |
YAML.parse(File.read("#{TESTING_APP}/shard.yml")) | ||
end | ||
|
||
def environment_yml(environment : String) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't these already exist? Why does it show you adding them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK, not for the environment yaml files. It did exist for others: def db_yml
YAML.parse(File.read("#{TESTING_APP}/config/database.yml"))
end
def amber_yml
YAML.parse(File.read("#{TESTING_APP}/.amber.yml"))
end
def shard_yml
YAML.parse(File.read("#{TESTING_APP}/shard.yml"))
end |
||
YAML.parse(File.read("#{TESTING_APP}/config/environments/#{environment}.yml")) | ||
end | ||
|
||
def development_yml | ||
environment_yml("development") | ||
end | ||
|
||
def production_yml | ||
environment_yml("production") | ||
end | ||
|
||
def test_yml | ||
environment_yml("test") | ||
end | ||
|
||
def docker_compose_yml | ||
YAML.parse(File.read("#{TESTING_APP}/docker-compose.yml")) | ||
end | ||
|
||
def prepare_yaml(path) | ||
shard = File.read("#{path}/shard.yml") | ||
shard = shard.gsub("github: amberframework/amber\n", "path: ../../\n") | ||
|
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<%= @database %>: | ||
<% case @database | ||
when "mysql" -%> | ||
database: mysql://root@localhost:3306/<%= "#{@name}_development" %> | ||
database: mysql://root@localhost:3306/<%= "#{database_name_base}_development" %> | ||
<% when "pg" -%> | ||
database: postgres://root:@localhost:5432/<%= "#{@name}_development" %> | ||
database: postgres://postgres:@localhost:5432/<%= "#{database_name_base}_development" %> | ||
<% when "sqlite" -%> | ||
database: sqlite3:./db/<%= "#{@name}_development" %>.db | ||
database: sqlite3:./db/<%= "#{database_name_base}_development" %>.db | ||
<% 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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? I personally prefer "test_app" since that's what it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons, though this might not be the best place for it: