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.1.3' |
27 VERSION = '0.2.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. |
38 else |
38 else |
39 Pathname.new( __FILE__ ).dirname.parent.parent.parent + |
39 Pathname.new( __FILE__ ).dirname.parent.parent.parent + |
40 'data' + 'thingfish-metastore-pggraph' |
40 'data' + 'thingfish-metastore-pggraph' |
41 end |
41 end |
42 |
42 |
43 # The default config values |
|
44 DEFAULT_CONFIG = { |
|
45 uri: 'postgres:/thingfish', |
|
46 slow_query_seconds: 0.01, |
|
47 } |
|
48 |
|
49 |
|
50 # Loggability API -- use a separate logger |
|
51 log_as :thingfish_metastore_pggraph |
43 log_as :thingfish_metastore_pggraph |
52 |
44 |
53 # Configurability API -- load the `pg_metastore` |
45 # Configurability API -- load the `pg_metastore` |
54 config_key :pggraph_metastore |
46 configurability 'thingfish.pggraph_metastore' do |
55 |
47 |
56 ## |
48 # The Sequel::Database that's used to access the metastore tables |
57 # The URI of the database to use for the metastore |
49 setting :uri, default: 'postgres:/thingfish' |
58 singleton_attr_accessor :uri |
50 |
59 |
51 # The number of seconds to consider a "slow" query |
60 ## |
52 setting :slow_query_seconds, default: 0.01 |
|
53 end |
|
54 |
61 # The Sequel::Database that's used to access the metastore tables |
55 # The Sequel::Database that's used to access the metastore tables |
62 singleton_attr_accessor :db |
56 singleton_attr_accessor :db |
63 |
|
64 ## |
|
65 # The number of seconds to consider a "slow" query |
|
66 singleton_attr_accessor :slow_query_seconds |
|
67 |
57 |
68 |
58 |
69 ### Set up the metastore database and migrate to the latest version. |
59 ### Set up the metastore database and migrate to the latest version. |
70 def self::setup_database |
60 def self::setup_database |
71 Sequel.extension :pg_json_ops |
61 Sequel.extension :pg_json_ops |
102 |
92 |
103 |
93 |
104 ### Configurability API -- set up the metastore with the `pg_metastore` section of |
94 ### Configurability API -- set up the metastore with the `pg_metastore` section of |
105 ### the config file. |
95 ### the config file. |
106 def self::configure( config=nil ) |
96 def self::configure( config=nil ) |
107 config = self.defaults.merge( config || {} ) |
97 super |
108 |
98 self.setup_database if self.uri |
109 self.uri = config[:uri] |
|
110 self.slow_query_seconds = config[:slow_query_seconds] |
|
111 |
|
112 self.setup_database |
|
113 end |
99 end |
114 |
100 |
115 |
101 |
116 ### Set up the metastore. |
102 ### Set up the metastore. |
117 def initialize( * ) # :notnew: |
103 def initialize( * ) # :notnew: |