Class: Proxy::ContainerGateway::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_container_gateway/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_string, prior_sqlite_db_path = nil) ⇒ Database

Returns a new instance of Database.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/smart_proxy_container_gateway/database.rb', line 7

def initialize(connection_string, prior_sqlite_db_path = nil)
  @connection = Sequel.connect(connection_string)
  if connection_string.start_with?('sqlite://')
    @connection.run("PRAGMA foreign_keys = ON;")
    @connection.run("PRAGMA journal_mode = wal;")
  elsif prior_sqlite_db_path && File.exist?(prior_sqlite_db_path) &&
        (!@connection.table_exists?(:repositories) || @connection[:repositories].count.zero?)
    migrate_to_postgres(Sequel.sqlite(prior_sqlite_db_path), @connection)
    File.delete(prior_sqlite_db_path)
  end
  migrate
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/smart_proxy_container_gateway/database.rb', line 5

def connection
  @connection
end