Move Ticket Name to the Participant model.
This commit is contained in:
parent
cc4dd76438
commit
2ff06bdb76
5 changed files with 20 additions and 18 deletions
14
db.go
14
db.go
|
|
@ -201,6 +201,7 @@ func migrateV2(db *sql.DB) error {
|
|||
// and links volunteers to participants via participant_id.
|
||||
func migrateV3(db *sql.DB) error {
|
||||
addColumnIfMissing(db, "volunteers", "participant_id INTEGER REFERENCES participants(id)")
|
||||
addColumnIfMissing(db, "participants", "ticket_name TEXT NOT NULL DEFAULT ''")
|
||||
|
||||
// Seed participants from volunteers first (better name data: preferred_name).
|
||||
db.Exec(`
|
||||
|
|
@ -424,6 +425,7 @@ type Participant struct {
|
|||
ID int `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PreferredName string `json:"preferred_name"`
|
||||
TicketName string `json:"ticket_name"`
|
||||
Phone string `json:"phone"`
|
||||
Pronouns string `json:"pronouns"`
|
||||
Note string `json:"note"`
|
||||
|
|
@ -860,7 +862,7 @@ func (app *App) attendeeCounts() (total, checkedIn int, err error) {
|
|||
|
||||
// --- Participants ---
|
||||
|
||||
const participantCols = `id, email, preferred_name, phone, pronouns, note, created_at, updated_at, deleted_at`
|
||||
const participantCols = `id, email, preferred_name, ticket_name, phone, pronouns, note, created_at, updated_at, deleted_at`
|
||||
|
||||
func (app *App) listParticipants(search, since string) ([]Participant, error) {
|
||||
var q string
|
||||
|
|
@ -900,8 +902,8 @@ func (app *App) getParticipantByEmail(email string) (*Participant, error) {
|
|||
|
||||
func (app *App) createParticipant(p Participant) (*Participant, error) {
|
||||
res, err := app.db.Exec(
|
||||
`INSERT INTO participants (email, preferred_name, phone, pronouns, note, updated_at) VALUES (?, ?, ?, ?, ?, ?)`,
|
||||
strings.ToLower(p.Email), p.PreferredName, p.Phone, p.Pronouns, p.Note, now(),
|
||||
`INSERT INTO participants (email, preferred_name, ticket_name, phone, pronouns, note, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
strings.ToLower(p.Email), p.PreferredName, p.TicketName, p.Phone, p.Pronouns, p.Note, now(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -912,9 +914,9 @@ func (app *App) createParticipant(p Participant) (*Participant, error) {
|
|||
|
||||
func (app *App) updateParticipant(p Participant) error {
|
||||
_, err := app.db.Exec(
|
||||
`UPDATE participants SET email=?, preferred_name=?, phone=?, pronouns=?, note=?, updated_at=?
|
||||
`UPDATE participants SET email=?, preferred_name=?, ticket_name=?, phone=?, pronouns=?, note=?, updated_at=?
|
||||
WHERE id=? AND deleted_at IS NULL`,
|
||||
strings.ToLower(p.Email), p.PreferredName, p.Phone, p.Pronouns, p.Note, now(), p.ID,
|
||||
strings.ToLower(p.Email), p.PreferredName, p.TicketName, p.Phone, p.Pronouns, p.Note, now(), p.ID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
|
@ -957,7 +959,7 @@ func queryParticipants(db *sql.DB, q string, args ...any) ([]Participant, error)
|
|||
for rows.Next() {
|
||||
var p Participant
|
||||
if err := rows.Scan(
|
||||
&p.ID, &p.Email, &p.PreferredName, &p.Phone, &p.Pronouns, &p.Note,
|
||||
&p.ID, &p.Email, &p.PreferredName, &p.TicketName, &p.Phone, &p.Pronouns, &p.Note,
|
||||
&p.CreatedAt, &p.UpdatedAt, &p.DeletedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue