Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More granular console SQL coloration #20607

Merged
merged 1 commit into from Jun 27, 2015

Conversation

cmtonkinson
Copy link
Contributor

This new coloration approach makes it easier to scan the rails console
for specific types of activity with more fine-grained visual cues.

Virtual terminal ANSI color escape codes are used when displaying SQL
statements in the rails console. The former implementation alternates
line prefix information (including the statement name and execution
latency) between CYAN and MAGENTA. This visually differentiates any SQL
statements in the log and is useful for quickly scanning for database
activity.

While a great idea and a solid foundation, alternating between just two
colors on an even/odd basis (much like striping an HTML table) can be
improved upon.

This patch replaces the even/odd striping with a more comprehensive
scheme that applies coloration based on the type of statement being
run. Every statement logged has its prefix (name and latency) colored
white (as the statement body was previously). The statement body is now
colored according to the nature of the statement:

  • INSERT statements are GREEN (symbolic of creation or genesis)
  • SELECT statements are BLUE (typically used for informational
    displays, as SELECT statements do not normally have side-effects)
  • DELETE statements are RED (commonly used to indicate the danger of
    a destructive action)
  • UPDATE statements are YELLOW (it's like a less extreme RED :P)
  • TRANSACTION statements are CYAN (arbitrary)
  • and any other statements are MAGENTA (again, arbitrary)

@cmtonkinson
Copy link
Contributor Author

Sample CRUD operations using a test app

rails-pr-20607-sample-output

This new coloration approach makes it easier to scan the rails console
for specific types of activity with more fine-grained visual cues.

Virtual terminal ANSI color escape codes are used when displaying SQL
statements in the rails console. The former implementation alternates
line prefix information (including the statement name and execution
latency) between CYAN and MAGENTA. This visually differentiates any SQL
statements in the log and is useful for quickly scanning for database
activity.

While a great idea and a solid foundation, alternating between just two
colors on an even/odd basis (much like striping an HTML table) can be
improved upon.

This patch replaces the even/odd striping with a more comprehensive
scheme that applies coloration based on the type of statement being
run. Every statement logged has its prefix (name and latency) colored
white (as the statement body was previously). The statement body is now
colored according to the nature of the statement:

  - INSERT statements are GREEN (symbolic of creation or genesis)
  - SELECT statements are BLUE (typically used for informational
    displays, as SELECT statements do not normally have side-effects)
  - DELETE statements are RED (commonly used to indicate the danger of
    a destructive action)
  - UPDATE statements are YELLOW (it's like a less extreme RED :P)
  - TRANSACTION statements are CYAN (arbitrary)
  - and any other statements are MAGENTA (again, arbitrary)
rafaelfranca added a commit that referenced this pull request Jun 27, 2015
@rafaelfranca rafaelfranca merged commit 261a8e1 into rails:master Jun 27, 2015
@fenec
Copy link
Contributor

fenec commented Jun 27, 2015

great stuff!

@bogdan
Copy link
Contributor

bogdan commented Jun 27, 2015

Yes looks great indeed. Consider also marking slow statements in some way.

@cmtonkinson
Copy link
Contributor Author

@bodgan now that I know there's interest in doing work on this feature, I've got a few other ideas (such as slow statement logging, rollbacks, etc)

Cheers!

@keepcosmos
Copy link
Contributor

👍

2 similar comments
@murajun1978
Copy link

👍

@mgrachev
Copy link
Contributor

mgrachev commented Jul 5, 2015

👍

@rails rails locked and limited conversation to collaborators Jul 5, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants