Class: Seira::Db::Create

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/seira/db/create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands

#gcloud, gcloud, kubectl, #kubectl

Constructor Details

#initialize(app:, action:, args:, context:) ⇒ Create

Returns a new instance of Create.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/seira/db/create.rb', line 11

def initialize(app:, action:, args:, context:)
  @app = app
  @action = action
  @args = args
  @context = context

  # We allow overriding the version, so you could specify a mysql version but much of the
  # below assumes postgres for now
  @version = 'POSTGRES_9_6'
  @cpu = 1 # Number of CPUs
  @memory = 4 # GB
  @storage = 10 # GB
  @replica_for = nil
  @make_highly_available = false

  @root_password = nil
  @proxyuser_password = nil
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/seira/db/create.rb', line 6

def action
  @action
end

#appObject (readonly)

Returns the value of attribute app.



6
7
8
# File 'lib/seira/db/create.rb', line 6

def app
  @app
end

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'lib/seira/db/create.rb', line 6

def args
  @args
end

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/seira/db/create.rb', line 6

def context
  @context
end

#cpuObject (readonly)

Returns the value of attribute cpu.



8
9
10
# File 'lib/seira/db/create.rb', line 8

def cpu
  @cpu
end

#make_highly_availableObject (readonly)

Returns the value of attribute make_highly_available.



8
9
10
# File 'lib/seira/db/create.rb', line 8

def make_highly_available
  @make_highly_available
end

#memoryObject (readonly)

Returns the value of attribute memory.



8
9
10
# File 'lib/seira/db/create.rb', line 8

def memory
  @memory
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/seira/db/create.rb', line 8

def name
  @name
end

#proxyuser_passwordObject (readonly)

Returns the value of attribute proxyuser_password.



9
10
11
# File 'lib/seira/db/create.rb', line 9

def proxyuser_password
  @proxyuser_password
end

#replica_forObject (readonly)

Returns the value of attribute replica_for.



8
9
10
# File 'lib/seira/db/create.rb', line 8

def replica_for
  @replica_for
end

#root_passwordObject (readonly)

Returns the value of attribute root_password.



9
10
11
# File 'lib/seira/db/create.rb', line 9

def root_password
  @root_password
end

#storageObject (readonly)

Returns the value of attribute storage.



8
9
10
# File 'lib/seira/db/create.rb', line 8

def storage
  @storage
end

#versionObject (readonly)

Returns the value of attribute version.



8
9
10
# File 'lib/seira/db/create.rb', line 8

def version
  @version
end

Instance Method Details

#run(existing_instances) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/seira/db/create.rb', line 30

def run(existing_instances)
  @name = "#{app}-#{Seira::Random.unique_name(existing_instances)}"

  run_create_command

  if replica_for.nil?
    update_root_password
    create_proxy_user
  end

  set_secrets
  write_pgbouncer_yaml

  puts "To use this database, deploy the pgbouncer config file that was created and use the ENV that was set."
  puts "To make this database the primary, promote it using the CLI and update the DATABASE_URL."
end