Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/hanami/cli/generators/gem/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def generate_app(app, context) # rubocop:disable Metrics/AbcSize
if context.generate_sqlite?
fs.create("db/.keep", t("keep.erb", context))
end

if context.generate_postgres? || context.generate_mysql?
fs.create("compose.yml", t("compose.yml.erb", context))
end
end

fs.create("app/operation.rb", t("operation.erb", context))
Expand Down
28 changes: 28 additions & 0 deletions lib/hanami/cli/generators/gem/app/compose.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
<%- if generate_postgres? -%>
postgres:
image: postgres:latest
ports:
- 5432:5432
environment:
POSTGRES_DB: <%= app %>
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
postgres_data:
<%- elsif generate_mysql? -%>
mysql:
image: mysql:latest
ports:
- 3306:3306
environment:
MYSQL_DATABASE: <%= app %>
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
volumes:
- mysql_data:/var/lib/mysql

volumes:
mysql_data:
<%- end -%>
13 changes: 13 additions & 0 deletions spec/unit/hanami/cli/commands/gem/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ module Types
expect(fs.exist?("config/db/")).to be(false)
expect(fs.read(".gitignore")).to_not include("db/*.sqlite")
expect(fs.exist?("db/")).to be(false)
expect(fs.exist?("compose.yml")).to be(false)

# bin/setup
bin_setup = <<~EXPECTED
Expand Down Expand Up @@ -1491,6 +1492,7 @@ class App < Hanami::App
expect(fs.read(".env")).to include("DATABASE_URL=sqlite://db/#{app}.sqlite")
expect(fs.read(".gitignore")).to include("db/*.sqlite")
expect(fs.exist?("db/.keep")).to be(true)
expect(fs.exist?("compose.yml")).to be(false)
end
end

Expand All @@ -1503,6 +1505,7 @@ class App < Hanami::App
expect(fs.read(".env")).to include("DATABASE_URL=sqlite://db/#{app}.sqlite")
expect(fs.read(".gitignore")).to include("db/*.sqlite")
expect(fs.exist?("db/.keep")).to be(true)
expect(fs.exist?("compose.yml")).to be(false)
end
end
end
Expand All @@ -1517,6 +1520,8 @@ class App < Hanami::App
expect(fs.read(".env")).to include("DATABASE_URL=postgres://localhost/#{app}")
expect(fs.read(".gitignore")).to_not include("db/*.sqlite")
expect(fs.exist?("db/")).to be(false)
expect(fs.read("compose.yml")).to include("postgres:")
expect(fs.read("compose.yml")).to include("POSTGRES_DB: #{app}")
end
end

Expand All @@ -1529,6 +1534,8 @@ class App < Hanami::App
expect(fs.read(".env")).to include("DATABASE_URL=postgres://localhost/#{app}")
expect(fs.read(".gitignore")).to_not include("db/*.sqlite")
expect(fs.exist?("db/")).to be(false)
expect(fs.read("compose.yml")).to include("postgres:")
expect(fs.read("compose.yml")).to include("POSTGRES_DB: #{app}")
end
end

Expand All @@ -1541,6 +1548,8 @@ class App < Hanami::App
expect(fs.read(".env")).to include("DATABASE_URL=postgres://localhost/#{app}")
expect(fs.read(".gitignore")).to_not include("db/*.sqlite")
expect(fs.exist?("db/")).to be(false)
expect(fs.read("compose.yml")).to include("postgres:")
expect(fs.read("compose.yml")).to include("POSTGRES_DB: #{app}")
end
end
end
Expand All @@ -1555,6 +1564,8 @@ class App < Hanami::App
expect(fs.read(".env")).to include("DATABASE_URL=mysql2://root@localhost/#{app}")
expect(fs.read(".gitignore")).to_not include("db/*.sqlite")
expect(fs.exist?("db/")).to be(false)
expect(fs.read("compose.yml")).to include("mysql:")
expect(fs.read("compose.yml")).to include("MYSQL_DATABASE: #{app}")
end
end

Expand All @@ -1567,6 +1578,8 @@ class App < Hanami::App
expect(fs.read(".env")).to include("DATABASE_URL=mysql2://root@localhost/#{app}")
expect(fs.read(".gitignore")).to_not include("db/*.sqlite")
expect(fs.exist?("db/")).to be(false)
expect(fs.read("compose.yml")).to include("mysql:")
expect(fs.read("compose.yml")).to include("MYSQL_DATABASE: #{app}")
end
end
end
Expand Down
Loading