hanami-cli 2.0.0.rc1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +3 -4
- data/exe/hanami +6 -1
- data/hanami-cli.gemspec +3 -2
- data/lib/hanami/cli/bundler.rb +95 -5
- data/lib/hanami/cli/command.rb +41 -0
- data/lib/hanami/cli/commands/app/command.rb +63 -2
- data/lib/hanami/cli/commands/app/console.rb +7 -3
- data/lib/hanami/cli/commands/app/db/create.rb +2 -0
- data/lib/hanami/cli/commands/app/db/create_migration.rb +3 -0
- data/lib/hanami/cli/commands/app/db/drop.rb +2 -0
- data/lib/hanami/cli/commands/app/db/migrate.rb +2 -0
- data/lib/hanami/cli/commands/app/db/reset.rb +2 -0
- data/lib/hanami/cli/commands/app/db/rollback.rb +2 -0
- data/lib/hanami/cli/commands/app/db/sample_data.rb +2 -0
- data/lib/hanami/cli/commands/app/db/seed.rb +2 -0
- data/lib/hanami/cli/commands/app/db/setup.rb +2 -0
- data/lib/hanami/cli/commands/app/db/structure/dump.rb +3 -0
- data/lib/hanami/cli/commands/app/db/utils/database.rb +155 -0
- data/lib/hanami/cli/commands/app/db/utils/database_config.rb +60 -0
- data/lib/hanami/cli/commands/app/db/utils/mysql.rb +33 -0
- data/lib/hanami/cli/commands/app/db/utils/postgres.rb +64 -0
- data/lib/hanami/cli/commands/app/db/utils/sqlite.rb +45 -0
- data/lib/hanami/cli/commands/app/db/version.rb +2 -0
- data/lib/hanami/cli/commands/app/generate/action.rb +10 -3
- data/lib/hanami/cli/commands/app/generate/slice.rb +9 -6
- data/lib/hanami/cli/commands/app/generate.rb +2 -0
- data/lib/hanami/cli/commands/app/install.rb +13 -2
- data/lib/hanami/cli/commands/app/middleware.rb +7 -1
- data/lib/hanami/cli/commands/app/routes.rb +8 -0
- data/lib/hanami/cli/commands/app/server.rb +10 -0
- data/lib/hanami/cli/commands/app/version.rb +4 -2
- data/lib/hanami/cli/commands/app.rb +6 -19
- data/lib/hanami/cli/commands/gem/new.rb +12 -13
- data/lib/hanami/cli/commands/gem/version.rb +4 -2
- data/lib/hanami/cli/commands/gem.rb +8 -5
- data/lib/hanami/cli/commands.rb +19 -3
- data/lib/hanami/cli/errors.rb +65 -0
- data/lib/hanami/cli/files.rb +10 -0
- data/lib/hanami/cli/generators/app/action.rb +11 -5
- data/lib/hanami/cli/generators/app/action_context.rb +22 -0
- data/lib/hanami/cli/generators/app/slice.rb +6 -1
- data/lib/hanami/cli/generators/app/slice_context.rb +8 -0
- data/lib/hanami/cli/generators/context.rb +14 -0
- data/lib/hanami/cli/generators/gem/app.rb +9 -5
- data/lib/hanami/cli/generators/version.rb +8 -6
- data/lib/hanami/cli/middleware_stack_inspector.rb +5 -0
- data/lib/hanami/cli/rake_tasks.rb +0 -1
- data/lib/hanami/cli/repl/core.rb +12 -4
- data/lib/hanami/cli/repl/irb.rb +3 -2
- data/lib/hanami/cli/repl/pry.rb +1 -3
- data/lib/hanami/cli/server.rb +11 -0
- data/lib/hanami/cli/system_call.rb +65 -7
- data/lib/hanami/cli/url.rb +9 -2
- data/lib/hanami/cli/version.rb +4 -1
- data/lib/hanami/cli.rb +26 -3
- data/lib/hanami/console/context.rb +4 -2
- data/lib/hanami/console/plugins/slice_readers.rb +1 -0
- data/lib/hanami-cli.rb +3 -0
- metadata +46 -25
- data/lib/hanami/cli/command_line.rb +0 -17
- data/lib/hanami/cli/commands/db/utils/database.rb +0 -133
- data/lib/hanami/cli/commands/db/utils/database_config.rb +0 -48
- data/lib/hanami/cli/commands/db/utils/mysql.rb +0 -27
- data/lib/hanami/cli/commands/db/utils/postgres.rb +0 -54
- data/lib/hanami/cli/commands/db/utils/sqlite.rb +0 -37
- data/lib/hanami/cli/error.rb +0 -8
data/lib/hanami/cli/server.rb
CHANGED
@@ -2,25 +2,36 @@
|
|
2
2
|
|
3
3
|
module Hanami
|
4
4
|
module CLI
|
5
|
+
# @since 2.0.0
|
5
6
|
# @api private
|
6
7
|
class Server
|
8
|
+
# @since 2.0.0
|
9
|
+
# @api private
|
7
10
|
attr_reader :rack_server
|
8
11
|
|
12
|
+
# @since 2.0.0
|
13
|
+
# @api private
|
9
14
|
RACK_FALLBACK_OPTIONS = {
|
10
15
|
host: :Host,
|
11
16
|
port: :Port
|
12
17
|
}.freeze
|
13
18
|
|
19
|
+
# @since 2.0.0
|
20
|
+
# @api private
|
14
21
|
OVERRIDING_OPTIONS = {
|
15
22
|
config: :config,
|
16
23
|
debug: :debug,
|
17
24
|
warn: :warn
|
18
25
|
}.freeze
|
19
26
|
|
27
|
+
# @since 2.0.0
|
28
|
+
# @api private
|
20
29
|
def initialize(rack_server: Rack::Server)
|
21
30
|
@rack_server = rack_server
|
22
31
|
end
|
23
32
|
|
33
|
+
# @since 2.0.0
|
34
|
+
# @api private
|
24
35
|
def call(**options)
|
25
36
|
rack_server.start(Hash[
|
26
37
|
extract_rack_fallback_options(options) + extract_overriding_options(options)
|
@@ -1,33 +1,90 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# SystemCall#call is adapted from hanami-devtools as well as the Bundler source code. Bundler is
|
4
|
+
# released under the MIT license: https://github.com/bundler/bundler/blob/master/LICENSE.md.
|
5
|
+
#
|
6
|
+
# Thank you to the Bundler maintainers and contributors.
|
7
|
+
|
3
8
|
module Hanami
|
4
9
|
module CLI
|
10
|
+
# Facility for making convenient system calls and returning their results.
|
11
|
+
#
|
12
|
+
# @since 2.0.0
|
13
|
+
# @api public
|
5
14
|
class SystemCall
|
15
|
+
# The result of a system call. Provides access to its standard out and error streams, plus
|
16
|
+
# whether the command executed successfully.
|
17
|
+
#
|
18
|
+
# @since 2.0.0
|
19
|
+
# @api public
|
6
20
|
class Result
|
7
21
|
SUCCESSFUL_EXIT_CODE = 0
|
8
22
|
private_constant :SUCCESSFUL_EXIT_CODE
|
9
23
|
|
10
|
-
|
24
|
+
# Returns the command's exit code
|
25
|
+
#
|
26
|
+
# @return [Integer]
|
27
|
+
#
|
28
|
+
# @since 2.0.0
|
29
|
+
# @api public
|
30
|
+
attr_reader :exit_code
|
31
|
+
|
32
|
+
# Returns the command's standard output stream
|
33
|
+
#
|
34
|
+
# @return [IO]
|
35
|
+
#
|
36
|
+
# @since 2.0.0
|
37
|
+
# @api public
|
38
|
+
attr_reader :out
|
39
|
+
|
40
|
+
# Returns the command's error ouptut stream
|
41
|
+
#
|
42
|
+
# @return [IO]
|
43
|
+
#
|
44
|
+
# @since 2.0.0
|
45
|
+
# @api public
|
46
|
+
attr_reader :err
|
11
47
|
|
48
|
+
# @since 2.0.0
|
49
|
+
# @api private
|
12
50
|
def initialize(exit_code:, out:, err:)
|
13
51
|
@exit_code = exit_code
|
14
52
|
@out = out
|
15
53
|
@err = err
|
16
54
|
end
|
17
55
|
|
56
|
+
# Returns true if the command executed successfully (if its {#exit_code} is 0).
|
57
|
+
#
|
58
|
+
# @return [Boolean]
|
59
|
+
#
|
60
|
+
# @since 2.0.0
|
61
|
+
# @api public
|
18
62
|
def successful?
|
19
63
|
exit_code == SUCCESSFUL_EXIT_CODE
|
20
64
|
end
|
21
65
|
end
|
22
66
|
|
23
|
-
#
|
67
|
+
# Executes the given system command and returns the result.
|
24
68
|
#
|
25
|
-
#
|
26
|
-
#
|
69
|
+
# @param cmd [String] the system command to execute
|
70
|
+
# @param env [Hash<String, String>] an optional hash of environment variables to set before
|
71
|
+
# executing the command
|
27
72
|
#
|
28
|
-
#
|
73
|
+
# @overload call(cmd, env: {})
|
29
74
|
#
|
30
|
-
#
|
75
|
+
# @overload call(cmd, env: {}, &blk)
|
76
|
+
# Executes the command and passes the given block to the `Open3.popen3` method called
|
77
|
+
# internally.
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# call("info") do |stdin, stdout, stderr, wait_thread|
|
81
|
+
# # ...
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
# @return [Result]
|
85
|
+
#
|
86
|
+
# @since 2.0.0
|
87
|
+
# @api public
|
31
88
|
def call(cmd, env: {})
|
32
89
|
exitstatus = nil
|
33
90
|
out = nil
|
@@ -35,7 +92,8 @@ module Hanami
|
|
35
92
|
|
36
93
|
::Bundler.with_unbundled_env do
|
37
94
|
Open3.popen3(env, cmd) do |stdin, stdout, stderr, wait_thr|
|
38
|
-
yield stdin, stdout, wait_thr if block_given?
|
95
|
+
yield stdin, stdout, stderr, wait_thr if block_given?
|
96
|
+
|
39
97
|
stdin.close
|
40
98
|
|
41
99
|
exitstatus = wait_thr&.value&.exitstatus
|
data/lib/hanami/cli/url.rb
CHANGED
@@ -1,28 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "uri"
|
4
|
+
require_relative "./errors"
|
4
5
|
|
5
6
|
module Hanami
|
6
7
|
module CLI
|
8
|
+
# @since 2.0.0
|
9
|
+
# @api private
|
7
10
|
module URL
|
8
11
|
DEFAULT_URL_PREFIX = "/"
|
9
12
|
private_constant :DEFAULT_URL_PREFIX
|
10
13
|
|
11
14
|
class << self
|
15
|
+
# @since 2.0.0
|
16
|
+
# @api private
|
12
17
|
def call(url)
|
13
18
|
result = url
|
14
19
|
result = URI.parse(result).path
|
15
20
|
|
16
21
|
unless valid?(result)
|
17
|
-
raise
|
22
|
+
raise InvalidURLError.new(url)
|
18
23
|
end
|
19
24
|
|
20
25
|
result
|
21
26
|
rescue URI::InvalidURIError
|
22
|
-
raise
|
27
|
+
raise InvalidURLError.new(url)
|
23
28
|
end
|
24
29
|
alias_method :[], :call
|
25
30
|
|
31
|
+
# @since 2.0.0
|
32
|
+
# @api private
|
26
33
|
def valid?(url)
|
27
34
|
return false if url.nil?
|
28
35
|
|
data/lib/hanami/cli/version.rb
CHANGED
data/lib/hanami/cli.rb
CHANGED
@@ -1,13 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "dry/cli"
|
4
|
+
require "zeitwerk"
|
4
5
|
|
5
6
|
module Hanami
|
7
|
+
# Extensible command line interface for Hanami.
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
# @since 2.0.0
|
6
11
|
module CLI
|
7
|
-
|
8
|
-
|
9
|
-
|
12
|
+
# @api private
|
13
|
+
# @since 2.0.0
|
14
|
+
def self.gem_loader
|
15
|
+
@gem_loader ||= Zeitwerk::Loader.new.tap do |loader|
|
16
|
+
root = File.expand_path("..", __dir__)
|
17
|
+
loader.tag = "hanami-cli"
|
18
|
+
loader.inflector = Zeitwerk::GemInflector.new("#{root}/hanami-cli.rb")
|
19
|
+
loader.push_dir(root)
|
20
|
+
loader.ignore(
|
21
|
+
"#{root}/hanami-cli.rb",
|
22
|
+
"#{root}/hanami/cli/{errors,version}.rb"
|
23
|
+
)
|
24
|
+
loader.inflector.inflect("cli" => "CLI")
|
25
|
+
loader.inflector.inflect("db" => "DB")
|
26
|
+
loader.inflector.inflect("url" => "URL")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
gem_loader.setup
|
10
31
|
require_relative "cli/commands"
|
32
|
+
require_relative "cli/errors"
|
33
|
+
require_relative "cli/version"
|
11
34
|
|
12
35
|
extend Dry::CLI::Registry
|
13
36
|
|
@@ -3,15 +3,17 @@
|
|
3
3
|
require_relative "plugins/slice_readers"
|
4
4
|
|
5
5
|
module Hanami
|
6
|
+
# @since 2.0.0
|
7
|
+
# @api private
|
6
8
|
module Console
|
7
9
|
# Hanami app console context
|
8
10
|
#
|
9
|
-
# @api private
|
10
11
|
# @since 2.0.0
|
12
|
+
# @api private
|
11
13
|
class Context < Module
|
12
|
-
# @api private
|
13
14
|
attr_reader :app
|
14
15
|
|
16
|
+
# @since 2.0.0
|
15
17
|
# @api private
|
16
18
|
def initialize(app)
|
17
19
|
super()
|
data/lib/hanami-cli.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,26 +25,35 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: dry-cli
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
41
|
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
43
|
+
version: '1.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: dry-
|
48
|
+
name: dry-files
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '1.0'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.0.1
|
48
57
|
- - "<"
|
49
58
|
- !ruby/object:Gem::Version
|
50
59
|
version: '2'
|
@@ -55,11 +64,14 @@ dependencies:
|
|
55
64
|
- - "~>"
|
56
65
|
- !ruby/object:Gem::Version
|
57
66
|
version: '1.0'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.1
|
58
70
|
- - "<"
|
59
71
|
- !ruby/object:Gem::Version
|
60
72
|
version: '2'
|
61
73
|
- !ruby/object:Gem::Dependency
|
62
|
-
name: dry-
|
74
|
+
name: dry-inflector
|
63
75
|
requirement: !ruby/object:Gem::Requirement
|
64
76
|
requirements:
|
65
77
|
- - "~>"
|
@@ -79,25 +91,33 @@ dependencies:
|
|
79
91
|
- !ruby/object:Gem::Version
|
80
92
|
version: '2'
|
81
93
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
94
|
+
name: rake
|
83
95
|
requirement: !ruby/object:Gem::Requirement
|
84
96
|
requirements:
|
85
97
|
- - "~>"
|
86
98
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
88
|
-
- - "<"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '2'
|
99
|
+
version: '13.0'
|
91
100
|
type: :runtime
|
92
101
|
prerelease: false
|
93
102
|
version_requirements: !ruby/object:Gem::Requirement
|
94
103
|
requirements:
|
95
104
|
- - "~>"
|
96
105
|
- !ruby/object:Gem::Version
|
97
|
-
version: '
|
98
|
-
|
106
|
+
version: '13.0'
|
107
|
+
- !ruby/object:Gem::Dependency
|
108
|
+
name: zeitwerk
|
109
|
+
requirement: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
99
112
|
- !ruby/object:Gem::Version
|
100
|
-
version: '2'
|
113
|
+
version: '2.6'
|
114
|
+
type: :runtime
|
115
|
+
prerelease: false
|
116
|
+
version_requirements: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - "~>"
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '2.6'
|
101
121
|
- !ruby/object:Gem::Dependency
|
102
122
|
name: rspec
|
103
123
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,6 +174,7 @@ files:
|
|
154
174
|
- ".gitignore"
|
155
175
|
- ".rspec"
|
156
176
|
- ".rubocop.yml"
|
177
|
+
- ".yardopts"
|
157
178
|
- CHANGELOG.md
|
158
179
|
- CODE_OF_CONDUCT.md
|
159
180
|
- Gemfile
|
@@ -164,10 +185,10 @@ files:
|
|
164
185
|
- bin/setup
|
165
186
|
- exe/hanami
|
166
187
|
- hanami-cli.gemspec
|
188
|
+
- lib/hanami-cli.rb
|
167
189
|
- lib/hanami/cli.rb
|
168
190
|
- lib/hanami/cli/bundler.rb
|
169
191
|
- lib/hanami/cli/command.rb
|
170
|
-
- lib/hanami/cli/command_line.rb
|
171
192
|
- lib/hanami/cli/commands.rb
|
172
193
|
- lib/hanami/cli/commands/app.rb
|
173
194
|
- lib/hanami/cli/commands/app/command.rb
|
@@ -182,6 +203,11 @@ files:
|
|
182
203
|
- lib/hanami/cli/commands/app/db/seed.rb
|
183
204
|
- lib/hanami/cli/commands/app/db/setup.rb
|
184
205
|
- lib/hanami/cli/commands/app/db/structure/dump.rb
|
206
|
+
- lib/hanami/cli/commands/app/db/utils/database.rb
|
207
|
+
- lib/hanami/cli/commands/app/db/utils/database_config.rb
|
208
|
+
- lib/hanami/cli/commands/app/db/utils/mysql.rb
|
209
|
+
- lib/hanami/cli/commands/app/db/utils/postgres.rb
|
210
|
+
- lib/hanami/cli/commands/app/db/utils/sqlite.rb
|
185
211
|
- lib/hanami/cli/commands/app/db/version.rb
|
186
212
|
- lib/hanami/cli/commands/app/generate.rb
|
187
213
|
- lib/hanami/cli/commands/app/generate/action.rb
|
@@ -191,15 +217,10 @@ files:
|
|
191
217
|
- lib/hanami/cli/commands/app/routes.rb
|
192
218
|
- lib/hanami/cli/commands/app/server.rb
|
193
219
|
- lib/hanami/cli/commands/app/version.rb
|
194
|
-
- lib/hanami/cli/commands/db/utils/database.rb
|
195
|
-
- lib/hanami/cli/commands/db/utils/database_config.rb
|
196
|
-
- lib/hanami/cli/commands/db/utils/mysql.rb
|
197
|
-
- lib/hanami/cli/commands/db/utils/postgres.rb
|
198
|
-
- lib/hanami/cli/commands/db/utils/sqlite.rb
|
199
220
|
- lib/hanami/cli/commands/gem.rb
|
200
221
|
- lib/hanami/cli/commands/gem/new.rb
|
201
222
|
- lib/hanami/cli/commands/gem/version.rb
|
202
|
-
- lib/hanami/cli/
|
223
|
+
- lib/hanami/cli/errors.rb
|
203
224
|
- lib/hanami/cli/files.rb
|
204
225
|
- lib/hanami/cli/generators/app/action.rb
|
205
226
|
- lib/hanami/cli/generators/app/action/action.erb
|
@@ -265,11 +286,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
265
286
|
version: '3.0'
|
266
287
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
267
288
|
requirements:
|
268
|
-
- - "
|
289
|
+
- - ">="
|
269
290
|
- !ruby/object:Gem::Version
|
270
|
-
version:
|
291
|
+
version: '0'
|
271
292
|
requirements: []
|
272
|
-
rubygems_version: 3.3.
|
293
|
+
rubygems_version: 3.3.7
|
273
294
|
signing_key:
|
274
295
|
specification_version: 4
|
275
296
|
summary: Hanami CLI
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./bundler"
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
module CLI
|
7
|
-
class CommandLine
|
8
|
-
def initialize(bundler: CLI::Bundler.new)
|
9
|
-
@bundler = bundler
|
10
|
-
end
|
11
|
-
|
12
|
-
def call(command)
|
13
|
-
@bundler.exec(command)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "database_config"
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
module CLI
|
7
|
-
module Commands
|
8
|
-
module DB
|
9
|
-
module Utils
|
10
|
-
class Database
|
11
|
-
attr_reader :app, :config
|
12
|
-
|
13
|
-
SCHEME_MAP = {
|
14
|
-
"sqlite" => -> {
|
15
|
-
require_relative("sqlite")
|
16
|
-
Sqlite
|
17
|
-
},
|
18
|
-
"postgres" => -> {
|
19
|
-
require_relative("postgres")
|
20
|
-
Postgres
|
21
|
-
},
|
22
|
-
"postgresql" => -> {
|
23
|
-
require_relative("postgres")
|
24
|
-
Postgres
|
25
|
-
},
|
26
|
-
"mysql" => -> {
|
27
|
-
require_relative("mysql")
|
28
|
-
Mysql
|
29
|
-
}
|
30
|
-
}.freeze
|
31
|
-
|
32
|
-
def self.[](app)
|
33
|
-
database_url =
|
34
|
-
if app.key?(:settings) && app[:settings].respond_to?(:database_url)
|
35
|
-
app[:settings].database_url
|
36
|
-
else
|
37
|
-
ENV.fetch("DATABASE_URL")
|
38
|
-
end
|
39
|
-
|
40
|
-
config = DatabaseConfig.new(database_url)
|
41
|
-
|
42
|
-
resolver = SCHEME_MAP.fetch(config.db_type) do
|
43
|
-
raise "#{config.db_type} is not a supported db scheme"
|
44
|
-
end
|
45
|
-
|
46
|
-
klass = resolver.()
|
47
|
-
|
48
|
-
klass.new(app: app, config: config)
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize(app:, config:)
|
52
|
-
@app = app
|
53
|
-
@config = config
|
54
|
-
end
|
55
|
-
|
56
|
-
def create_command
|
57
|
-
raise NotImplementedError
|
58
|
-
end
|
59
|
-
|
60
|
-
def drop_command
|
61
|
-
raise NotImplementedError
|
62
|
-
end
|
63
|
-
|
64
|
-
def dump_command
|
65
|
-
raise NotImplementedError
|
66
|
-
end
|
67
|
-
|
68
|
-
def load_command
|
69
|
-
raise NotImplementedError
|
70
|
-
end
|
71
|
-
|
72
|
-
def root_path
|
73
|
-
app.root
|
74
|
-
end
|
75
|
-
|
76
|
-
def rom_config
|
77
|
-
@rom_config ||=
|
78
|
-
begin
|
79
|
-
app.prepare(:persistence)
|
80
|
-
app.container["persistence.config"]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def name
|
85
|
-
config.db_name
|
86
|
-
end
|
87
|
-
|
88
|
-
def gateway
|
89
|
-
rom_config.gateways[:default]
|
90
|
-
end
|
91
|
-
|
92
|
-
def connection
|
93
|
-
gateway.connection
|
94
|
-
end
|
95
|
-
|
96
|
-
def run_migrations(**options)
|
97
|
-
require "rom/sql"
|
98
|
-
ROM::SQL.with_gateway(gateway) do
|
99
|
-
migrator.run(options)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def migrator
|
104
|
-
@migrator ||=
|
105
|
-
begin
|
106
|
-
require "rom/sql"
|
107
|
-
ROM::SQL::Migration::Migrator.new(connection, path: File.join(root_path, "db/migrate"))
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def applied_migrations
|
112
|
-
sequel_migrator.applied_migrations
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
def sequel_migrator
|
118
|
-
@sequel_migrator ||= begin
|
119
|
-
require "sequel"
|
120
|
-
Sequel.extension :migration
|
121
|
-
Sequel::TimestampMigrator.new(migrator.connection, migrations_path, {})
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def migrations_path
|
126
|
-
File.join(root_path, "db/migrate")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "uri"
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
module CLI
|
7
|
-
module Commands
|
8
|
-
module DB
|
9
|
-
module Utils
|
10
|
-
class DatabaseConfig
|
11
|
-
attr_reader :uri
|
12
|
-
|
13
|
-
def initialize(database_url)
|
14
|
-
@uri = URI(database_url)
|
15
|
-
end
|
16
|
-
|
17
|
-
def hostname
|
18
|
-
uri.hostname
|
19
|
-
end
|
20
|
-
alias_method :host, :hostname
|
21
|
-
|
22
|
-
def user
|
23
|
-
uri.user
|
24
|
-
end
|
25
|
-
alias_method :username, :user
|
26
|
-
|
27
|
-
def password
|
28
|
-
uri.password
|
29
|
-
end
|
30
|
-
alias_method :pass, :password
|
31
|
-
|
32
|
-
def port
|
33
|
-
uri.port
|
34
|
-
end
|
35
|
-
|
36
|
-
def db_name
|
37
|
-
@db_name ||= uri.path.gsub(/\A\//, "")
|
38
|
-
end
|
39
|
-
|
40
|
-
def db_type
|
41
|
-
uri.scheme
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "database"
|
4
|
-
|
5
|
-
module Hanami
|
6
|
-
module CLI
|
7
|
-
module Commands
|
8
|
-
module DB
|
9
|
-
module Utils
|
10
|
-
class Mysql < Database
|
11
|
-
def create_command
|
12
|
-
raise "Not Implemented Yet"
|
13
|
-
end
|
14
|
-
|
15
|
-
def dump_command
|
16
|
-
raise "Not Implemented Yet"
|
17
|
-
end
|
18
|
-
|
19
|
-
def load_command
|
20
|
-
raise "Not Implemented Yet"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|