SQL is the language used to talk to a database.
database.yml, you can run
INSERT ... SELECT
You don't need to read or use all of the resources below. Just pick some that work for you.
db/schema.rb is useful get a first impression of a Rails app's database model. It contains a compact description of all tables and columns in the app's database:
ActiveRecord::Schema.define(version: 2021_07_05_075620) do create_table "bookings", force: :cascade do |t| t.bigint "desk_id" t.datetime "start_time" t.datetime "end_time" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["desk_id"], name: "index_bookings_on_desk_id" t.index ["user_id"], name: "index_bookings_on_user_id" end create_table "desks", force: :cascade do |t| t.string "code" t.text "notes" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.boolean "bookable" t.index ["bookable"], name: "index_desks_on_bookable" t.index ["code"], name: "index_desks_on_code" t.index ["room_id"], name: "index_desks_on_room_id" end end
Each of the
create_table blocks corresponds to a statement that can be used to re-create the database structure.
Most Rails apps followwhen designing their table and columns. Because there is a standard way of modelling and naming things, it's easy to guess how a Rails app stores its data.
Browse through the
schema.rb of all sample apps that you checked out at the beginning of this curriculum. Just by looking at the table and column names you should get an idea what these applications do.
In an earlier lesson you cloned the code for the makandra cards app.
Import the staging database into your local database. There is atask to help you with that.
Start the server and sign up as a new user.
Now do the following things in a database console:
Come up with a database schema for the fictional apps below.
To describe the schema you can use any format that your mentor understands. For instance, an
schema.rb above, or a set of
CREATE TABLE statements.
It is sufficient to only use the most essential record properties for this exercise. E.g. in most cases it is enough for a user to have a name, e-mail and password (hash), even though in a real schema there may be many more columns.
A schema is easier to use the fewer tables it has. Try to minimize the number of tables you need.