Class: DatabasusRuby::Databases

Inherits:
Object
  • Object
show all
Includes:
Endpoint
Defined in:
lib/databasus_ruby/objects/databases.rb,
sig/databasus_ruby.rbs

Overview

Databases under backup.

client.databases.list(workspace_id: id)
client.databases.create(name: "primary", type: "POSTGRES_LOGICAL",
                      workspaceId: id, postgresqlLogical: { ... })

The create/update bodies are the full databases.Database payload, whose engine-specific half lives under one of postgresqlLogical, postgresqlPhysical, mysql, mariadb or mongodb.

Constant Summary collapse

TYPES =

Returns:

  • (Array[String])
%w[POSTGRES_LOGICAL POSTGRES_PHYSICAL MYSQL MARIADB MONGODB].freeze
HEALTH_STATUSES =

Returns:

  • (Array[String])
%w[AVAILABLE UNAVAILABLE].freeze

Instance Attribute Summary

Attributes included from Endpoint

#client

Instance Method Summary collapse

Methods included from Endpoint

#acknowledged, #build, #collection, #compact, #escape, #http_delete, #http_get, #http_post, #http_put, #initialize, #inspect, #object, #single_value, #with_default_workspace

Methods inherited from Object

#==, #[], #hash, #initialize, #inspect, #key?, #keys, #method_missing, #respond_to_missing?, #to_h

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DatabasusRuby::Object

Instance Method Details

#backup(id) ⇒ Object

Parameters:

  • id (String)

Returns:



93
94
95
# File 'lib/databasus_ruby/objects/databases.rb', line 93

def backup(id)
  client.backups.create(database_id: require_id(id))
end

#backups(id, **filters) ⇒ Collection

The backups of one database by id. A database returned by this endpoint answers the same two methods without the id — see Database.

client.databases.backups(database.id, status: "COMPLETED")
client.databases.backup(database.id)          # queue a run

#backups takes the same filters as Backups#list.

Parameters:

Returns:



89
90
91
# File 'lib/databasus_ruby/objects/databases.rb', line 89

def backups(id, **filters)
  client.backups.list(database_id: require_id(id), **filters)
end

#copy(id) ⇒ Database

POST /databases/id/copy

Parameters:

  • id (String)

Returns:



48
49
50
# File 'lib/databasus_ruby/objects/databases.rb', line 48

def copy(id)
  object(http_post("databases/#{escape(id)}/copy"), as: Database)
end

#create(**attributes) ⇒ Database

POST /databases/create

Parameters:

Returns:



33
34
35
# File 'lib/databasus_ruby/objects/databases.rb', line 33

def create(**attributes)
  object(http_post("databases/create", with_default_workspace(attributes)), as: Database)
end

#create_readonly_user(**attributes) ⇒ Object

POST /databases/create-readonly-user -> { username, password }

Parameters:

Returns:



64
65
66
# File 'lib/databasus_ruby/objects/databases.rb', line 64

def create_readonly_user(**attributes)
  object(http_post("databases/create-readonly-user", attributes))
end

#create_replication_only_user(**attributes) ⇒ Object

POST /databases/create-replication-only-user (PostgreSQL physical only)

Parameters:

Returns:



69
70
71
# File 'lib/databasus_ruby/objects/databases.rb', line 69

def create_replication_only_user(**attributes)
  object(http_post("databases/create-replication-only-user", attributes))
end

#delete(id) ⇒ Boolean

DELETE /databases/id

Parameters:

  • id (String)

Returns:

  • (Boolean)


43
44
45
# File 'lib/databasus_ruby/objects/databases.rb', line 43

def delete(id)
  acknowledged(http_delete("databases/#{escape(id)}"))
end

#get(id) ⇒ Database Also known as: find

GET /databases/id

Parameters:

  • id (String)

Returns:



27
28
29
# File 'lib/databasus_ruby/objects/databases.rb', line 27

def get(id)
  object(http_get("databases/#{escape(id)}"), as: Database)
end

#list(workspace_id: nil) ⇒ Collection Also known as: all

GET /databases

Parameters:

  • workspace_id: (String, nil) (defaults to: nil)

Returns:



20
21
22
23
# File 'lib/databasus_ruby/objects/databases.rb', line 20

def list(workspace_id: nil)
  collection(http_get("databases", { workspace_id: workspace_id || client.workspace_id! }),
             key: "databases", as: Database)
end

#notifier_databases_count(notifier_id) ⇒ Object

GET /databases/notifier/id/databases-count

Parameters:

  • notifier_id (String)

Returns:



98
99
100
# File 'lib/databasus_ruby/objects/databases.rb', line 98

def notifier_databases_count(notifier_id)
  single_value(http_get("databases/notifier/#{escape(notifier_id)}/databases-count"))
end

#notifier_using?(notifier_id) ⇒ Boolean

GET /databases/notifier/id/is-using

Parameters:

  • notifier_id (String)

Returns:

  • (Boolean)


103
104
105
# File 'lib/databasus_ruby/objects/databases.rb', line 103

def notifier_using?(notifier_id)
  single_value(http_get("databases/notifier/#{escape(notifier_id)}/is-using")) == true
end

#readonly(**attributes) ⇒ Object

POST /databases/is-readonly -> { isReadOnly, privileges }

Parameters:

Returns:



74
75
76
# File 'lib/databasus_ruby/objects/databases.rb', line 74

def readonly(**attributes)
  object(http_post("databases/is-readonly", attributes))
end

#readonly?(**attributes) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


78
79
80
# File 'lib/databasus_ruby/objects/databases.rb', line 78

def readonly?(**attributes)
  readonly(**attributes).isReadOnly == true
end

#test_connection(id) ⇒ Boolean

POST /databases/id/test-connection — true when the database answers.

Parameters:

  • id (String)

Returns:

  • (Boolean)


53
54
55
# File 'lib/databasus_ruby/objects/databases.rb', line 53

def test_connection(id)
  acknowledged(http_post("databases/#{escape(id)}/test-connection"))
end

#test_connection_direct(**attributes) ⇒ Boolean

POST /databases/test-connection-direct — tests a payload that has not been saved yet.

Parameters:

Returns:

  • (Boolean)


59
60
61
# File 'lib/databasus_ruby/objects/databases.rb', line 59

def test_connection_direct(**attributes)
  acknowledged(http_post("databases/test-connection-direct", attributes))
end

#update(**attributes) ⇒ Database

POST /databases/update — the id travels in the body, not the path.

Parameters:

Returns:



38
39
40
# File 'lib/databasus_ruby/objects/databases.rb', line 38

def update(**attributes)
  object(http_post("databases/update", attributes), as: Database)
end