Rails console command made easier

Command trong rails thực sự rất là nhiều và củng không nhớ hết được syntax. Đâu đó thì củng chỉ nhớ được 1 vài task hay dùng, thay vì mỗi lần như vậy mình phải gõ cmd bin/rails -T để xem các command line có sẵn

Ruby
rails db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_...
rails db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_EN...
rails db:encryption:init  # Generate a set of keys for configuring Active Record encryption in a given environment
rails db:environment:set  # Set the environment value for the database
rails db:fixtures:load  # Loads fixtures into the current environment's database
rails db:migrate  # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
rails db:migrate:down # Runs the "down" for a given migration VERSION
rails db:migrate:redo # Rolls back the database one migration and re-migrates up (options: STEP=x, VERSION=x)
rails db:migrate:status # Display status of migrations
rails db:migrate:up # Runs the "up" for a given migration VERSION
rails db:prepare # Runs setup if database does not exist, or runs migrations if it does
rails db:reset # Drops and recreates all databases from their schema for the current environment and ...
rails db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
rails db:schema:cache:clear # Clears a db/schema_cache.yml file
rails db:schema:cache:dump  # Creates a db/schema_cache.yml file
rails db:schema:dump  # Creates a database schema file (either db/schema.rb or db/structure.sql, depending on...
rails db:schema:load  # Loads a database schema file (either db/schema.rb or db/structure.sql, depending on ...
rails db:seed # Loads the seed data from db/seeds.rb
rails db:seed:replant # Truncates tables of each database for current environment and loads the seeds
rails db:setup  # Creates all databases, loads all schemas, and initializes with the seed data (use db...
rails db:version  # Retrieves the current schema version number
rails test:db # Run tests quickly, but also reset db

Thay vì phải nhớ hết như vậy thì ta nên thiết lập alias cho đơn giản.

Thiết lập alias tại: vi ~/.bashrc

Ruby
alias br='bin/rails'
alias be='bundle exec'
alias brdm='bin/rails db:migrate RAILS_ENV=development && bin/rails db:migrate RAILS_ENV=test'
alias brdrol='bin/rails db:rollback STEP=1 && bin/rails db:rollback STEP=1 RAILS_ENV=test'
alias bi='bundle install'
alias ees="export EDITOR='subl -w'"
alias bd="./bin/dev"
alias brdcm="br db:drop db:create db:migrate"
alias brdcms="br db:drop db:create db:migrate db:seed"
alias rcr="bin/rails cypress:run"
alias rco="bin/rails cypress:open"
alias resetdbtest='bin/rails db:drop db:create db:migrate RAILS_ENV=test'
alias resetdbdev='bin/rails db:drop db:create db:migrate RAILS_ENV=development'
alias brg='bin/rails generate'
alias brt='bin/rails test'
alias fd="foreman start -f Procfile.dev"

Happy Coding!

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
Read More

MOVE ON

Trong cuộc sống thường ngày đang có rất nhiều người bị mắc kẹt trong những nỗi đau từ…