Module: Pakyow::Data::Adapters::Sql::Migrator::AdapterMethods::Postgres Private

Defined in:
lib/pakyow/data/adapters/sql/migrator/adapter_methods.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.globalize_connection_opts!(connection_opts) ⇒ 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.



62
63
64
65
# File 'lib/pakyow/data/adapters/sql/migrator/adapter_methods.rb', line 62

def self.globalize_connection_opts!(connection_opts)
  connection_opts[:initial] = Sql.build_opts(path: connection_opts[:path])
  connection_opts[:path] = "template1"
end

Instance Method Details

#create!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.



38
39
40
41
42
# File 'lib/pakyow/data/adapters/sql/migrator/adapter_methods.rb', line 38

def create!
  handle_error do
    @connection.adapter.connection.run("CREATE DATABASE \"#{database}\"")
  end
end

#drop!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.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pakyow/data/adapters/sql/migrator/adapter_methods.rb', line 44

def drop!
  handle_error do
    @connection.adapter.connection.run <<~SQL
      SELECT
      pg_terminate_backend(pid)
      FROM
      pg_stat_activity
      WHERE
      -- don't kill my own connection!
      pid <> pg_backend_pid()
      -- don't kill the connections to other databases
      AND datname = '#{@connection.opts[:path]}';
    SQL

    @connection.adapter.connection.run("DROP DATABASE \"#{database}\"")
  end
end