2026-03-03 11:27:07 -06:00
|
|
|
import Dexie from 'dexie'
|
|
|
|
|
|
|
|
|
|
export const db = new Dexie('turnpike')
|
|
|
|
|
|
|
|
|
|
db.version(1).stores({
|
|
|
|
|
session: 'id, token, user',
|
|
|
|
|
meta: 'key',
|
|
|
|
|
event: 'id',
|
|
|
|
|
attendees: 'id, name, ticket_type, checked_in, deleted_at',
|
|
|
|
|
departments: 'id, name, deleted_at',
|
|
|
|
|
volunteers: 'id, name, department_id, checked_in, attendee_id, deleted_at',
|
|
|
|
|
shifts: 'id, department_id, day, deleted_at',
|
|
|
|
|
volunteer_shifts: '[volunteer_id+shift_id], volunteer_id, shift_id',
|
|
|
|
|
outbox: '++id, table, op, synced_at',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
db.version(2).stores({
|
|
|
|
|
session: 'id, token, user',
|
|
|
|
|
meta: 'key',
|
|
|
|
|
event: 'id',
|
|
|
|
|
attendees: 'id, name, ticket_type, checked_in, volunteer_token, deleted_at',
|
|
|
|
|
departments: 'id, name, deleted_at',
|
|
|
|
|
volunteers: 'id, name, department_id, checked_in, attendee_id, deleted_at',
|
|
|
|
|
shifts: 'id, department_id, day, position, deleted_at',
|
|
|
|
|
volunteer_shifts: '[volunteer_id+shift_id], volunteer_id, shift_id',
|
|
|
|
|
outbox: '++id, table, op, synced_at',
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-04 10:53:42 -06:00
|
|
|
db.version(3).stores({
|
|
|
|
|
session: 'id, token, user',
|
|
|
|
|
meta: 'key',
|
|
|
|
|
event: 'id',
|
|
|
|
|
attendees: 'id, name, ticket_type, checked_in, volunteer_token, deleted_at',
|
|
|
|
|
participants: 'id, email, preferred_name, updated_at, deleted_at',
|
|
|
|
|
tickets: 'id, participant_id, code, source, checked_in_at, updated_at, deleted_at',
|
|
|
|
|
departments: 'id, name, deleted_at',
|
|
|
|
|
volunteers: 'id, name, department_id, checked_in, attendee_id, participant_id, deleted_at',
|
|
|
|
|
shifts: 'id, department_id, day, position, deleted_at',
|
|
|
|
|
volunteer_shifts: '[volunteer_id+shift_id], volunteer_id, shift_id',
|
|
|
|
|
outbox: '++id, table, op, synced_at',
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-04 15:27:03 -06:00
|
|
|
db.version(4).stores({
|
|
|
|
|
attendees: null,
|
|
|
|
|
outbox: null,
|
|
|
|
|
volunteers: 'id, name, department_id, checked_in, participant_id, deleted_at',
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-06 07:11:19 -06:00
|
|
|
db.version(5).stores({
|
|
|
|
|
volunteers: 'id, participant_id, department_id, deleted_at',
|
|
|
|
|
participants: 'id, email, preferred_name, email_confirmed, updated_at, deleted_at',
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-10 14:24:51 -05:00
|
|
|
db.version(6).stores({}).upgrade(async tx => {
|
|
|
|
|
await tx.table('session').clear()
|
|
|
|
|
await tx.table('meta').clear()
|
|
|
|
|
await tx.table('participants').clear()
|
|
|
|
|
await tx.table('tickets').clear()
|
|
|
|
|
await tx.table('departments').clear()
|
|
|
|
|
await tx.table('volunteers').clear()
|
|
|
|
|
await tx.table('shifts').clear()
|
|
|
|
|
await tx.table('volunteer_shifts').clear()
|
|
|
|
|
})
|
2026-03-10 14:08:00 -05:00
|
|
|
|
2026-03-03 11:27:07 -06:00
|
|
|
export async function getLastSync() {
|
|
|
|
|
const m = await db.meta.get('last_sync')
|
|
|
|
|
return m?.value ?? ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function setLastSync(ts) {
|
|
|
|
|
await db.meta.put({ key: 'last_sync', value: ts })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getSession() {
|
|
|
|
|
return db.session.get(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function saveSession(token, user) {
|
|
|
|
|
await db.session.put({ id: 1, token, user })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function clearSession() {
|
|
|
|
|
await db.session.clear()
|
|
|
|
|
await db.meta.clear()
|
|
|
|
|
}
|