migrateDB creates the votes table if it does not already exist.
(db *sql.DB)
| 48 | |
| 49 | // migrateDB creates the votes table if it does not already exist. |
| 50 | func migrateDB(db *sql.DB) error { |
| 51 | createVotes := `CREATE TABLE IF NOT EXISTS votes ( |
| 52 | id SERIAL NOT NULL, |
| 53 | created_at timestamp NOT NULL, |
| 54 | candidate VARCHAR(6) NOT NULL, |
| 55 | PRIMARY KEY (id) |
| 56 | );` |
| 57 | _, err := db.Exec(createVotes) |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | // recentVotes returns the last five votes cast. |
| 62 | func recentVotes(db *sql.DB) ([]vote, error) { |