42 lines
No EOL
744 B
Ruby
42 lines
No EOL
744 B
Ruby
|
|
|
|
module Timeseries
|
|
module Hoarder
|
|
class Table
|
|
def initialize(db, table_name, table_schema = "public")
|
|
@table_name = table_name
|
|
@table_schema = table_schema
|
|
|
|
@db = db
|
|
@pg = @db.pg
|
|
|
|
@created = false
|
|
|
|
ensure_table_exists
|
|
end
|
|
|
|
def ensure_table_exists
|
|
return if @created
|
|
|
|
@pg.transaction do
|
|
@pg.exec("SELECT pg_advisory_lock(0)")
|
|
|
|
r = @pg.exec_params("SELECT 1 FROM information_schema.tables WHERE table_name = $1 AND table_schema = $2", [@table_name, @schema_name])
|
|
|
|
if r.num_tuples >= 1
|
|
@created = true
|
|
return
|
|
end
|
|
|
|
table_creation
|
|
|
|
@created = true
|
|
end
|
|
end
|
|
|
|
def table_creation
|
|
raise "No table creation string method provided!"
|
|
end
|
|
end
|
|
end
|
|
end |