Skip to content

Commit

Permalink
user_exists? method added.
Browse files Browse the repository at this point in the history
  • Loading branch information
mob1970 committed Jun 19, 2024
1 parent c2cff39 commit 679aabd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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

0 comments on commit 679aabd

Please sign in to comment.