lib/thingfish/metastore/pggraph.rb
changeset 13 686fbfe638bd
parent 11 b1f97f6063a3
child 15 38ea95105574
equal deleted inserted replaced
12:2f9a295bdba7 13:686fbfe638bd
    22 	# Load Sequel extensions/plugins
    22 	# Load Sequel extensions/plugins
    23 	Sequel.extension :migration
    23 	Sequel.extension :migration
    24 
    24 
    25 
    25 
    26 	# Package version
    26 	# Package version
    27 	VERSION = '0.2.0'
    27 	VERSION = '0.3.0'
    28 
    28 
    29 	# Version control revision
    29 	# Version control revision
    30 	REVISION = %q$Revision$
    30 	REVISION = %q$Revision$
    31 
    31 
    32 	# The data directory that contains migration files.
    32 	# The data directory that contains migration files.
    57 
    57 
    58 
    58 
    59 	### Set up the metastore database and migrate to the latest version.
    59 	### Set up the metastore database and migrate to the latest version.
    60 	def self::setup_database
    60 	def self::setup_database
    61 		Sequel.extension :pg_json_ops
    61 		Sequel.extension :pg_json_ops
       
    62 		Sequel.split_symbols = true
       
    63 		Sequel::Model.require_valid_table = false
    62 
    64 
    63 		self.db = Sequel.connect( self.uri )
    65 		self.db = Sequel.connect( self.uri )
    64 		self.db.logger = Loggability[ Thingfish::Metastore::PgGraph ]
    66 		self.db.logger = Loggability[ Thingfish::Metastore::PgGraph ]
    65 		self.db.extension :pg_streaming
    67 		self.db.extension :pg_streaming
    66 		self.db.stream_all_queries = true
    68 		self.db.stream_all_queries = true
    67 		self.db.optimize_model_load = true
       
    68 		self.db.sql_log_level = :debug
    69 		self.db.sql_log_level = :debug
    69 		self.db.extension( :pg_json )
    70 		self.db.extension( :pg_json )
    70 		self.db.log_warn_duration = self.slow_query_seconds
    71 		self.db.log_warn_duration = self.slow_query_seconds
    71 
    72 
    72 		# Ensure the database is current.
    73 		# Ensure the database is current.
   101 
   102 
   102 	### Set up the metastore.
   103 	### Set up the metastore.
   103 	def initialize( * ) # :notnew:
   104 	def initialize( * ) # :notnew:
   104 		require 'thingfish/metastore/pggraph/node'
   105 		require 'thingfish/metastore/pggraph/node'
   105 		require 'thingfish/metastore/pggraph/edge'
   106 		require 'thingfish/metastore/pggraph/edge'
   106 		Thingfish::Metastore::PgGraph::Node.db = self.class.db
   107 
   107 		Thingfish::Metastore::PgGraph::Edge.db = self.class.db
   108 		Thingfish::Metastore::PgGraph::Node.dataset = self.class.db[ :nodes ]
       
   109 		Thingfish::Metastore::PgGraph::Edge.dataset = self.class.db[ :edges ]
   108 		@model = Thingfish::Metastore::PgGraph::Node
   110 		@model = Thingfish::Metastore::PgGraph::Node
   109 	end
   111 	end
   110 
   112 
   111 
   113 
   112 	######
   114 	######