Skip to content
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
merged 9 commits into from Oct 31, 2017

Conversation

marksiemers
Copy link
Contributor

Description of the Change

This fixes the issue that if an app name has a dash "-" in it, then an invalid database name will be generated for postgresql.

Alternate Designs

Some alternative choices:

  • Treat the database name consistently, and have this convention apply to all database types
  • Refactor to have the database name generation take place in one spot, instead of across many files

Adopting the first would make the second easier to accomplish.

Benefits

Users will not face errors generating a new postgresql database when their app name has a dash in it. Fixes #329

Possible Drawbacks

As written, this will create inconsistent database names between postgresql and other databases.

Also, I changed the name of the TESTING_APP from test_app to sample-app. It didn't cause any pre-existing tests to fail, so I don't think it is an issue.

@marksiemers
Copy link
Contributor Author

I did not make any changes to the default user for postgresql. It is still root in one or two places.

I can incorporate that change also if wanted.

@drujensen
Copy link
Member

@marksiemers yes, go ahead and change the default user.

@marksiemers
Copy link
Contributor Author

@drujensen - I can get that change in tomorrow. Overall, is my approach of adding a lot of LOC to the test suite acceptable? Not just for this change, but in general?

@marksiemers
Copy link
Contributor Author

The changes that were merged in from master may mean I have to rework some code. A few questions:

  1. With the change to spec/spec_helper.cr is it now preferred not to Dir.cd in any of the tests?
  2. Is it preferred to resolve conflicts then create additional commits, or rebase locally, and push all new commits?

@drujensen
Copy link
Member

@marksiemers the test coverage and approach your taking looks good to me.

@marksiemers
Copy link
Contributor Author

Conflicts have been resolved, anything else needed for this PR?

@marksiemers
Copy link
Contributor Author

One question - should the database name be treated the same for all databases? Should we gsub('-', '_') for sqlite and mysql also?

@drujensen
Copy link
Member

@marksiemers yes, I think you can rename it for all 3 for consistency.

@marksiemers
Copy link
Contributor Author

@drujensen - The naming is now consistent. This one should be good to merge.

Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@elorest elorest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marksiemers In regard to your last question. I think we should always default database names to be underscore instead of hyphen. Same for files and folder names as well.

@@ -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"
Copy link
Member

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.

Copy link
Contributor Author

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:

  1. In order to test this fix, the app name needs a dash (-) in it
  2. This test would be a false green for an app containing "test"

@@ -42,6 +51,26 @@ module Amber::CLI::Spec
YAML.parse(File.read("#{TESTING_APP}/shard.yml"))
end

def environment_yml(environment : String)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't these already exist? Why does it show you adding them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

@drujensen
Copy link
Member

@elorest @eliasjpr Is this approved? Would like to merge it.

@marksiemers
Copy link
Contributor Author

marksiemers commented Oct 31, 2017

@elorest

I think we should always default database names to be underscore instead of hyphen.

That should be the case after this is merged in, all 3 dbs will use database_name_base which gsubs "-" with "_"

Same for files and folder names as well.

In #330 we are consistent with underscore, but I did not gsub hyphens. It should be easy enough to do - likely one line (not including tests).

@marksiemers
Copy link
Contributor Author

The build finally passed, are we good to merge?

@eliasjpr eliasjpr merged commit b876e97 into amberframework:master Oct 31, 2017
elorest pushed a commit that referenced this pull request Nov 17, 2017
* Add test for generating and app with postgres

* Add test for database url in environment yaml files

* Add tests for database urls and names generated for docker-compose.yml

* Replace '-' with '_' for postgresql database names

* Switch default postgresql username to postgres in database.yml

* Name databases consistently for pg, mysql, sqlite

* Test Amber::CLI::App directly for database naming

* Use 'database_name_base' property in all parts of docker-compose.yml
elorest pushed a commit that referenced this pull request Nov 17, 2017
* Add test for generating and app with postgres

* Add test for database url in environment yaml files

* Add tests for database urls and names generated for docker-compose.yml

* Replace '-' with '_' for postgresql database names

* Switch default postgresql username to postgres in database.yml

* Name databases consistently for pg, mysql, sqlite

* Test Amber::CLI::App directly for database naming

* Use 'database_name_base' property in all parts of docker-compose.yml


Former-commit-id: 69716c4
@faustinoaq faustinoaq added this to Done in Framework 2018 May 5, 2018
@faustinoaq faustinoaq removed this from Done in Framework 2018 Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

App names with dashes (-) create invalid postgresql database names
5 participants