QueryWise 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +45 -0
- data/CLOUD_RUN_README.md +263 -0
- data/DOCKER_README.md +327 -0
- data/Dockerfile +69 -0
- data/Dockerfile.cloudrun +76 -0
- data/Dockerfile.dev +36 -0
- data/GEM_Gemfile +16 -0
- data/GEM_README.md +421 -0
- data/GEM_Rakefile +10 -0
- data/GEM_gitignore +137 -0
- data/LICENSE.txt +21 -0
- data/PUBLISHING_GUIDE.md +269 -0
- data/README.md +392 -0
- data/app/controllers/api/v1/analysis_controller.rb +340 -0
- data/app/controllers/api/v1/api_keys_controller.rb +83 -0
- data/app/controllers/api/v1/base_controller.rb +93 -0
- data/app/controllers/api/v1/health_controller.rb +86 -0
- data/app/controllers/application_controller.rb +2 -0
- data/app/controllers/concerns/.keep +0 -0
- data/app/jobs/application_job.rb +7 -0
- data/app/mailers/application_mailer.rb +4 -0
- data/app/models/app_profile.rb +18 -0
- data/app/models/application_record.rb +3 -0
- data/app/models/concerns/.keep +0 -0
- data/app/models/optimization_suggestion.rb +44 -0
- data/app/models/query_analysis.rb +47 -0
- data/app/models/query_pattern.rb +55 -0
- data/app/services/missing_index_detector_service.rb +244 -0
- data/app/services/n_plus_one_detector_service.rb +177 -0
- data/app/services/slow_query_analyzer_service.rb +225 -0
- data/app/services/sql_parser_service.rb +352 -0
- data/app/validators/query_data_validator.rb +96 -0
- data/app/views/layouts/mailer.html.erb +13 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/app.yaml +109 -0
- data/cloudbuild.yaml +47 -0
- data/config/application.rb +32 -0
- data/config/boot.rb +4 -0
- data/config/cable.yml +17 -0
- data/config/cache.yml +16 -0
- data/config/credentials.yml.enc +1 -0
- data/config/database.yml +69 -0
- data/config/deploy.yml +116 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +70 -0
- data/config/environments/production.rb +87 -0
- data/config/environments/test.rb +53 -0
- data/config/initializers/cors.rb +16 -0
- data/config/initializers/filter_parameter_logging.rb +8 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/locales/en.yml +31 -0
- data/config/master.key +1 -0
- data/config/puma.rb +41 -0
- data/config/puma_cloudrun.rb +48 -0
- data/config/queue.yml +18 -0
- data/config/recurring.yml +15 -0
- data/config/routes.rb +28 -0
- data/config/storage.yml +34 -0
- data/config.ru +6 -0
- data/db/cable_schema.rb +11 -0
- data/db/cache_schema.rb +14 -0
- data/db/migrate/20250818214709_create_app_profiles.rb +13 -0
- data/db/migrate/20250818214731_create_query_analyses.rb +22 -0
- data/db/migrate/20250818214740_create_query_patterns.rb +22 -0
- data/db/migrate/20250818214805_create_optimization_suggestions.rb +20 -0
- data/db/queue_schema.rb +129 -0
- data/db/schema.rb +79 -0
- data/db/seeds.rb +9 -0
- data/init.sql +9 -0
- data/lib/query_optimizer_client/client.rb +176 -0
- data/lib/query_optimizer_client/configuration.rb +43 -0
- data/lib/query_optimizer_client/generators/install_generator.rb +43 -0
- data/lib/query_optimizer_client/generators/templates/README +46 -0
- data/lib/query_optimizer_client/generators/templates/analysis_job.rb +84 -0
- data/lib/query_optimizer_client/generators/templates/initializer.rb +30 -0
- data/lib/query_optimizer_client/middleware.rb +126 -0
- data/lib/query_optimizer_client/railtie.rb +37 -0
- data/lib/query_optimizer_client/tasks.rake +228 -0
- data/lib/query_optimizer_client/version.rb +5 -0
- data/lib/query_optimizer_client.rb +48 -0
- data/lib/tasks/.keep +0 -0
- data/public/robots.txt +1 -0
- data/query_optimizer_client.gemspec +60 -0
- data/script/.keep +0 -0
- data/storage/.keep +0 -0
- data/storage/development.sqlite3 +0 -0
- data/storage/test.sqlite3 +0 -0
- data/vendor/.keep +0 -0
- metadata +265 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization and
|
2
|
+
# are automatically loaded by Rails. If you want to use locales other than
|
3
|
+
# English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t "hello"
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t("hello") %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more about the API, please read the Rails Internationalization guide
|
20
|
+
# at https://guides.rubyonrails.org/i18n.html.
|
21
|
+
#
|
22
|
+
# Be aware that YAML interprets the following case-insensitive strings as
|
23
|
+
# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
|
24
|
+
# must be quoted to be interpreted as strings. For example:
|
25
|
+
#
|
26
|
+
# en:
|
27
|
+
# "yes": yup
|
28
|
+
# enabled: "ON"
|
29
|
+
|
30
|
+
en:
|
31
|
+
hello: "Hello world"
|
data/config/master.key
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
739479735365bc824bffe836402b665a
|
data/config/puma.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# This configuration file will be evaluated by Puma. The top-level methods that
|
2
|
+
# are invoked here are part of Puma's configuration DSL. For more information
|
3
|
+
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
|
4
|
+
#
|
5
|
+
# Puma starts a configurable number of processes (workers) and each process
|
6
|
+
# serves each request in a thread from an internal thread pool.
|
7
|
+
#
|
8
|
+
# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You
|
9
|
+
# should only set this value when you want to run 2 or more workers. The
|
10
|
+
# default is already 1.
|
11
|
+
#
|
12
|
+
# The ideal number of threads per worker depends both on how much time the
|
13
|
+
# application spends waiting for IO operations and on how much you wish to
|
14
|
+
# prioritize throughput over latency.
|
15
|
+
#
|
16
|
+
# As a rule of thumb, increasing the number of threads will increase how much
|
17
|
+
# traffic a given process can handle (throughput), but due to CRuby's
|
18
|
+
# Global VM Lock (GVL) it has diminishing returns and will degrade the
|
19
|
+
# response time (latency) of the application.
|
20
|
+
#
|
21
|
+
# The default is set to 3 threads as it's deemed a decent compromise between
|
22
|
+
# throughput and latency for the average Rails application.
|
23
|
+
#
|
24
|
+
# Any libraries that use a connection pool or another resource pool should
|
25
|
+
# be configured to provide at least as many connections as the number of
|
26
|
+
# threads. This includes Active Record's `pool` parameter in `database.yml`.
|
27
|
+
threads_count = ENV.fetch("RAILS_MAX_THREADS", 3)
|
28
|
+
threads threads_count, threads_count
|
29
|
+
|
30
|
+
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
31
|
+
port ENV.fetch("PORT", 3000)
|
32
|
+
|
33
|
+
# Allow puma to be restarted by `bin/rails restart` command.
|
34
|
+
plugin :tmp_restart
|
35
|
+
|
36
|
+
# Run the Solid Queue supervisor inside of Puma for single-server deployments
|
37
|
+
plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"]
|
38
|
+
|
39
|
+
# Specify the PID file. Defaults to tmp/pids/server.pid in development.
|
40
|
+
# In other environments, only set the PID file if requested.
|
41
|
+
pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Puma configuration optimized for Google Cloud Run
|
2
|
+
|
3
|
+
# The environment Puma will run in
|
4
|
+
environment ENV.fetch("RAILS_ENV") { "production" }
|
5
|
+
|
6
|
+
# Port to listen on
|
7
|
+
port ENV.fetch("PORT") { 8080 }
|
8
|
+
|
9
|
+
# Number of worker processes
|
10
|
+
# Cloud Run containers have limited CPU, so we use threads instead of workers
|
11
|
+
workers 0
|
12
|
+
|
13
|
+
# Number of threads per worker
|
14
|
+
# Cloud Run containers typically have 1-2 vCPUs, so 5 threads is optimal
|
15
|
+
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
|
16
|
+
threads threads_count, threads_count
|
17
|
+
|
18
|
+
# Preload the application for better memory usage
|
19
|
+
preload_app!
|
20
|
+
|
21
|
+
# Allow puma to be restarted by `rails restart` command
|
22
|
+
plugin :tmp_restart
|
23
|
+
|
24
|
+
# Bind to all interfaces for Cloud Run
|
25
|
+
bind "tcp://0.0.0.0:#{ENV.fetch('PORT') { 8080 }}"
|
26
|
+
|
27
|
+
# Logging
|
28
|
+
stdout_redirect '/dev/stdout', '/dev/stderr', true
|
29
|
+
|
30
|
+
# Graceful shutdown for Cloud Run
|
31
|
+
on_worker_boot do
|
32
|
+
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Optimize for Cloud Run's request handling
|
36
|
+
before_fork do
|
37
|
+
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Cloud Run timeout handling
|
41
|
+
worker_timeout 30
|
42
|
+
worker_shutdown_timeout 8
|
43
|
+
|
44
|
+
# Memory and performance optimizations for Cloud Run
|
45
|
+
nakayoshi_fork if respond_to?(:nakayoshi_fork)
|
46
|
+
|
47
|
+
# Healthcheck endpoint
|
48
|
+
activate_control_app 'tcp://0.0.0.0:9293', { auth_token: 'health_check_token' }
|
data/config/queue.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
default: &default
|
2
|
+
dispatchers:
|
3
|
+
- polling_interval: 1
|
4
|
+
batch_size: 500
|
5
|
+
workers:
|
6
|
+
- queues: "*"
|
7
|
+
threads: 3
|
8
|
+
processes: <%= ENV.fetch("JOB_CONCURRENCY", 1) %>
|
9
|
+
polling_interval: 0.1
|
10
|
+
|
11
|
+
development:
|
12
|
+
<<: *default
|
13
|
+
|
14
|
+
test:
|
15
|
+
<<: *default
|
16
|
+
|
17
|
+
production:
|
18
|
+
<<: *default
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# examples:
|
2
|
+
# periodic_cleanup:
|
3
|
+
# class: CleanSoftDeletedRecordsJob
|
4
|
+
# queue: background
|
5
|
+
# args: [ 1000, { batch_size: 500 } ]
|
6
|
+
# schedule: every hour
|
7
|
+
# periodic_cleanup_with_command:
|
8
|
+
# command: "SoftDeletedRecord.due.delete_all"
|
9
|
+
# priority: 2
|
10
|
+
# schedule: at 5am every day
|
11
|
+
|
12
|
+
production:
|
13
|
+
clear_solid_queue_finished_jobs:
|
14
|
+
command: "SolidQueue::Job.clear_finished_in_batches(sleep_between_batches: 0.3)"
|
15
|
+
schedule: every hour at minute 12
|
data/config/routes.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
3
|
+
|
4
|
+
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
|
5
|
+
# Can be used by load balancers and uptime monitors to verify that the app is live.
|
6
|
+
get "up" => "rails/health#show", as: :rails_health_check
|
7
|
+
|
8
|
+
# API routes
|
9
|
+
namespace :api do
|
10
|
+
namespace :v1 do
|
11
|
+
# Query analysis endpoints
|
12
|
+
post 'analyze', to: 'analysis#analyze'
|
13
|
+
post 'analyze_ci', to: 'analysis#analyze_ci'
|
14
|
+
|
15
|
+
# API key management endpoints
|
16
|
+
post 'api_keys', to: 'api_keys#create'
|
17
|
+
get 'api_keys/current', to: 'api_keys#show'
|
18
|
+
post 'api_keys/regenerate', to: 'api_keys#regenerate'
|
19
|
+
delete 'api_keys/current', to: 'api_keys#destroy'
|
20
|
+
|
21
|
+
# Health check endpoint
|
22
|
+
get 'health', to: 'health#show'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Defines the root path route ("/")
|
27
|
+
# root "posts#index"
|
28
|
+
end
|
data/config/storage.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
test:
|
2
|
+
service: Disk
|
3
|
+
root: <%= Rails.root.join("tmp/storage") %>
|
4
|
+
|
5
|
+
local:
|
6
|
+
service: Disk
|
7
|
+
root: <%= Rails.root.join("storage") %>
|
8
|
+
|
9
|
+
# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
|
10
|
+
# amazon:
|
11
|
+
# service: S3
|
12
|
+
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
|
13
|
+
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
|
14
|
+
# region: us-east-1
|
15
|
+
# bucket: your_own_bucket-<%= Rails.env %>
|
16
|
+
|
17
|
+
# Remember not to checkin your GCS keyfile to a repository
|
18
|
+
# google:
|
19
|
+
# service: GCS
|
20
|
+
# project: your_project
|
21
|
+
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
|
22
|
+
# bucket: your_own_bucket-<%= Rails.env %>
|
23
|
+
|
24
|
+
# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
|
25
|
+
# microsoft:
|
26
|
+
# service: AzureStorage
|
27
|
+
# storage_account_name: your_account_name
|
28
|
+
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
|
29
|
+
# container: your_container_name-<%= Rails.env %>
|
30
|
+
|
31
|
+
# mirror:
|
32
|
+
# service: Mirror
|
33
|
+
# primary: local
|
34
|
+
# mirrors: [ amazon, google, microsoft ]
|
data/config.ru
ADDED
data/db/cable_schema.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
ActiveRecord::Schema[7.1].define(version: 1) do
|
2
|
+
create_table "solid_cable_messages", force: :cascade do |t|
|
3
|
+
t.binary "channel", limit: 1024, null: false
|
4
|
+
t.binary "payload", limit: 536870912, null: false
|
5
|
+
t.datetime "created_at", null: false
|
6
|
+
t.integer "channel_hash", limit: 8, null: false
|
7
|
+
t.index ["channel"], name: "index_solid_cable_messages_on_channel"
|
8
|
+
t.index ["channel_hash"], name: "index_solid_cable_messages_on_channel_hash"
|
9
|
+
t.index ["created_at"], name: "index_solid_cable_messages_on_created_at"
|
10
|
+
end
|
11
|
+
end
|
data/db/cache_schema.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ActiveRecord::Schema[7.2].define(version: 1) do
|
4
|
+
create_table "solid_cache_entries", force: :cascade do |t|
|
5
|
+
t.binary "key", limit: 1024, null: false
|
6
|
+
t.binary "value", limit: 536870912, null: false
|
7
|
+
t.datetime "created_at", null: false
|
8
|
+
t.integer "key_hash", limit: 8, null: false
|
9
|
+
t.integer "byte_size", limit: 4, null: false
|
10
|
+
t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size"
|
11
|
+
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
|
12
|
+
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateAppProfiles < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :app_profiles do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.string :api_key_digest, null: false
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :app_profiles, :api_key_digest, unique: true
|
11
|
+
add_index :app_profiles, :name
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateQueryAnalyses < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :query_analyses do |t|
|
4
|
+
t.references :app_profile, null: false, foreign_key: true
|
5
|
+
t.text :sql_query, null: false
|
6
|
+
t.integer :duration_ms
|
7
|
+
t.string :table_name
|
8
|
+
t.string :query_type
|
9
|
+
t.datetime :analyzed_at, null: false
|
10
|
+
t.string :query_hash # For detecting similar queries
|
11
|
+
t.json :parsed_data # Store parsed query structure
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :query_analyses, :analyzed_at
|
17
|
+
add_index :query_analyses, :table_name
|
18
|
+
add_index :query_analyses, :query_type
|
19
|
+
add_index :query_analyses, :query_hash
|
20
|
+
add_index :query_analyses, :duration_ms
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateQueryPatterns < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :query_patterns do |t|
|
4
|
+
t.string :pattern_type, null: false # 'n_plus_one', 'slow_query', 'missing_index'
|
5
|
+
t.string :table_name, null: false
|
6
|
+
t.string :column_name
|
7
|
+
t.integer :frequency, default: 1
|
8
|
+
t.datetime :first_seen, null: false
|
9
|
+
t.datetime :last_seen, null: false
|
10
|
+
t.string :pattern_signature # Unique identifier for the pattern
|
11
|
+
t.json :metadata # Additional pattern-specific data
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :query_patterns, :pattern_type
|
17
|
+
add_index :query_patterns, :table_name
|
18
|
+
add_index :query_patterns, :pattern_signature, unique: true
|
19
|
+
add_index :query_patterns, :frequency
|
20
|
+
add_index :query_patterns, [:pattern_type, :table_name]
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateOptimizationSuggestions < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :optimization_suggestions do |t|
|
4
|
+
t.references :query_analysis, null: false, foreign_key: true
|
5
|
+
t.string :suggestion_type, null: false # 'n_plus_one', 'slow_query', 'missing_index', 'query_optimization'
|
6
|
+
t.string :title, null: false
|
7
|
+
t.text :description, null: false
|
8
|
+
t.text :sql_suggestion
|
9
|
+
t.integer :priority, default: 1 # 1=low, 2=medium, 3=high, 4=critical
|
10
|
+
t.boolean :implemented, default: false
|
11
|
+
t.json :metadata # Additional suggestion-specific data
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :optimization_suggestions, :suggestion_type
|
17
|
+
add_index :optimization_suggestions, :priority
|
18
|
+
add_index :optimization_suggestions, :implemented
|
19
|
+
end
|
20
|
+
end
|
data/db/queue_schema.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
ActiveRecord::Schema[7.1].define(version: 1) do
|
2
|
+
create_table "solid_queue_blocked_executions", force: :cascade do |t|
|
3
|
+
t.bigint "job_id", null: false
|
4
|
+
t.string "queue_name", null: false
|
5
|
+
t.integer "priority", default: 0, null: false
|
6
|
+
t.string "concurrency_key", null: false
|
7
|
+
t.datetime "expires_at", null: false
|
8
|
+
t.datetime "created_at", null: false
|
9
|
+
t.index [ "concurrency_key", "priority", "job_id" ], name: "index_solid_queue_blocked_executions_for_release"
|
10
|
+
t.index [ "expires_at", "concurrency_key" ], name: "index_solid_queue_blocked_executions_for_maintenance"
|
11
|
+
t.index [ "job_id" ], name: "index_solid_queue_blocked_executions_on_job_id", unique: true
|
12
|
+
end
|
13
|
+
|
14
|
+
create_table "solid_queue_claimed_executions", force: :cascade do |t|
|
15
|
+
t.bigint "job_id", null: false
|
16
|
+
t.bigint "process_id"
|
17
|
+
t.datetime "created_at", null: false
|
18
|
+
t.index [ "job_id" ], name: "index_solid_queue_claimed_executions_on_job_id", unique: true
|
19
|
+
t.index [ "process_id", "job_id" ], name: "index_solid_queue_claimed_executions_on_process_id_and_job_id"
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "solid_queue_failed_executions", force: :cascade do |t|
|
23
|
+
t.bigint "job_id", null: false
|
24
|
+
t.text "error"
|
25
|
+
t.datetime "created_at", null: false
|
26
|
+
t.index [ "job_id" ], name: "index_solid_queue_failed_executions_on_job_id", unique: true
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table "solid_queue_jobs", force: :cascade do |t|
|
30
|
+
t.string "queue_name", null: false
|
31
|
+
t.string "class_name", null: false
|
32
|
+
t.text "arguments"
|
33
|
+
t.integer "priority", default: 0, null: false
|
34
|
+
t.string "active_job_id"
|
35
|
+
t.datetime "scheduled_at"
|
36
|
+
t.datetime "finished_at"
|
37
|
+
t.string "concurrency_key"
|
38
|
+
t.datetime "created_at", null: false
|
39
|
+
t.datetime "updated_at", null: false
|
40
|
+
t.index [ "active_job_id" ], name: "index_solid_queue_jobs_on_active_job_id"
|
41
|
+
t.index [ "class_name" ], name: "index_solid_queue_jobs_on_class_name"
|
42
|
+
t.index [ "finished_at" ], name: "index_solid_queue_jobs_on_finished_at"
|
43
|
+
t.index [ "queue_name", "finished_at" ], name: "index_solid_queue_jobs_for_filtering"
|
44
|
+
t.index [ "scheduled_at", "finished_at" ], name: "index_solid_queue_jobs_for_alerting"
|
45
|
+
end
|
46
|
+
|
47
|
+
create_table "solid_queue_pauses", force: :cascade do |t|
|
48
|
+
t.string "queue_name", null: false
|
49
|
+
t.datetime "created_at", null: false
|
50
|
+
t.index [ "queue_name" ], name: "index_solid_queue_pauses_on_queue_name", unique: true
|
51
|
+
end
|
52
|
+
|
53
|
+
create_table "solid_queue_processes", force: :cascade do |t|
|
54
|
+
t.string "kind", null: false
|
55
|
+
t.datetime "last_heartbeat_at", null: false
|
56
|
+
t.bigint "supervisor_id"
|
57
|
+
t.integer "pid", null: false
|
58
|
+
t.string "hostname"
|
59
|
+
t.text "metadata"
|
60
|
+
t.datetime "created_at", null: false
|
61
|
+
t.string "name", null: false
|
62
|
+
t.index [ "last_heartbeat_at" ], name: "index_solid_queue_processes_on_last_heartbeat_at"
|
63
|
+
t.index [ "name", "supervisor_id" ], name: "index_solid_queue_processes_on_name_and_supervisor_id", unique: true
|
64
|
+
t.index [ "supervisor_id" ], name: "index_solid_queue_processes_on_supervisor_id"
|
65
|
+
end
|
66
|
+
|
67
|
+
create_table "solid_queue_ready_executions", force: :cascade do |t|
|
68
|
+
t.bigint "job_id", null: false
|
69
|
+
t.string "queue_name", null: false
|
70
|
+
t.integer "priority", default: 0, null: false
|
71
|
+
t.datetime "created_at", null: false
|
72
|
+
t.index [ "job_id" ], name: "index_solid_queue_ready_executions_on_job_id", unique: true
|
73
|
+
t.index [ "priority", "job_id" ], name: "index_solid_queue_poll_all"
|
74
|
+
t.index [ "queue_name", "priority", "job_id" ], name: "index_solid_queue_poll_by_queue"
|
75
|
+
end
|
76
|
+
|
77
|
+
create_table "solid_queue_recurring_executions", force: :cascade do |t|
|
78
|
+
t.bigint "job_id", null: false
|
79
|
+
t.string "task_key", null: false
|
80
|
+
t.datetime "run_at", null: false
|
81
|
+
t.datetime "created_at", null: false
|
82
|
+
t.index [ "job_id" ], name: "index_solid_queue_recurring_executions_on_job_id", unique: true
|
83
|
+
t.index [ "task_key", "run_at" ], name: "index_solid_queue_recurring_executions_on_task_key_and_run_at", unique: true
|
84
|
+
end
|
85
|
+
|
86
|
+
create_table "solid_queue_recurring_tasks", force: :cascade do |t|
|
87
|
+
t.string "key", null: false
|
88
|
+
t.string "schedule", null: false
|
89
|
+
t.string "command", limit: 2048
|
90
|
+
t.string "class_name"
|
91
|
+
t.text "arguments"
|
92
|
+
t.string "queue_name"
|
93
|
+
t.integer "priority", default: 0
|
94
|
+
t.boolean "static", default: true, null: false
|
95
|
+
t.text "description"
|
96
|
+
t.datetime "created_at", null: false
|
97
|
+
t.datetime "updated_at", null: false
|
98
|
+
t.index [ "key" ], name: "index_solid_queue_recurring_tasks_on_key", unique: true
|
99
|
+
t.index [ "static" ], name: "index_solid_queue_recurring_tasks_on_static"
|
100
|
+
end
|
101
|
+
|
102
|
+
create_table "solid_queue_scheduled_executions", force: :cascade do |t|
|
103
|
+
t.bigint "job_id", null: false
|
104
|
+
t.string "queue_name", null: false
|
105
|
+
t.integer "priority", default: 0, null: false
|
106
|
+
t.datetime "scheduled_at", null: false
|
107
|
+
t.datetime "created_at", null: false
|
108
|
+
t.index [ "job_id" ], name: "index_solid_queue_scheduled_executions_on_job_id", unique: true
|
109
|
+
t.index [ "scheduled_at", "priority", "job_id" ], name: "index_solid_queue_dispatch_all"
|
110
|
+
end
|
111
|
+
|
112
|
+
create_table "solid_queue_semaphores", force: :cascade do |t|
|
113
|
+
t.string "key", null: false
|
114
|
+
t.integer "value", default: 1, null: false
|
115
|
+
t.datetime "expires_at", null: false
|
116
|
+
t.datetime "created_at", null: false
|
117
|
+
t.datetime "updated_at", null: false
|
118
|
+
t.index [ "expires_at" ], name: "index_solid_queue_semaphores_on_expires_at"
|
119
|
+
t.index [ "key", "value" ], name: "index_solid_queue_semaphores_on_key_and_value"
|
120
|
+
t.index [ "key" ], name: "index_solid_queue_semaphores_on_key", unique: true
|
121
|
+
end
|
122
|
+
|
123
|
+
add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
124
|
+
add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
125
|
+
add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
126
|
+
add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
127
|
+
add_foreign_key "solid_queue_recurring_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
128
|
+
add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
|
129
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
|
+
# be faster and is potentially less error prone than running all of your
|
8
|
+
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
|
+
# migrations use external dependencies or application code.
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema[8.0].define(version: 2025_08_18_214805) do
|
14
|
+
create_table "app_profiles", force: :cascade do |t|
|
15
|
+
t.string "name", null: false
|
16
|
+
t.string "api_key_digest", null: false
|
17
|
+
t.datetime "created_at", null: false
|
18
|
+
t.datetime "updated_at", null: false
|
19
|
+
t.index ["api_key_digest"], name: "index_app_profiles_on_api_key_digest", unique: true
|
20
|
+
t.index ["name"], name: "index_app_profiles_on_name"
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table "optimization_suggestions", force: :cascade do |t|
|
24
|
+
t.integer "query_analysis_id", null: false
|
25
|
+
t.string "suggestion_type", null: false
|
26
|
+
t.string "title", null: false
|
27
|
+
t.text "description", null: false
|
28
|
+
t.text "sql_suggestion"
|
29
|
+
t.integer "priority", default: 1
|
30
|
+
t.boolean "implemented", default: false
|
31
|
+
t.json "metadata"
|
32
|
+
t.datetime "created_at", null: false
|
33
|
+
t.datetime "updated_at", null: false
|
34
|
+
t.index ["implemented"], name: "index_optimization_suggestions_on_implemented"
|
35
|
+
t.index ["priority"], name: "index_optimization_suggestions_on_priority"
|
36
|
+
t.index ["query_analysis_id"], name: "index_optimization_suggestions_on_query_analysis_id"
|
37
|
+
t.index ["suggestion_type"], name: "index_optimization_suggestions_on_suggestion_type"
|
38
|
+
end
|
39
|
+
|
40
|
+
create_table "query_analyses", force: :cascade do |t|
|
41
|
+
t.integer "app_profile_id", null: false
|
42
|
+
t.text "sql_query", null: false
|
43
|
+
t.integer "duration_ms"
|
44
|
+
t.string "table_name"
|
45
|
+
t.string "query_type"
|
46
|
+
t.datetime "analyzed_at", null: false
|
47
|
+
t.string "query_hash"
|
48
|
+
t.json "parsed_data"
|
49
|
+
t.datetime "created_at", null: false
|
50
|
+
t.datetime "updated_at", null: false
|
51
|
+
t.index ["analyzed_at"], name: "index_query_analyses_on_analyzed_at"
|
52
|
+
t.index ["app_profile_id"], name: "index_query_analyses_on_app_profile_id"
|
53
|
+
t.index ["duration_ms"], name: "index_query_analyses_on_duration_ms"
|
54
|
+
t.index ["query_hash"], name: "index_query_analyses_on_query_hash"
|
55
|
+
t.index ["query_type"], name: "index_query_analyses_on_query_type"
|
56
|
+
t.index ["table_name"], name: "index_query_analyses_on_table_name"
|
57
|
+
end
|
58
|
+
|
59
|
+
create_table "query_patterns", force: :cascade do |t|
|
60
|
+
t.string "pattern_type", null: false
|
61
|
+
t.string "table_name", null: false
|
62
|
+
t.string "column_name"
|
63
|
+
t.integer "frequency", default: 1
|
64
|
+
t.datetime "first_seen", null: false
|
65
|
+
t.datetime "last_seen", null: false
|
66
|
+
t.string "pattern_signature"
|
67
|
+
t.json "metadata"
|
68
|
+
t.datetime "created_at", null: false
|
69
|
+
t.datetime "updated_at", null: false
|
70
|
+
t.index ["frequency"], name: "index_query_patterns_on_frequency"
|
71
|
+
t.index ["pattern_signature"], name: "index_query_patterns_on_pattern_signature", unique: true
|
72
|
+
t.index ["pattern_type", "table_name"], name: "index_query_patterns_on_pattern_type_and_table_name"
|
73
|
+
t.index ["pattern_type"], name: "index_query_patterns_on_pattern_type"
|
74
|
+
t.index ["table_name"], name: "index_query_patterns_on_table_name"
|
75
|
+
end
|
76
|
+
|
77
|
+
add_foreign_key "optimization_suggestions", "query_analyses"
|
78
|
+
add_foreign_key "query_analyses", "app_profiles"
|
79
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# This file should ensure the existence of records required to run the application in every environment (production,
|
2
|
+
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
|
3
|
+
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
#
|
7
|
+
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
|
8
|
+
# MovieGenre.find_or_create_by!(name: genre_name)
|
9
|
+
# end
|
data/init.sql
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
-- Initialize PostgreSQL for Query Optimizer API
|
2
|
+
-- This script runs when the database container starts for the first time
|
3
|
+
|
4
|
+
-- Enable required extensions
|
5
|
+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
6
|
+
CREATE EXTENSION IF NOT EXISTS "pg_stat_statements";
|
7
|
+
|
8
|
+
-- Create database if it doesn't exist (handled by POSTGRES_DB env var)
|
9
|
+
-- This file is mainly for any additional setup needed
|