rails_console_pro 0.1.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/.editorconfig +12 -0
- data/.rspec +4 -0
- data/.rspec_status +240 -0
- data/.rubocop.yml +26 -0
- data/CHANGELOG.md +24 -0
- data/CONTRIBUTING.md +76 -0
- data/LICENSE.txt +22 -0
- data/QUICK_START.md +112 -0
- data/README.md +124 -0
- data/Rakefile +13 -0
- data/config/database.yml +3 -0
- data/docs/ASSOCIATION_NAVIGATION.md +85 -0
- data/docs/EXPORT.md +95 -0
- data/docs/FORMATTING.md +86 -0
- data/docs/MODEL_STATISTICS.md +72 -0
- data/docs/OBJECT_DIFFING.md +87 -0
- data/docs/SCHEMA_INSPECTION.md +60 -0
- data/docs/SQL_EXPLAIN.md +70 -0
- data/lib/generators/rails_console_pro/install_generator.rb +16 -0
- data/lib/generators/rails_console_pro/templates/rails_console_pro.rb +44 -0
- data/lib/rails_console_pro/active_record_extensions.rb +113 -0
- data/lib/rails_console_pro/association_navigator.rb +273 -0
- data/lib/rails_console_pro/base_printer.rb +74 -0
- data/lib/rails_console_pro/color_helper.rb +36 -0
- data/lib/rails_console_pro/commands/base_command.rb +17 -0
- data/lib/rails_console_pro/commands/diff_command.rb +135 -0
- data/lib/rails_console_pro/commands/explain_command.rb +118 -0
- data/lib/rails_console_pro/commands/export_command.rb +16 -0
- data/lib/rails_console_pro/commands/schema_command.rb +20 -0
- data/lib/rails_console_pro/commands/stats_command.rb +93 -0
- data/lib/rails_console_pro/commands.rb +34 -0
- data/lib/rails_console_pro/configuration.rb +219 -0
- data/lib/rails_console_pro/diff_result.rb +56 -0
- data/lib/rails_console_pro/error_handler.rb +60 -0
- data/lib/rails_console_pro/explain_result.rb +47 -0
- data/lib/rails_console_pro/format_exporter.rb +403 -0
- data/lib/rails_console_pro/global_methods.rb +42 -0
- data/lib/rails_console_pro/initializer.rb +176 -0
- data/lib/rails_console_pro/model_validator.rb +219 -0
- data/lib/rails_console_pro/paginator.rb +204 -0
- data/lib/rails_console_pro/printers/active_record_printer.rb +30 -0
- data/lib/rails_console_pro/printers/collection_printer.rb +34 -0
- data/lib/rails_console_pro/printers/diff_printer.rb +97 -0
- data/lib/rails_console_pro/printers/explain_printer.rb +151 -0
- data/lib/rails_console_pro/printers/relation_printer.rb +25 -0
- data/lib/rails_console_pro/printers/schema_printer.rb +188 -0
- data/lib/rails_console_pro/printers/stats_printer.rb +129 -0
- data/lib/rails_console_pro/pry_commands.rb +241 -0
- data/lib/rails_console_pro/pry_integration.rb +9 -0
- data/lib/rails_console_pro/railtie.rb +29 -0
- data/lib/rails_console_pro/schema_inspector_result.rb +43 -0
- data/lib/rails_console_pro/serializers/active_record_serializer.rb +18 -0
- data/lib/rails_console_pro/serializers/array_serializer.rb +31 -0
- data/lib/rails_console_pro/serializers/base_serializer.rb +25 -0
- data/lib/rails_console_pro/serializers/diff_serializer.rb +24 -0
- data/lib/rails_console_pro/serializers/explain_serializer.rb +35 -0
- data/lib/rails_console_pro/serializers/relation_serializer.rb +25 -0
- data/lib/rails_console_pro/serializers/schema_serializer.rb +121 -0
- data/lib/rails_console_pro/serializers/stats_serializer.rb +24 -0
- data/lib/rails_console_pro/services/column_stats_calculator.rb +64 -0
- data/lib/rails_console_pro/services/index_analyzer.rb +110 -0
- data/lib/rails_console_pro/services/stats_calculator.rb +40 -0
- data/lib/rails_console_pro/services/table_size_calculator.rb +43 -0
- data/lib/rails_console_pro/stats_result.rb +66 -0
- data/lib/rails_console_pro/version.rb +6 -0
- data/lib/rails_console_pro.rb +14 -0
- data/lib/tasks/rails_console_pro.rake +10 -0
- data/rails_console_pro.gemspec +60 -0
- metadata +240 -0
data/Rakefile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rspec/core/rake_task"
|
|
5
|
+
|
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
7
|
+
|
|
8
|
+
require "rubocop/rake_task" if defined?(RuboCop)
|
|
9
|
+
|
|
10
|
+
RuboCop::RakeTask.new if defined?(RuboCop)
|
|
11
|
+
|
|
12
|
+
task default: :spec
|
|
13
|
+
|
data/config/database.yml
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Association Navigation
|
|
2
|
+
|
|
3
|
+
Interactive navigation through model associations to explore your data relationships.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
# Start navigation from a model
|
|
9
|
+
navigate User
|
|
10
|
+
|
|
11
|
+
# Or as a method
|
|
12
|
+
navigate(User)
|
|
13
|
+
|
|
14
|
+
# Navigate from a model class name (string)
|
|
15
|
+
navigate "User"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Interactive Menu
|
|
19
|
+
|
|
20
|
+
When you run `navigate User`, you'll see:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
═══════════════════════════════════════════════════════════
|
|
24
|
+
🧭 ASSOCIATION NAVIGATOR
|
|
25
|
+
═══════════════════════════════════════════════════════════
|
|
26
|
+
|
|
27
|
+
📍 Current Location: User
|
|
28
|
+
(1,234 records in database)
|
|
29
|
+
|
|
30
|
+
🔗 Available Associations:
|
|
31
|
+
|
|
32
|
+
belongs_to:
|
|
33
|
+
1. ↖️ account → Account [account_id]
|
|
34
|
+
|
|
35
|
+
has_many:
|
|
36
|
+
2. ⇒ posts → Post [user_id] (dependent: destroy) [~5 per record]
|
|
37
|
+
3. ⇒ comments → Comment [user_id] [~12 per record]
|
|
38
|
+
|
|
39
|
+
has_one:
|
|
40
|
+
4. → profile → Profile [user_id]
|
|
41
|
+
|
|
42
|
+
📌 Navigation Options:
|
|
43
|
+
b - Go back to previous model
|
|
44
|
+
q - Exit navigator
|
|
45
|
+
s - Show sample records for current model
|
|
46
|
+
c - Show count for all associations
|
|
47
|
+
|
|
48
|
+
➤ Enter choice:
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Commands
|
|
52
|
+
|
|
53
|
+
- **Number or name**: Navigate to that association
|
|
54
|
+
- **b**: Go back to previous model
|
|
55
|
+
- **q**: Exit navigator
|
|
56
|
+
- **s**: Show sample records for current model
|
|
57
|
+
- **c**: Show count for all associations
|
|
58
|
+
|
|
59
|
+
## Code Example
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
# Start navigation
|
|
63
|
+
navigate User
|
|
64
|
+
|
|
65
|
+
# In the menu, select an association by number or name
|
|
66
|
+
# For example, enter "2" to navigate to Post model
|
|
67
|
+
# Then enter "q" to exit
|
|
68
|
+
|
|
69
|
+
# View sample records
|
|
70
|
+
navigate User
|
|
71
|
+
# Then type "s" to see sample User records
|
|
72
|
+
|
|
73
|
+
# View association counts
|
|
74
|
+
navigate User
|
|
75
|
+
# Then type "c" to see counts for all associations
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Features
|
|
79
|
+
|
|
80
|
+
- **Visual Icons**: Different icons for each association type
|
|
81
|
+
- **Breadcrumb Navigation**: See your navigation path
|
|
82
|
+
- **Sample Records**: View sample data from current model
|
|
83
|
+
- **Association Counts**: See record counts for all associations
|
|
84
|
+
- **History**: Navigate back through your path
|
|
85
|
+
|
data/docs/EXPORT.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Export Capabilities
|
|
2
|
+
|
|
3
|
+
Export data to JSON, YAML, and HTML formats for sharing and analysis.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
# Export using Pry command
|
|
9
|
+
export schema(User) user_schema.json
|
|
10
|
+
export stats(User) user_stats.json
|
|
11
|
+
export explain(User.where(active: true)) query_explain.json
|
|
12
|
+
|
|
13
|
+
# Export as method
|
|
14
|
+
schema(User).export_to_file('user_schema.json')
|
|
15
|
+
stats(User).export_to_file('user_stats.yaml')
|
|
16
|
+
diff(user1, user2).export_to_file('diff.html')
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Supported Formats
|
|
20
|
+
|
|
21
|
+
### JSON
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
# Export to JSON
|
|
25
|
+
export schema(User) user_schema.json
|
|
26
|
+
|
|
27
|
+
# Or programmatically
|
|
28
|
+
schema(User).to_json
|
|
29
|
+
schema(User).export_to_file('user_schema.json', format: :json)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### YAML
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
# Export to YAML
|
|
36
|
+
export stats(User) user_stats.yaml
|
|
37
|
+
|
|
38
|
+
# Or programmatically
|
|
39
|
+
stats(User).to_yaml
|
|
40
|
+
stats(User).export_to_file('user_stats.yaml', format: :yaml)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### HTML
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# Export to HTML
|
|
47
|
+
export diff(user1, user2) comparison.html
|
|
48
|
+
|
|
49
|
+
# Or programmatically
|
|
50
|
+
diff(user1, user2).to_html
|
|
51
|
+
diff(user1, user2).export_to_file('comparison.html', format: :html)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Code Examples
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
# Export schema
|
|
58
|
+
schema_result = schema(User)
|
|
59
|
+
schema_result.export_to_file('user_schema.json')
|
|
60
|
+
|
|
61
|
+
# Export statistics
|
|
62
|
+
stats_result = stats(User)
|
|
63
|
+
stats_result.export_to_file('user_stats.yaml', format: :yaml)
|
|
64
|
+
|
|
65
|
+
# Export explain result
|
|
66
|
+
explain_result = explain(User.where(active: true))
|
|
67
|
+
explain_result.export_to_file('query_explain.html', format: :html)
|
|
68
|
+
|
|
69
|
+
# Export ActiveRecord objects
|
|
70
|
+
user = User.first
|
|
71
|
+
user.export_to_file('user.json')
|
|
72
|
+
|
|
73
|
+
# Export collections
|
|
74
|
+
users = User.limit(10)
|
|
75
|
+
users.export_to_file('users.json')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Exportable Objects
|
|
79
|
+
|
|
80
|
+
- Schema inspection results (`schema(User)`)
|
|
81
|
+
- SQL explain results (`explain(query)`)
|
|
82
|
+
- Model statistics (`stats(User)`)
|
|
83
|
+
- Object diffs (`diff(obj1, obj2)`)
|
|
84
|
+
- ActiveRecord objects
|
|
85
|
+
- ActiveRecord relations
|
|
86
|
+
- Arrays and hashes
|
|
87
|
+
|
|
88
|
+
## Features
|
|
89
|
+
|
|
90
|
+
- **Automatic Format Detection**: Format inferred from file extension
|
|
91
|
+
- **Pretty JSON**: Human-readable JSON output
|
|
92
|
+
- **Styled HTML**: Beautiful HTML with CSS styling
|
|
93
|
+
- **YAML Support**: Clean YAML output
|
|
94
|
+
- **Error Handling**: Graceful handling of unsupported formats
|
|
95
|
+
|
data/docs/FORMATTING.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Beautiful Formatting
|
|
2
|
+
|
|
3
|
+
Automatic colored and styled output for ActiveRecord objects, relations, and collections.
|
|
4
|
+
|
|
5
|
+
## Automatic Formatting
|
|
6
|
+
|
|
7
|
+
The gem automatically formats ActiveRecord objects when displayed in the console:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
# ActiveRecord objects
|
|
11
|
+
user = User.first
|
|
12
|
+
# Automatically displayed with colors and formatting
|
|
13
|
+
|
|
14
|
+
# Relations
|
|
15
|
+
User.where(active: true)
|
|
16
|
+
# Automatically formatted with pagination
|
|
17
|
+
|
|
18
|
+
# Collections
|
|
19
|
+
User.limit(10).to_a
|
|
20
|
+
# Automatically formatted with nice layout
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Example Output
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
┌─────────────────────────────────────────────────────────┐
|
|
27
|
+
│ User #1 │
|
|
28
|
+
├─────────────────────────────────────────────────────────┤
|
|
29
|
+
│ id: 1 │
|
|
30
|
+
│ email: john@example.com │
|
|
31
|
+
│ name: John Doe │
|
|
32
|
+
│ active: true │
|
|
33
|
+
│ created_at: 2024-01-01 12:00:00 UTC │
|
|
34
|
+
│ updated_at: 2024-01-02 10:30:00 UTC │
|
|
35
|
+
└─────────────────────────────────────────────────────────┘
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Pagination
|
|
39
|
+
|
|
40
|
+
Large collections are automatically paginated:
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
# Collection with more than 10 items
|
|
44
|
+
User.all
|
|
45
|
+
# Shows: "Showing 1-10 of 1234 records. Press Enter for more..."
|
|
46
|
+
|
|
47
|
+
# Relations are paginated automatically
|
|
48
|
+
Post.where(published: true)
|
|
49
|
+
# Shows paginated results
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
Customize formatting in your initializer:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
RailsConsolePro.configure do |config|
|
|
58
|
+
# Color scheme
|
|
59
|
+
config.color_scheme = :dark # or :light
|
|
60
|
+
|
|
61
|
+
# Pagination settings
|
|
62
|
+
config.pagination_enabled = true
|
|
63
|
+
config.pagination_threshold = 10
|
|
64
|
+
config.pagination_page_size = 5
|
|
65
|
+
|
|
66
|
+
# Custom colors
|
|
67
|
+
config.set_color(:header, :bright_blue)
|
|
68
|
+
config.set_color(:key, :cyan)
|
|
69
|
+
config.set_color(:value, :white)
|
|
70
|
+
end
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Formatted Objects
|
|
74
|
+
|
|
75
|
+
- **ActiveRecord objects**: Single records with all attributes
|
|
76
|
+
- **ActiveRecord relations**: Paginated collections
|
|
77
|
+
- **Arrays**: Formatted lists
|
|
78
|
+
- **Command results**: Schema, stats, explain, diff results
|
|
79
|
+
|
|
80
|
+
## Features
|
|
81
|
+
|
|
82
|
+
- **Color Coding**: Different colors for different data types
|
|
83
|
+
- **Automatic Pagination**: Large collections are paginated
|
|
84
|
+
- **Clean Layout**: Well-organized, readable output
|
|
85
|
+
- **Dark/Light Themes**: Choose your preferred color scheme
|
|
86
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Model Statistics
|
|
2
|
+
|
|
3
|
+
Get comprehensive statistics about your models including record counts, growth rates, table sizes, and index usage.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
# Get statistics for a model
|
|
9
|
+
stats User
|
|
10
|
+
|
|
11
|
+
# Or as a method
|
|
12
|
+
stats(User)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Example Output
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
═══════════════════════════════════════════════════════════
|
|
19
|
+
📈 STATISTICS: User
|
|
20
|
+
═══════════════════════════════════════════════════════════
|
|
21
|
+
|
|
22
|
+
Record Count: 1,234
|
|
23
|
+
|
|
24
|
+
Growth Rate:
|
|
25
|
+
Last 24 hours: +15 records
|
|
26
|
+
Last 7 days: +98 records
|
|
27
|
+
Last 30 days: +456 records
|
|
28
|
+
|
|
29
|
+
Table Size:
|
|
30
|
+
Total: 2.5 MB
|
|
31
|
+
Data: 1.8 MB
|
|
32
|
+
Indexes: 0.7 MB
|
|
33
|
+
|
|
34
|
+
Index Usage:
|
|
35
|
+
✓ index_users_on_email (frequently used)
|
|
36
|
+
✓ index_users_on_created_at (frequently used)
|
|
37
|
+
⚠ index_users_on_last_login (rarely used)
|
|
38
|
+
|
|
39
|
+
Column Statistics:
|
|
40
|
+
email: 1,234 unique values
|
|
41
|
+
active: 85% true, 15% false
|
|
42
|
+
created_at: 2020-01-01 to 2024-12-31
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Code Example
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
# Get statistics
|
|
49
|
+
stats User
|
|
50
|
+
|
|
51
|
+
# Get stats result object
|
|
52
|
+
result = stats(User)
|
|
53
|
+
result.record_count # => 1234
|
|
54
|
+
result.growth_rate # => { "24h" => 15, "7d" => 98, "30d" => 456 }
|
|
55
|
+
result.table_size # => { "total" => "2.5 MB", "data" => "1.8 MB" }
|
|
56
|
+
result.index_usage # => { ... }
|
|
57
|
+
|
|
58
|
+
# Export statistics
|
|
59
|
+
stats(User).to_json
|
|
60
|
+
|
|
61
|
+
# Export to file
|
|
62
|
+
export stats(User) user_stats.json
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Statistics Included
|
|
66
|
+
|
|
67
|
+
- **Record Count**: Total number of records
|
|
68
|
+
- **Growth Rate**: New records in last 24h, 7d, 30d (requires `created_at` column)
|
|
69
|
+
- **Table Size**: Database table size and index size
|
|
70
|
+
- **Index Usage**: Which indexes are used frequently
|
|
71
|
+
- **Column Statistics**: Unique values, distributions, ranges (for smaller tables)
|
|
72
|
+
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Object Diffing
|
|
2
|
+
|
|
3
|
+
Compare two ActiveRecord objects or hashes and highlight their differences.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
# Compare two ActiveRecord objects
|
|
9
|
+
user1 = User.first
|
|
10
|
+
user2 = User.last
|
|
11
|
+
diff user1, user2
|
|
12
|
+
|
|
13
|
+
# Compare two hashes
|
|
14
|
+
diff({ name: "John", age: 30 }, { name: "Jane", age: 30 })
|
|
15
|
+
|
|
16
|
+
# Or as a method
|
|
17
|
+
diff(user1, user2)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Example Output
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
═══════════════════════════════════════════════════════════
|
|
24
|
+
🔄 OBJECT DIFF
|
|
25
|
+
═══════════════════════════════════════════════════════════
|
|
26
|
+
|
|
27
|
+
Comparing:
|
|
28
|
+
User #1 vs User #2
|
|
29
|
+
|
|
30
|
+
Status: ❌ Objects are different
|
|
31
|
+
|
|
32
|
+
Differences:
|
|
33
|
+
name:
|
|
34
|
+
Old: "John Doe"
|
|
35
|
+
New: "Jane Doe"
|
|
36
|
+
|
|
37
|
+
email:
|
|
38
|
+
Old: "john@example.com"
|
|
39
|
+
New: "jane@example.com"
|
|
40
|
+
|
|
41
|
+
active:
|
|
42
|
+
Old: true
|
|
43
|
+
New: false
|
|
44
|
+
|
|
45
|
+
Identical Attributes:
|
|
46
|
+
id: 1
|
|
47
|
+
created_at: 2024-01-01 12:00:00 UTC
|
|
48
|
+
updated_at: 2024-01-01 12:00:00 UTC
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Code Example
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
# Compare two users
|
|
55
|
+
user1 = User.find(1)
|
|
56
|
+
user2 = User.find(2)
|
|
57
|
+
diff user1, user2
|
|
58
|
+
|
|
59
|
+
# Compare hashes
|
|
60
|
+
diff(
|
|
61
|
+
{ name: "John", age: 30, city: "NYC" },
|
|
62
|
+
{ name: "Jane", age: 30, city: "LA" }
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Get diff result
|
|
66
|
+
result = diff(user1, user2)
|
|
67
|
+
result.identical? # => false
|
|
68
|
+
result.differences # => { name: { old_value: "...", new_value: "..." } }
|
|
69
|
+
|
|
70
|
+
# Export diff result
|
|
71
|
+
diff(user1, user2).to_json
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Supported Object Types
|
|
75
|
+
|
|
76
|
+
- **ActiveRecord objects**: Compares all attributes
|
|
77
|
+
- **Hash objects**: Compares all keys and values
|
|
78
|
+
- **Objects with attributes**: Any object responding to `attributes`
|
|
79
|
+
- **Simple values**: Direct comparison
|
|
80
|
+
|
|
81
|
+
## Features
|
|
82
|
+
|
|
83
|
+
- **Highlight Differences**: Only shows attributes that differ
|
|
84
|
+
- **Show Identical Attributes**: Lists attributes that are the same
|
|
85
|
+
- **Multiple Object Types**: Works with ActiveRecord, Hash, and more
|
|
86
|
+
- **Export Support**: Export diff results to JSON/YAML/HTML
|
|
87
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Schema Inspection
|
|
2
|
+
|
|
3
|
+
Inspect database schemas with detailed information about columns, indexes, associations, validations, and scopes.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
# Simple usage
|
|
9
|
+
schema User
|
|
10
|
+
|
|
11
|
+
# Or as a method
|
|
12
|
+
schema(User)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Example Output
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
═══════════════════════════════════════════════════════════
|
|
19
|
+
📊 SCHEMA: User
|
|
20
|
+
═══════════════════════════════════════════════════════════
|
|
21
|
+
|
|
22
|
+
Columns:
|
|
23
|
+
id :integer PRIMARY KEY, NOT NULL
|
|
24
|
+
email :string NOT NULL, UNIQUE
|
|
25
|
+
name :string NULLABLE
|
|
26
|
+
created_at :datetime NOT NULL
|
|
27
|
+
updated_at :datetime NOT NULL
|
|
28
|
+
|
|
29
|
+
Indexes:
|
|
30
|
+
index_users_on_email UNIQUE (email)
|
|
31
|
+
index_users_on_created_at (created_at)
|
|
32
|
+
|
|
33
|
+
Associations:
|
|
34
|
+
has_many :posts
|
|
35
|
+
has_one :profile
|
|
36
|
+
belongs_to :account
|
|
37
|
+
|
|
38
|
+
Validations:
|
|
39
|
+
validates :email, presence: true, uniqueness: true
|
|
40
|
+
|
|
41
|
+
Scopes:
|
|
42
|
+
scope :active, -> { where(active: true) }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Code Example
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
# Inspect a model
|
|
49
|
+
schema User
|
|
50
|
+
|
|
51
|
+
# Get schema result object
|
|
52
|
+
result = schema(User)
|
|
53
|
+
|
|
54
|
+
# Export schema to JSON
|
|
55
|
+
schema(User).to_json
|
|
56
|
+
|
|
57
|
+
# Export to file
|
|
58
|
+
export schema(User) user_schema.json
|
|
59
|
+
```
|
|
60
|
+
|
data/docs/SQL_EXPLAIN.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# SQL Explain
|
|
2
|
+
|
|
3
|
+
Analyze SQL query execution plans with performance recommendations and index usage.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
# Explain a relation
|
|
9
|
+
explain User.where(active: true)
|
|
10
|
+
|
|
11
|
+
# Explain with conditions
|
|
12
|
+
explain User, active: true
|
|
13
|
+
|
|
14
|
+
# Explain a complex query
|
|
15
|
+
explain Post.joins(:user).where(users: { active: true })
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Example Output
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
═══════════════════════════════════════════════════════════
|
|
22
|
+
🔍 SQL EXPLAIN ANALYSIS
|
|
23
|
+
═══════════════════════════════════════════════════════════
|
|
24
|
+
|
|
25
|
+
SQL Query:
|
|
26
|
+
SELECT "users".* FROM "users" WHERE "users"."active" = true
|
|
27
|
+
|
|
28
|
+
Execution Time: 45ms
|
|
29
|
+
|
|
30
|
+
Query Plan:
|
|
31
|
+
Index Scan using index_users_on_active on users
|
|
32
|
+
Index Cond: (active = true)
|
|
33
|
+
Rows: 1,234
|
|
34
|
+
|
|
35
|
+
Indexes Used:
|
|
36
|
+
✓ index_users_on_active
|
|
37
|
+
|
|
38
|
+
Performance Recommendations:
|
|
39
|
+
✓ Query executed efficiently
|
|
40
|
+
✓ Appropriate index usage detected
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Code Example
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# Analyze a simple query
|
|
47
|
+
explain User.where(active: true)
|
|
48
|
+
|
|
49
|
+
# Analyze a join query
|
|
50
|
+
explain Post.joins(:user).where(users: { active: true })
|
|
51
|
+
|
|
52
|
+
# Get explain result
|
|
53
|
+
result = explain(User.where(active: true))
|
|
54
|
+
result.execution_time # => 45 (milliseconds)
|
|
55
|
+
result.indexes_used # => ["index_users_on_active"]
|
|
56
|
+
result.recommendations # => ["Query executed efficiently"]
|
|
57
|
+
|
|
58
|
+
# Export explain result
|
|
59
|
+
explain(User.where(active: true)).to_json
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Performance Recommendations
|
|
63
|
+
|
|
64
|
+
The explain command automatically detects:
|
|
65
|
+
- Sequential scans (suggests adding indexes)
|
|
66
|
+
- Full table scans
|
|
67
|
+
- Slow queries (>100ms)
|
|
68
|
+
- Missing index usage
|
|
69
|
+
- LIKE queries with leading wildcards
|
|
70
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RailsConsolePro
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
|
7
|
+
|
|
8
|
+
desc "Creates a Rails Console Pro initializer file"
|
|
9
|
+
|
|
10
|
+
def create_initializer
|
|
11
|
+
template "rails_console_pro.rb", "config/initializers/rails_console_pro.rb"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Rails Console Pro Configuration
|
|
4
|
+
# See https://github.com/yourusername/rails_console_pro for documentation
|
|
5
|
+
|
|
6
|
+
RailsConsolePro.configure do |config|
|
|
7
|
+
# Enable/disable features
|
|
8
|
+
config.enabled = true
|
|
9
|
+
config.schema_command_enabled = true
|
|
10
|
+
config.explain_command_enabled = true
|
|
11
|
+
config.stats_command_enabled = true
|
|
12
|
+
config.diff_command_enabled = true
|
|
13
|
+
config.navigate_command_enabled = true
|
|
14
|
+
config.export_enabled = true
|
|
15
|
+
|
|
16
|
+
# Printer toggles
|
|
17
|
+
config.active_record_printer_enabled = true
|
|
18
|
+
config.relation_printer_enabled = true
|
|
19
|
+
config.collection_printer_enabled = true
|
|
20
|
+
|
|
21
|
+
# Color scheme (dark or light)
|
|
22
|
+
config.color_scheme = :dark
|
|
23
|
+
|
|
24
|
+
# Style customization
|
|
25
|
+
config.max_depth = 10
|
|
26
|
+
config.show_sql_by_default = false
|
|
27
|
+
config.show_welcome_message = true
|
|
28
|
+
config.border_char = "─"
|
|
29
|
+
config.header_width = 60
|
|
30
|
+
|
|
31
|
+
# Pagination settings
|
|
32
|
+
config.pagination_enabled = true
|
|
33
|
+
config.pagination_threshold = 10 # Automatically paginate collections with 10+ items
|
|
34
|
+
config.pagination_page_size = 5 # Show 5 records per page
|
|
35
|
+
|
|
36
|
+
# Customize colors (optional)
|
|
37
|
+
# config.set_color(:header, :bright_blue)
|
|
38
|
+
# config.set_color(:attribute_key, :cyan)
|
|
39
|
+
|
|
40
|
+
# Customize type colors (optional)
|
|
41
|
+
# config.set_type_color(:string, :green)
|
|
42
|
+
# config.set_type_color(:integer, :bright_blue)
|
|
43
|
+
end
|
|
44
|
+
|