Description
Please share this gem with your friends to get more feedback. I would really appreciate for the gem review if you have a blog. If you have ideas - please create an issue or contact me by email: igorkasyanchuk[@]gmail.com.
Quick way to inspect your Rails database http://localhost:12345/rails/db, see content of tables, export them to CSV, EXPLAIN SQL and run SQL queries.
Demo available on: https://rails-db.herokuapp.com/rails/db/
Video Demos: https://youtu.be/TYsRxXRFp1g, https://youtu.be/dfViQPZw9zE
Rails DB alternatives and similar gems
Based on the "Database Tools" category.
Alternatively, view Rails DB alternatives based on common mentions on social networks and blogs.
-
Database Cleaner
Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing. -
Lol DBA
lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts. -
Seed Fu
Advanced seed data handling for Rails, combining the best practices of several methods together. -
Seedbank
Seedbank gives your seed data a little structure. Create seeds for each environment, share seeds between environments and specify dependencies to load your seeds in order. All nicely integrated with simple rake tasks. -
DatabaseConsistency
The tool to avoid various issues due to inconsistencies and inefficiencies between a database schema and application models. -
Polo
Polo travels through your database and creates sample snapshots so you can work with real world data in development. -
SchemaPlus
DISCONTINUED. SchemaPlus provides a collection of enhancements and extensions to ActiveRecord -
Upsert
Upsert on MySQL, PostgreSQL, and SQLite3. Transparently creates functions (UDF) for MySQL and PostgreSQL; on SQLite3, uses INSERT OR IGNORE. -
OnlineMigrations
Catch unsafe PostgreSQL migrations in development and run them easier in production (code helpers for table/column renaming, changing column type, adding columns with default, background migrations, etc). -
Ruby PG Extras
Ruby PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more. -
Slack Smart Bot
Create a Slack bot that is smart and so easy to expand, create new bots on demand, run ruby code on chat, create shortcuts... The main scope of this gem is to be used internally in the company so teams can create team channels with their own bot to help them on their daily work, almost everything is suitable to be automated!! slack-smart-bot can create bots on demand, create shortcuts, run ruby code... just on a chat channel. You can access it just from your mobile phone if you want and run those tests you forgot to run, get the results, restart a server... no limits. -
PgDriveBackup
Simple solution to make encrypted with ccrypt PostgreSQL backups and storing on Google Drive API -
Perfect Shape
Perfect Shape is a collection of geometric algorithms that are mostly useful for GUI manipulation like checking containment of a point in popular geometric shapes such as rectangle, square, arc, circle, polygon, and paths containing lines, quadratic bézier curves, and cubic bezier curves. Also, some general math algorithms like IEEE-754 Remainder. -
ActiveRecord Setops
Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll). -
Rapidity
Simple but fast Redis-backed distributed rate limiter. Allows you to specify time interval and count within to limit distributed operations. -
PRY-BYETYPO 👋
A Pry plugin that captures exceptions that may arise from typos and deduces the correct command.
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Rails DB or a related project?
README
Rails DB
Please share this gem with your friends to get more feedback. I would really appreciate for the gem review if you have a blog. If you have ideas - please create an issue or contact me by email: igorkasyanchuk[@]gmail.com
.
Quick way to inspect your Rails database http://localhost:12345/rails/db, see content of tables, export them to CSV, EXPLAIN SQL and run SQL queries.
Demo available on: https://rails-db.herokuapp.com/rails/db/
Video Demos: https://youtu.be/TYsRxXRFp1g, https://youtu.be/dfViQPZw9zE
Requirements
Version >2.0
100% works with Ruby 2.3+, and Rails 5 and Rails 6 (2.3.1 requires >= Rails 6, for Rails 5 use 2.2.1). As for other versions of RoR use 1.6 version of gem. Also there are automated tests running on Travis CI.
Supports: PostgreSQL, MySQL, SQLite. Not sure about other adapters. Since gem is using ActiveRecord it will work with others DBs.
For older versions of Rails (Rails 3.2, 4.X) please user gem "rails_db", "1.6"
.
Note (!)
Gem works with ruby 1.9.3 but you need to use kaminari < 1.0.0 gem and rails_db <= 1.6. Please add to gemfile gem 'kaminari', '< 1.0.0'
.
Main Features
- command line tools
railsdb
andrunsql
to run app and sql for your apps. - view content and schema of DB tables (including indexes)
- create, edit content
- sort content of DB tables
- filtering data (multiple filters supported too)
- execute SQL queries
- autocomplete for SQL queries
- filter tables for easier navigation
- show/hide columns in tables
- use history of you SQL queries
- see EXPLAIN results for your queries
- export data to CSV and Excel
- import SQL files
- expand/collapse sidebar
- hide/show columns
- allow access for current user for example with appropriate role
- added HTTP_BASIC auth for Rails DB
- ability to turn on/off using initializer
- white/black list of tables
- data-tables inside your app
- ajax-ify Rails DB
- delete records, truncate tables
- visualize SQL schema (future)
- CRUD for table records (future)
Install
Add this to the development group in your Gemfile
For all environments (be careful with production environment):
# Rails >= 6
gem 'rails_db', '>= 2.3.1'
# Rails < 6
gem 'rails_db', '2.2.1'
Or only for development:
group :development do
# Rails >= 6
# and there are is a big change it will work with Rails 5.2 too
gem 'rails_db', '>= 2.3.1'
# Rails < 6
gem 'rails_db', '2.2.1'
end
Run bundle install
Visit http://localhost:3000/rails/db
and you will see your database tables and SQL editors.
Use port 12345 if running in 'standalone' mode
Optionally, add gem 'caxlsx_rails'
to your application's Gemfile to be able to export to excel .xlsx
files.
Customization
If you want to customize gem (create initializer) run in console:
rails g rails_db initializer
If will create file config/initializers/rails_db.rb.
Options
- enabled - enable or disable gem (default: true).
- automatic_routes_mount - automatically mount engine routes in your app (default: true).
- http_basic_authentication_enabled - Enable HTTP_BASIC authentication (default: false).
- http_basic_authentication_user_name - HTTP_BASIC authentication user name.
- http_basic_authentication_password - HTTP_BASIC authentication password.
- black_list_tables - black list for tables (hide tables from sidebar).
- white_list_tables - black list for tables (show only these tables in sidebar).
- verify_access_proc - allow access by specific conditions, for example by role for current_user, or
you can use for example Pundit here (default:
proc { |controller| true }
) - sandbox - allow only read-only queries (https://github.com/igorkasyanchuk/rails_db/pull/122)
If you want to add routes manually (or customize the mounted location) you need to first turn off automatic_routes_mount and then add to your routes.rb
mount RailsDb::Engine => '/rails/db', :as => 'rails_db'
If you wanted to only allow access to admins and, for example, you are using Devise you could do following (in config/initializers/rails_db.rb
)
config.verify_access_proc = proc { |controller| controller.current_user.admin? }
Data Tables
You can easily embed data-tables into your App with content from DB.
You can build data tables for the whole Table, Table with specific columns or based on SQL query.
Below you can see samples on how you can embed data-tables directly in your app.
<h3>Table</h3>
<%= rails_db_data_table 'accounts',
footer: true,
columns: ['id', 'name', 'users_count'],
header: true,
style: :bootstrap %>
<h3>SQL</h3>
<%= rails_db_data_table_sql 'select id, name, age from users order by age desc limit 10',
footer: false,
header: true %>
Samples & Screenshots
Schema
SQL Editor
Rails App SQL editor with syntax highlight and code complete.
Install & visit http://localhost:3000/rails/db
to see it in action.
RailsDB Standalone
Run RailsDB Standalone commands locally withing configuration of your config/database.yml
.
RailsDB Standalone and runsql doesn't require to be added to Gemfile or you application.
RunSQL Util
Run SQL commands locally withing configuration of your config/database.yml
Edit Content in Rails DB
===
++There is a dependency on MySQL. You may need to gem install mysql2 -v '0.3.20'
Contributing
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Added some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request
Local Development
- Checkout it
- cd test/dummy
- bundle
- rake db:migrate
- rails s -b 0.0.0.0
- open http://locahost:3000/
Local Build
- in gem root folder run
gem build rails_db.gemspec
- then try to install local version of the gem
gem install rails_db-0.X.X.gem
- now you can use this gem locally
- don't forget to uninstall it
Run Tests
To run tests locally you need to execute rake test
withing root folder of project.
After your push to git, all tests will be executed on Travis CI environment.
You can also change locally DB to verify gem accross multiple Databases (mysql, postgres, sqlite). For more details see test/dummy/config/database.yml
(you need to set DB ENV variable).
On CI tests are executed with BUNDLE_GEMFILE=./gemfiles/rails_6_0.gemfile rails test
.
Common Issues and Solutions
- "Invalid css error" - https://github.com/igorkasyanchuk/rails_db/issues/11
- "Automatic routes mounting" - https://github.com/igorkasyanchuk/rails_db/issues/4
- gems(mysql, pg) are not found - RailsDB doesn't have any strict dependency inside. So you need to install gems manually
gem install pg
orgem install mysql -v=0.3.18
. - "ActionView::Template::Error (No input found for
jsonb
):" - https://github.com/igorkasyanchuk/rails_db/issues/39 - issue with Ransack gem (in rails_db
search
method is removed), try to use methodransack
instead becausesearch
is deprectated.
Plans
- Add more tests
- Verify all environments
- Add DB schema visualization
- Create WIKI pages, improve documentation
- Add favicon for standalone and dummy apps
- Add ERD schema
Other stuff
As a good addition to this gem (or as separate utility) you can use this gem: https://github.com/igorkasyanchuk/execute_sql which allows to execute SQL in rails console or app.
License
This project uses MIT-LICENSE.
*Note that all licence references and agreements mentioned in the Rails DB README section above
are relevant to that project's source code only.