hanami-cli 2.0.0.beta4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -1
  3. data/.rubocop.yml +2 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG.md +14 -0
  6. data/Gemfile +7 -4
  7. data/exe/hanami +6 -1
  8. data/hanami-cli.gemspec +4 -3
  9. data/lib/hanami/cli/bundler.rb +95 -5
  10. data/lib/hanami/cli/command.rb +41 -0
  11. data/lib/hanami/cli/commands/app/command.rb +63 -2
  12. data/lib/hanami/cli/commands/app/console.rb +7 -3
  13. data/lib/hanami/cli/commands/app/db/create.rb +2 -0
  14. data/lib/hanami/cli/commands/app/db/create_migration.rb +3 -0
  15. data/lib/hanami/cli/commands/app/db/drop.rb +2 -0
  16. data/lib/hanami/cli/commands/app/db/migrate.rb +2 -0
  17. data/lib/hanami/cli/commands/app/db/reset.rb +2 -0
  18. data/lib/hanami/cli/commands/app/db/rollback.rb +2 -0
  19. data/lib/hanami/cli/commands/app/db/sample_data.rb +2 -0
  20. data/lib/hanami/cli/commands/app/db/seed.rb +2 -0
  21. data/lib/hanami/cli/commands/app/db/setup.rb +2 -0
  22. data/lib/hanami/cli/commands/app/db/structure/dump.rb +3 -0
  23. data/lib/hanami/cli/commands/app/db/utils/database.rb +155 -0
  24. data/lib/hanami/cli/commands/app/db/utils/database_config.rb +60 -0
  25. data/lib/hanami/cli/commands/app/db/utils/mysql.rb +33 -0
  26. data/lib/hanami/cli/commands/app/db/utils/postgres.rb +64 -0
  27. data/lib/hanami/cli/commands/app/db/utils/sqlite.rb +45 -0
  28. data/lib/hanami/cli/commands/app/db/version.rb +2 -0
  29. data/lib/hanami/cli/commands/app/generate/action.rb +10 -3
  30. data/lib/hanami/cli/commands/app/generate/slice.rb +9 -6
  31. data/lib/hanami/cli/commands/app/generate.rb +2 -0
  32. data/lib/hanami/cli/commands/app/install.rb +13 -2
  33. data/lib/hanami/cli/commands/app/middleware.rb +7 -1
  34. data/lib/hanami/cli/commands/app/routes.rb +8 -0
  35. data/lib/hanami/cli/commands/app/server.rb +10 -0
  36. data/lib/hanami/cli/commands/app/version.rb +4 -2
  37. data/lib/hanami/cli/commands/app.rb +6 -19
  38. data/lib/hanami/cli/commands/gem/new.rb +12 -13
  39. data/lib/hanami/cli/commands/gem/version.rb +4 -2
  40. data/lib/hanami/cli/commands/gem.rb +8 -5
  41. data/lib/hanami/cli/commands.rb +19 -3
  42. data/lib/hanami/cli/errors.rb +65 -0
  43. data/lib/hanami/cli/files.rb +10 -0
  44. data/lib/hanami/cli/generators/app/action.rb +11 -5
  45. data/lib/hanami/cli/generators/app/action_context.rb +22 -0
  46. data/lib/hanami/cli/generators/app/slice.rb +6 -1
  47. data/lib/hanami/cli/generators/app/slice_context.rb +8 -0
  48. data/lib/hanami/cli/generators/context.rb +14 -0
  49. data/lib/hanami/cli/generators/gem/app.rb +9 -5
  50. data/lib/hanami/cli/generators/version.rb +8 -6
  51. data/lib/hanami/cli/middleware_stack_inspector.rb +5 -0
  52. data/lib/hanami/cli/rake_tasks.rb +0 -1
  53. data/lib/hanami/cli/repl/core.rb +12 -4
  54. data/lib/hanami/cli/repl/irb.rb +3 -2
  55. data/lib/hanami/cli/repl/pry.rb +1 -3
  56. data/lib/hanami/cli/server.rb +11 -0
  57. data/lib/hanami/cli/system_call.rb +65 -7
  58. data/lib/hanami/cli/url.rb +9 -2
  59. data/lib/hanami/cli/version.rb +5 -1
  60. data/lib/hanami/cli.rb +26 -3
  61. data/lib/hanami/console/context.rb +4 -2
  62. data/lib/hanami/console/plugins/slice_readers.rb +1 -0
  63. data/lib/hanami-cli.rb +3 -0
  64. metadata +60 -27
  65. data/lib/hanami/cli/command_line.rb +0 -17
  66. data/lib/hanami/cli/commands/db/utils/database.rb +0 -133
  67. data/lib/hanami/cli/commands/db/utils/database_config.rb +0 -48
  68. data/lib/hanami/cli/commands/db/utils/mysql.rb +0 -27
  69. data/lib/hanami/cli/commands/db/utils/postgres.rb +0 -54
  70. data/lib/hanami/cli/commands/db/utils/sqlite.rb +0 -37
  71. data/lib/hanami/cli/error.rb +0 -8
@@ -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
- attr_reader :exit_code, :out, :err
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
- # Adapted from Bundler source code
67
+ # Executes the given system command and returns the result.
24
68
  #
25
- # Bundler is released under MIT license
26
- # https://github.com/bundler/bundler/blob/master/LICENSE.md
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
- # A special "thank you" goes to Bundler maintainers and contributors.
73
+ # @overload call(cmd, env: {})
29
74
  #
30
- # Also adapted from `hanami-devtools` source code
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
@@ -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 ArgumentError.new("invalid URL: `#{url}'")
22
+ raise InvalidURLError.new(url)
18
23
  end
19
24
 
20
25
  result
21
26
  rescue URI::InvalidURIError
22
- raise ArgumentError.new("invalid URL: `#{url}'")
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
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Hanami
4
4
  module CLI
5
- VERSION = "2.0.0.beta4"
5
+ # The current hanami-cli version.
6
+ #
7
+ # @api public
8
+ # @since 2.0.0
9
+ VERSION = "2.0.0"
6
10
  end
7
11
  end
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
- require_relative "cli/version"
8
- require_relative "cli/error"
9
- require_relative "cli/bundler"
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()
@@ -8,6 +8,7 @@ module Hanami
8
8
  # @api private
9
9
  # @since 2.0.0
10
10
  class SliceReaders < Module
11
+ # @since 2.0.0
11
12
  # @api private
12
13
  def initialize(app)
13
14
  super()
data/lib/hanami-cli.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "hanami/cli"
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.beta4
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-10-24 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -25,67 +25,99 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: dry-cli
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '13.0'
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: '13.0'
43
+ version: '1.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
41
47
  - !ruby/object:Gem::Dependency
42
- name: dry-cli
48
+ name: dry-files
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0.7'
53
+ version: '1.0'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 1.0.1
57
+ - - "<"
58
+ - !ruby/object:Gem::Version
59
+ version: '2'
48
60
  type: :runtime
49
61
  prerelease: false
50
62
  version_requirements: !ruby/object:Gem::Requirement
51
63
  requirements:
52
64
  - - "~>"
53
65
  - !ruby/object:Gem::Version
54
- version: '0.7'
66
+ version: '1.0'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.1
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '2'
55
73
  - !ruby/object:Gem::Dependency
56
- name: dry-files
74
+ name: dry-inflector
57
75
  requirement: !ruby/object:Gem::Requirement
58
76
  requirements:
59
77
  - - "~>"
60
78
  - !ruby/object:Gem::Version
61
- version: '0.3'
62
- - - ">="
79
+ version: '1.0'
80
+ - - "<"
63
81
  - !ruby/object:Gem::Version
64
- version: 0.3.0
82
+ version: '2'
65
83
  type: :runtime
66
84
  prerelease: false
67
85
  version_requirements: !ruby/object:Gem::Requirement
68
86
  requirements:
69
87
  - - "~>"
70
88
  - !ruby/object:Gem::Version
71
- version: '0.3'
72
- - - ">="
89
+ version: '1.0'
90
+ - - "<"
73
91
  - !ruby/object:Gem::Version
74
- version: 0.3.0
92
+ version: '2'
75
93
  - !ruby/object:Gem::Dependency
76
- name: dry-inflector
94
+ name: rake
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '13.0'
100
+ type: :runtime
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '13.0'
107
+ - !ruby/object:Gem::Dependency
108
+ name: zeitwerk
77
109
  requirement: !ruby/object:Gem::Requirement
78
110
  requirements:
79
111
  - - "~>"
80
112
  - !ruby/object:Gem::Version
81
- version: '0.2'
113
+ version: '2.6'
82
114
  type: :runtime
83
115
  prerelease: false
84
116
  version_requirements: !ruby/object:Gem::Requirement
85
117
  requirements:
86
118
  - - "~>"
87
119
  - !ruby/object:Gem::Version
88
- version: '0.2'
120
+ version: '2.6'
89
121
  - !ruby/object:Gem::Dependency
90
122
  name: rspec
91
123
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +174,7 @@ files:
142
174
  - ".gitignore"
143
175
  - ".rspec"
144
176
  - ".rubocop.yml"
177
+ - ".yardopts"
145
178
  - CHANGELOG.md
146
179
  - CODE_OF_CONDUCT.md
147
180
  - Gemfile
@@ -152,10 +185,10 @@ files:
152
185
  - bin/setup
153
186
  - exe/hanami
154
187
  - hanami-cli.gemspec
188
+ - lib/hanami-cli.rb
155
189
  - lib/hanami/cli.rb
156
190
  - lib/hanami/cli/bundler.rb
157
191
  - lib/hanami/cli/command.rb
158
- - lib/hanami/cli/command_line.rb
159
192
  - lib/hanami/cli/commands.rb
160
193
  - lib/hanami/cli/commands/app.rb
161
194
  - lib/hanami/cli/commands/app/command.rb
@@ -170,6 +203,11 @@ files:
170
203
  - lib/hanami/cli/commands/app/db/seed.rb
171
204
  - lib/hanami/cli/commands/app/db/setup.rb
172
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
173
211
  - lib/hanami/cli/commands/app/db/version.rb
174
212
  - lib/hanami/cli/commands/app/generate.rb
175
213
  - lib/hanami/cli/commands/app/generate/action.rb
@@ -179,15 +217,10 @@ files:
179
217
  - lib/hanami/cli/commands/app/routes.rb
180
218
  - lib/hanami/cli/commands/app/server.rb
181
219
  - lib/hanami/cli/commands/app/version.rb
182
- - lib/hanami/cli/commands/db/utils/database.rb
183
- - lib/hanami/cli/commands/db/utils/database_config.rb
184
- - lib/hanami/cli/commands/db/utils/mysql.rb
185
- - lib/hanami/cli/commands/db/utils/postgres.rb
186
- - lib/hanami/cli/commands/db/utils/sqlite.rb
187
220
  - lib/hanami/cli/commands/gem.rb
188
221
  - lib/hanami/cli/commands/gem/new.rb
189
222
  - lib/hanami/cli/commands/gem/version.rb
190
- - lib/hanami/cli/error.rb
223
+ - lib/hanami/cli/errors.rb
191
224
  - lib/hanami/cli/files.rb
192
225
  - lib/hanami/cli/generators/app/action.rb
193
226
  - lib/hanami/cli/generators/app/action/action.erb
@@ -253,9 +286,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
286
  version: '3.0'
254
287
  required_rubygems_version: !ruby/object:Gem::Requirement
255
288
  requirements:
256
- - - ">"
289
+ - - ">="
257
290
  - !ruby/object:Gem::Version
258
- version: 1.3.1
291
+ version: '0'
259
292
  requirements: []
260
293
  rubygems_version: 3.3.7
261
294
  signing_key:
@@ -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