-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip schema dumper when extension is not available
- Loading branch information
Showing
8 changed files
with
124 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
module Timescaledb | ||
class ConnectionNotEstablishedError < StandardError; end | ||
|
||
# @param [String] config The postgres connection string. | ||
module_function | ||
|
||
# @param [String] config with the postgres connection string. | ||
def establish_connection(config) | ||
Connection.instance.config = config | ||
end | ||
module_function :establish_connection | ||
|
||
# @param [PG::Connection] to use it directly from a raw connection | ||
def use_connection conn | ||
Connection.instance.use_connection conn | ||
end | ||
|
||
def connection | ||
raise ConnectionNotEstablishedError.new unless Connection.instance.connected? | ||
|
||
Connection.instance | ||
end | ||
module_function :connection | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Timescaledb | ||
|
||
# Provides metadata around the extension in the database | ||
module Extension | ||
module_function | ||
# @return String version of the timescaledb extension | ||
def version | ||
@version ||= Timescaledb.connection.query_first(<<~SQL)&.version | ||
SELECT extversion as version | ||
FROM pg_extension | ||
WHERE extname = 'timescaledb' | ||
SQL | ||
end | ||
|
||
def installed? | ||
version.present? | ||
end | ||
|
||
def update! | ||
Timescaledb.connection.execute('ALTER EXTENSION timescaledb UPDATE') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
RSpec.describe Timescaledb do | ||
describe '.establish_connection' do | ||
it 'returns a PG::Connection object' do | ||
expect do | ||
Timescaledb.establish_connection(ENV['PG_URI_TEST']) | ||
end.to_not raise_error | ||
end | ||
end | ||
|
||
describe ::Timescaledb::Connection do | ||
subject(:connection) { Timescaledb::Connection.instance } | ||
|
||
it 'returns a Connection object' do | ||
is_expected.to be_a(Timescaledb::Connection) | ||
end | ||
|
||
it 'has fast access to the connection' do | ||
expect(connection.send(:connection)).to be_a(PG::Connection) | ||
end | ||
|
||
describe '#connected?' do | ||
it { expect(connection.connected?).to be_truthy } | ||
end | ||
|
||
describe '#query_first' do | ||
let(:sql) { "select 1 as one" } | ||
subject(:result) { connection.query_first(sql) } | ||
|
||
it { expect(result).to be_a(OpenStruct) } | ||
end | ||
|
||
describe '#query' do | ||
let(:sql) { "select 1 as one" } | ||
subject(:result) { connection.query(sql) } | ||
|
||
it { expect(result).to eq([OpenStruct.new({"one" => "1"})]) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters