Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/mysql_framework/scripts/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def index_exists?(client, table_name, index_name)
result.count >= 1
end

def user_exists?(client, user, host)
result = client.query(<<~SQL)
SELECT user FROM mysql.user WHERE user = '#{user}' AND host = '#{host}';
SQL

result.count == 1
end

def index_up_to_date?(client, table_name, index_name, columns)
result = client.query(<<~SQL)
SHOW INDEX FROM #{table_name} WHERE Key_name="#{index_name}";
Expand Down
2 changes: 1 addition & 1 deletion lib/mysql_framework/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module MysqlFramework
VERSION = '2.1.9'
VERSION = '2.2.0'
end
12 changes: 12 additions & 0 deletions spec/lib/mysql_framework/scripts/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@
end
end

describe '#user_exists?' do
it 'returns true when user exists' do
expect(client).to receive(:query).and_return(['result'])
expect(subject.user_exists?(client,'foo', 'localhost')).to eq(true)
end

it 'returns false when user does not exist' do
expect(client).to receive(:query).and_return([])
expect(subject.user_exists?(client,'foo', 'localhost')).to eq(false)
end
end

describe '#index_up_to_date?' do
before do
expect(client).to receive(:query).and_return(
Expand Down