Class: Nvoi::External::Database::Sqlite
- Defined in:
- lib/nvoi/external/database/sqlite.rb
Overview
SQLite provider using direct SSH file access on hostPath volume
Instance Method Summary collapse
- #app_env(creds, host: nil) ⇒ Object
- #build_url(creds, host: nil) ⇒ Object
- #container_env(_creds) ⇒ Object
- #create_database(_ssh, _opts) ⇒ Object
- #default_port ⇒ Object
- #dump(ssh, opts) ⇒ Object
- #needs_container? ⇒ Boolean
- #parse_url(url) ⇒ Object
- #restore(ssh, data, opts) ⇒ Object
Methods inherited from Provider
Instance Method Details
#app_env(creds, host: nil) ⇒ Object
32 33 34 35 36 |
# File 'lib/nvoi/external/database/sqlite.rb', line 32 def app_env(creds, host: nil) { "DATABASE_URL" => build_url(creds) } end |
#build_url(creds, host: nil) ⇒ Object
24 25 26 |
# File 'lib/nvoi/external/database/sqlite.rb', line 24 def build_url(creds, host: nil) "sqlite://#{creds.path}" end |
#container_env(_creds) ⇒ Object
28 29 30 |
# File 'lib/nvoi/external/database/sqlite.rb', line 28 def container_env(_creds) {} end |
#create_database(_ssh, _opts) ⇒ Object
66 67 68 |
# File 'lib/nvoi/external/database/sqlite.rb', line 66 def create_database(_ssh, _opts) # No-op for SQLite end |
#default_port ⇒ Object
8 9 10 |
# File 'lib/nvoi/external/database/sqlite.rb', line 8 def default_port nil end |
#dump(ssh, opts) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/nvoi/external/database/sqlite.rb', line 38 def dump(ssh, opts) db_path = opts.host_path raise Errors::DatabaseError.new("dump", "host_path required for SQLite dump") unless db_path ssh.execute("sqlite3 #{db_path} .dump") rescue Errors::SshCommandError => e raise Errors::DatabaseError.new("dump", "sqlite3 dump failed: #{e.message}") end |
#needs_container? ⇒ Boolean
12 13 14 |
# File 'lib/nvoi/external/database/sqlite.rb', line 12 def needs_container? false end |
#parse_url(url) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/nvoi/external/database/sqlite.rb', line 16 def parse_url(url) path = url.sub(%r{^sqlite3?:///?}, "") Types::Credentials.new( path:, database: File.basename(path) ) end |
#restore(ssh, data, opts) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nvoi/external/database/sqlite.rb', line 47 def restore(ssh, data, opts) db_path = opts.host_path raise Errors::DatabaseError.new("restore", "host_path required for SQLite restore") unless db_path dir = File.dirname(db_path) new_db_path = "#{dir}/#{opts.database}.sqlite3" temp_file = "/tmp/restore_#{opts.database}.sql" write_cmd = "cat > #{temp_file} << 'SQLDUMP'\n#{data}\nSQLDUMP" ssh.execute(write_cmd) ssh.execute("sqlite3 #{new_db_path} < #{temp_file}") ssh.execute_ignore_errors("rm -f #{temp_file}") new_db_path rescue Errors::SshCommandError => e raise Errors::DatabaseError.new("restore", "sqlite3 restore failed: #{e.message}") end |