Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #353 from Charcoal-SE/sql-explorer
SQL data exploder
- Loading branch information
Showing
9 changed files
with
181 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# see https://github.com/ankane/blazer for more info | ||
|
||
data_sources: | ||
main: | ||
url: mysql2://metasmoke_blazer:zFpc8tw7CdAuXizX@localhost:3306/metasmoke_dev | ||
timeout: 10 | ||
cache: | ||
mode: slow | ||
expires_in: 60 | ||
slow_threshold: 5 | ||
|
||
smart_variables: | ||
reason_id: "SELECT id, reason_name FROM p_reasons ORDER BY id ASC" | ||
user_id: "SELECT id, username FROM p_users ORDER BY id ASC" | ||
api_key_id: "SELECT id, app_name FROM p_api_keys ORDER BY id ASC" | ||
site_id: "SELECT id, site_name FROM p_sites ORDER BY id ASC" | ||
|
||
linked_columns: | ||
# user_id: "/admin/users/{value}" | ||
|
||
smart_columns: | ||
reason_id: "SELECT id, reason_name FROM p_reasons WHERE id IN {value}" | ||
user_id: "SELECT id, username FROM p_users WHERE id IN {value}" | ||
api_key_id: "SELECT id, app_name FROM p_api_keys WHERE id IN {value}" | ||
site_id: "SELECT id, site_name FROM p_sites WHERE id IN {value}" | ||
|
||
audit: true |
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class RunCreateViews < ActiveRecord::Migration[5.2] | ||
def change | ||
success = system 'rails runner db/scripts/create_views.rb' | ||
raise StandardError, 'View script had non-zero exit code' unless success | ||
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,47 @@ | ||
# frozen_string_literal: true | ||
|
||
class InstallBlazer < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :blazer_queries do |t| | ||
t.references :creator | ||
t.string :name | ||
t.text :description | ||
t.text :statement | ||
t.string :data_source | ||
t.timestamps null: false | ||
end | ||
|
||
create_table :blazer_audits do |t| | ||
t.references :user | ||
t.references :query | ||
t.text :statement | ||
t.string :data_source | ||
t.timestamp :created_at | ||
end | ||
|
||
create_table :blazer_dashboards do |t| | ||
t.references :creator | ||
t.text :name | ||
t.timestamps null: false | ||
end | ||
|
||
create_table :blazer_dashboard_queries do |t| | ||
t.references :dashboard | ||
t.references :query | ||
t.integer :position | ||
t.timestamps null: false | ||
end | ||
|
||
create_table :blazer_checks do |t| | ||
t.references :creator | ||
t.references :query | ||
t.string :state | ||
t.string :schedule | ||
t.text :emails | ||
t.string :check_type | ||
t.text :message | ||
t.timestamp :last_run_at | ||
t.timestamps null: false | ||
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
EXCLUDE_TABLES = %w[ar_internal_metadata flags github_tokens schema_migrations].freeze | ||
EXCLUDE_COLUMNS = { | ||
'api_keys' => ['key'], | ||
'api_tokens' => %w[code token], | ||
'audits' => ['remote_address'], | ||
'smoke_detectors' => ['access_token'], | ||
'users' => %w[email encrypted_password reset_password_token encrypted_api_token two_factor_token enabled_2fa salt iv] | ||
}.freeze | ||
|
||
tables = ActiveRecord::Base.connection.tables | ||
queries = [] | ||
|
||
queries << "CREATE USER IF NOT EXISTS metasmoke_blazer@localhost IDENTIFIED BY 'zFpc8tw7CdAuXizX';" | ||
|
||
tables.each do |t| | ||
next if EXCLUDE_TABLES.include? t | ||
columns = ActiveRecord::Base.connection.columns(t).map(&:name) - (EXCLUDE_COLUMNS[t] || []) | ||
queries << "CREATE VIEW p_#{t} AS SELECT #{columns.join(', ')} FROM #{t};" | ||
queries << "GRANT SELECT ON #{ActiveRecord::Base.connection.current_database}.p_#{t} TO metasmoke_blazer@localhost;" | ||
end | ||
|
||
queries.each do |q| | ||
ActiveRecord::Base.connection.execute q | ||
end |