Performance: Column types and attributes
This affects database query speed and page load time by influencing how data is stored and retrieved.
t.integer :age
t.string :age
| Pattern | Data Size | Query Speed | Index Efficiency | Verdict |
|---|---|---|---|---|
| Using string for numbers | High | Slow | Poor | [X] Bad |
| Using integer for numbers | Low | Fast | Good | [OK] Good |
| Boolean without default | Medium | Slower | Average | [!] OK |
| Boolean with default and not null | Low | Faster | Good | [OK] Good |
title with a default value 'Untitled' in a Rails migration?create_table :users do |t| t.integer :age, null: false, default: 18 t.boolean :active, default: true end
active for a new user if not specified?add_column :orders, :price, :integer, null: true, default: 0
status column to your tasks table that stores short text but limits it to 10 characters, defaults to 'pending', and cannot be null. Which migration line is correct?Pass the test and this pattern moves unknown