48 lines
926 B
Ruby
48 lines
926 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
require 'sequel'
|
||
|
|
||
|
class ProtohandlerDBManager
|
||
|
attr_reader :db
|
||
|
|
||
|
def initialize
|
||
|
setup_database
|
||
|
end
|
||
|
|
||
|
def setup_database
|
||
|
@db = Sequel.sqlite # In-memory database
|
||
|
|
||
|
create_processors_table unless table_exists?(:processors)
|
||
|
create_orchestrators_table unless table_exists?(:orchestrators)
|
||
|
create_blacklist_table unless table_exists?(:blacklist)
|
||
|
end
|
||
|
|
||
|
def table_exists?(table_name)
|
||
|
@db.table_exists?(table_name)
|
||
|
end
|
||
|
|
||
|
def create_processors_table
|
||
|
@db.create_table :processors do
|
||
|
primary_key :proto_handler_id
|
||
|
String :uuid
|
||
|
String :domain
|
||
|
Integer :port
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def create_orchestrators_table
|
||
|
@db.create_table :orchestrators do
|
||
|
primary_key :id
|
||
|
String :domain
|
||
|
Integer :port
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def create_blacklist_table
|
||
|
@db.create_table :blacklist do
|
||
|
primary_key :id
|
||
|
String :uuid
|
||
|
end
|
||
|
end
|
||
|
end
|