Documentation
¶
Overview ¶
Package imports is the batch record of a history import (design: history-import-design.md section 4): one row of the imports table per commit, the drives and charges it brought in carry its id (import_id), and Undo removes them all in one transaction.
Nothing here parses a file or decides what a row is; it records, finds and undoes batches. The filename column holds "<source>.<ext>", never the name the user gave the file (it can carry a name or an email).
Index ¶
- Variables
- type AlreadyImported
- type Batch
- type Counts
- type Item
- type Store
- func (s *Store) Begin(ctx context.Context, b Batch) (uuid.UUID, error)
- func (s *Store) Check(ctx context.Context, source, sha string) error
- func (s *Store) Finish(ctx context.Context, id uuid.UUID, c Counts) error
- func (s *Store) List(ctx context.Context) ([]Item, error)
- func (s *Store) Started(ctx context.Context, since time.Time) (int, error)
- func (s *Store) Undo(ctx context.Context, id uuid.UUID) (Undone, error)
- type Undone
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound: no such batch for this user, or it is already undone. ErrNotFound = errors.New("imports: no such import") )
Functions ¶
This section is empty.
Types ¶
type AlreadyImported ¶
AlreadyImported is returned by Begin when this user has a live (not undone) batch of the same source and file hash.
func (*AlreadyImported) Error ¶
func (e *AlreadyImported) Error() string
type Batch ¶
type Batch struct {
Source string // "tezlab_import" style source name; a lowercase identifier
Ext string // the file's extension without the dot ("csv", "xlsx"); the filename stored is Source + "." + Ext
SHA256 string // lowercase hex of the uploaded bytes
Bytes int64
VehicleID *uuid.UUID // the vehicles.id the rows go to, nil when the file covers none yet
Metadata map[string]any
}
Batch is what a commit records about itself when it starts.
type Counts ¶
type Counts struct {
Rows, Drives, Charges, Skipped int
}
Counts is what a commit reports when it ends.
type Item ¶
type Item struct {
ID uuid.UUID `json:"id"`
Source string `json:"source"`
StartedAt time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
UndoneAt *time.Time `json:"undone_at,omitempty"`
Rows int `json:"rows"`
Drives int `json:"drives"`
Charges int `json:"charges"`
Skipped int `json:"skipped"`
First string `json:"first,omitempty"`
Last string `json:"last,omitempty"`
}
Item is one row of the user's import list.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store records batches for one user.
func (*Store) Begin ¶
Begin records a new batch and returns its id. A live batch of the same source and file hash for this user refuses it with *AlreadyImported (the unique index imports_user_sha_live, which Undo frees): two concurrent commits of one file give exactly one batch.
func (*Store) Check ¶
Check reports a live batch of this source and file hash as *AlreadyImported, nil when there is none. It writes nothing (the preview's "already imported on <date>").
func (*Store) Started ¶
Started counts the batches this user began since t, undone ones included: the commit rate limit.
func (*Store) Undo ¶
Undo deletes every drive and charge the batch brought in (with the per-drive rows), and marks the batch undone, in one transaction. The same file can then be imported again. Notes or tags the user added to those rows go with them. ErrNotFound when the batch is not this user's or is already undone.