Class: Hanami::CLI::Commands::App::DB::Utils::Database Private
- Inherits:
-
Object
- Object
- Hanami::CLI::Commands::App::DB::Utils::Database
- Defined in:
- lib/hanami/cli/commands/app/db/utils/database.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- SCHEME_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ "sqlite" => -> { require_relative("sqlite") Sqlite }, "postgres" => -> { require_relative("postgres") Postgres }, "postgresql" => -> { require_relative("postgres") Postgres }, "mysql" => -> { require_relative("mysql") Mysql } }.freeze
Instance Attribute Summary collapse
- #app ⇒ Object readonly private
- #config ⇒ Object readonly private
Class Method Summary collapse
- .[](app) ⇒ Object private
Instance Method Summary collapse
- #applied_migrations ⇒ Object private
- #connection ⇒ Object private
- #create_command ⇒ Object private
- #drop_command ⇒ Object private
- #dump_command ⇒ Object private
- #gateway ⇒ Object private
-
#initialize(app:, config:) ⇒ Database
constructor
private
A new instance of Database.
- #load_command ⇒ Object private
- #migrator ⇒ Object private
- #name ⇒ Object private
- #rom_config ⇒ Object private
- #root_path ⇒ Object private
- #run_migrations(**options) ⇒ Object private
Constructor Details
#initialize(app:, config:) ⇒ Database
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Database.
60 61 62 63 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 60 def initialize(app:, config:) @app = app @config = config end |
Instance Attribute Details
#app ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 14 def app @app end |
#config ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 17 def config @config end |
Class Method Details
.[](app) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 40 def self.[](app) database_url = if app.key?(:settings) && app[:settings].respond_to?(:database_url) app[:settings].database_url else ENV.fetch("DATABASE_URL") end config = DatabaseConfig.new(database_url) resolver = SCHEME_MAP.fetch(config.db_type) do raise "#{config.db_type} is not a supported db scheme" end klass = resolver.() klass.new(app: app, config: config) end |
Instance Method Details
#applied_migrations ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
132 133 134 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 132 def applied_migrations sequel_migrator.applied_migrations end |
#connection ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 110 def connection gateway.connection end |
#create_command ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 66 def create_command raise Hanami::CLI::NotImplementedError end |
#drop_command ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 71 def drop_command raise Hanami::CLI::NotImplementedError end |
#dump_command ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
76 77 78 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 76 def dump_command raise Hanami::CLI::NotImplementedError end |
#gateway ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 105 def gateway rom_config.gateways[:default] end |
#load_command ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 81 def load_command raise Hanami::CLI::NotImplementedError end |
#migrator ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 126 127 128 129 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 123 def migrator @migrator ||= begin require "rom/sql" ROM::SQL::Migration::Migrator.new(connection, path: File.join(root_path, "db/migrate")) end end |
#name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
100 101 102 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 100 def name config.db_name end |
#rom_config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 94 95 96 97 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 91 def rom_config @rom_config ||= begin app.prepare(:persistence) app.container["persistence.config"] end end |
#root_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 86 def root_path app.root end |
#run_migrations(**options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
115 116 117 118 119 120 |
# File 'lib/hanami/cli/commands/app/db/utils/database.rb', line 115 def run_migrations(**) require "rom/sql" ROM::SQL.with_gateway(gateway) do migrator.run() end end |