Class: SequelRails::Storage::Postgres
- Inherits:
-
Abstract
- Object
- Abstract
- SequelRails::Storage::Postgres
show all
- Defined in:
- lib/sequel_rails/storage/postgres.rb
Instance Attribute Summary
Attributes inherited from Abstract
#config
Instance Method Summary
collapse
Methods inherited from Abstract
#charset, #collation, #create, #database, #drop, #dump, #host, #initialize, #load, #owner, #password, #port, #username
Instance Method Details
#_create ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/sequel_rails/storage/postgres.rb', line 5
def _create
with_pgpassword do
commands = ["createdb"]
add_connection_settings commands
add_option commands, "--maintenance-db", maintenance_db
add_option commands, "--encoding", encoding
add_option commands, "--locale", locale
add_option commands, "--lc-collate", collation
add_option commands, "--lc-ctype", ctype
add_option commands, "--template", template
add_option commands, "--tablespace", tablespace
add_option commands, "--owner", owner
commands << database
safe_exec commands
end
end
|
#_drop ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/sequel_rails/storage/postgres.rb', line 22
def _drop
with_pgpassword do
commands = ["dropdb"]
add_connection_settings commands
commands << database
safe_exec commands
end
end
|
#_dump(filename) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/sequel_rails/storage/postgres.rb', line 31
def _dump(filename)
with_pgpassword do
commands = ["pg_dump"]
add_connection_settings commands
add_flag commands, "-i"
add_flag commands, "-s"
add_flag commands, "-x"
add_flag commands, "-O"
add_option commands, "--file", filename
commands << database
safe_exec commands
end
end
|
#_load(filename) ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'lib/sequel_rails/storage/postgres.rb', line 45
def _load(filename)
with_pgpassword do
commands = ["psql"]
add_connection_settings commands
add_option commands, "--file", filename
commands << database
safe_exec commands
end
end
|
#close_connections ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/sequel_rails/storage/postgres.rb', line 55
def close_connections
begin
db = ::Sequel.connect(config)
pid_column = db.server_version < 90200 ? "procpid" : "pid"
db.execute " SELECT COUNT(pg_terminate_backend(\#{pid_column}))\n FROM pg_stat_activity\n WHERE datname = '\#{database}';\n SQL\n rescue => _\n # Will raise an error as it kills existing process running this\n # command. Seems to be only way to ensure *all* test connections\n # are closed\n end\nend\n".gsub(/^\s{12}/,'')
|
#ctype ⇒ Object
84
85
86
|
# File 'lib/sequel_rails/storage/postgres.rb', line 84
def ctype
@ctype ||= config["ctype"] || ""
end
|
#encoding ⇒ Object
72
73
74
|
# File 'lib/sequel_rails/storage/postgres.rb', line 72
def encoding
@encoding ||= config["encoding"] || charset
end
|
#locale ⇒ Object
76
77
78
|
# File 'lib/sequel_rails/storage/postgres.rb', line 76
def locale
@locale ||= config["locale"] || ""
end
|
#maintenance_db ⇒ Object
92
93
94
|
# File 'lib/sequel_rails/storage/postgres.rb', line 92
def maintenance_db
@maintenance_db ||= config["maintenance_db"] || ""
end
|
#tablespace ⇒ Object
88
89
90
|
# File 'lib/sequel_rails/storage/postgres.rb', line 88
def tablespace
@tablespace ||= config["tablespace"] || ""
end
|
#template ⇒ Object
80
81
82
|
# File 'lib/sequel_rails/storage/postgres.rb', line 80
def template
@template ||= config["template"] || ""
end
|