Module: JunglePath::DBAccess::Meta::DB
- Defined in:
- lib/jungle_path/db_access/meta/db.rb
Class Method Summary collapse
- .create(config) ⇒ Object
- .drop!(config) ⇒ Object
- .drop?(config) ⇒ Boolean
-
.exists?(config) ⇒ Boolean
todo: fix to also work for ms sql server.
- .kill_connections!(config) ⇒ Object
- .rename(config_from, to_name) ⇒ Object
- .rename?(config_from, to_name) ⇒ Boolean
- .reset!(config) ⇒ Object
Class Method Details
.create(config) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/jungle_path/db_access/meta/db.rb', line 8 def self.create(config) puts "JunglePath::DBAccess::Meta::DB.create: #{config.name}." db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config) sql = "create database #{config.name}" db.run sql end |
.drop!(config) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/jungle_path/db_access/meta/db.rb', line 15 def self.drop!(config) puts "JunglePath::DBAccess::Meta::DB.drop: #{config.name}." kill_connections! config db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config) sql = "drop database #{config.name}" db.run sql end |
.drop?(config) ⇒ Boolean
23 24 25 26 27 |
# File 'lib/jungle_path/db_access/meta/db.rb', line 23 def self.drop?(config) if exists?(config) drop! config end end |
.exists?(config) ⇒ Boolean
todo: fix to also work for ms sql server.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jungle_path/db_access/meta/db.rb', line 34 def self.exists?(config) # todo: fix to also work for ms sql server. puts "JunglePath::DBAccess::Meta::DB.exists? #{config.name}." exists = false db = JunglePath::DBAccess::IO.connection_from_config_unknown_database(config) sql = sql_query_db_existence(config) db.fetch(sql) do |row| exists = true end exists end |
.kill_connections!(config) ⇒ Object
59 60 61 62 63 |
# File 'lib/jungle_path/db_access/meta/db.rb', line 59 def self.kill_connections!(config) db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config) sql = "select pg_terminate_backend(pid) from pg_stat_activity where datname = '#{config.name}'" db.run sql end |
.rename(config_from, to_name) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/jungle_path/db_access/meta/db.rb', line 45 def self.rename(config_from, to_name) puts "JunglePath::DBAccess::Meta::DB.rename: #{config_from.name} to #{to_name}." kill_connections! config_from db = JunglePath::DBAccess::IO.connection_from_config_use_postgres_db(config_from) sql = "alter database #{config_from.name} rename to #{to_name}" db.run sql end |
.rename?(config_from, to_name) ⇒ Boolean
53 54 55 56 57 |
# File 'lib/jungle_path/db_access/meta/db.rb', line 53 def self.rename?(config_from, to_name) if exists?(config_from) rename config_from, to_name end end |
.reset!(config) ⇒ Object
29 30 31 32 |
# File 'lib/jungle_path/db_access/meta/db.rb', line 29 def self.reset!(config) drop? config create config end |