diff --git a/nomad/state/schema.go b/nomad/state/schema.go index f61b1d109..535024c7c 100644 --- a/nomad/state/schema.go +++ b/nomad/state/schema.go @@ -20,6 +20,7 @@ func stateStoreSchema() *memdb.DBSchema { nodeTableSchema, jobTableSchema, jobSummarySchema, + jobHistorySchema, periodicLaunchTableSchema, evalTableSchema, allocTableSchema, @@ -141,6 +142,37 @@ func jobSummarySchema() *memdb.TableSchema { } } +// jobHistorySchema returns the memdb schema for the job history table which +// keeps a historical view of jobs. +func jobHistorySchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "job_histories", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + + // Use a compound index so the tuple of (JobID, Version) is + // uniquely identifying + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "JobID", + Lowercase: true, + }, + + // Will need to create a new indexer + &memdb.UintFieldIndex{ + Field: "Version", + }, + }, + }, + }, + }, + } +} + // jobIsGCable satisfies the ConditionalIndexFunc interface and creates an index // on whether a job is eligible for garbage collection. func jobIsGCable(obj interface{}) (bool, error) {