Isn’t a database just a spreadsheet? No?! Oh man!
A database makes a website a web application…don’t take this power lightly. How do I interact with the data? How do I get this data to interact with that other data? Why is it so hard to access the frickin’ data?! Wait, what happened to all my data? There is much to learn, to remember, and to respect about working with databases.

Debugging & learning SQL in the rails console

11/19/15  Public, Databases, Troubleshooting, Other Languages

Sometimes examining the SQL generated by ActiveRecord query and finder methods can be useful in debugging and learning SQL. Rails' ActiveRecord provides the to_sql method to make this easy.

Open up the rails console with rails c or `rails c...

2 votes - eliotsykes

Adding a unique constraint to a Postgres database column

08/11/15  Public, Databases

class AddUniqueConstraintToVolunteerPhoneNumber < ActiveRecord::Migration
  def change
    reversible do |dir|
      dir.up do
        execute 'ALTER TABLE volunteers ADD CONSTRAINT unique_phone UNIQUE (phone_number)'

1 vote - harrylevine

Command to access your Rails sqlite3 database from the command line

03/28/15  Public, Databases

$ sqlite3 db/development.sqlite3

Run .tables to get a list of database tables, to confirm you are in the right place

Then run .help for list of available commands

Reference site:

1 vote - harrylevine

Summary of rake database migration commands in development

11/16/14  Public, Command Line, Databases

$ rake db:migrate
$ rake db:migrate VERSION=0 --> Removes all migrations, resetting back to ground zero
$ rake db:migrate VERSION=20141013165213 --> Migrates back down to the specific named migration
$ rake db:migrate:status --> *P...

3 votes - plawler

Rails database column migration methods

11/15/14  Public, Databases, Rails General

add_column(table, column, type, options)
remove_column(table, column)
rename_column(table, column, new_name)
change_column(table, column, type, options)

1 vote - brookemcg