Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions entity/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "entity",
srcs = [
"batch.go",
"change_provider.go",
"request.go",
],
Expand Down
41 changes: 41 additions & 0 deletions entity/batch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package entity

// BatchState defines the possible states of a batch.
type BatchState string

const (
// BatchStateUnknown is the unreachable state. It is set by default when the structure is initialized. It should never be seen in the system.
BatchStateUnknown BatchState = ""
// TODO: Add comprehensive list of known batch states.
)

// Batch represents a group of requests to land (merge into target branch of the source control repository).
type Batch struct {
// ID is the globally unique identifier for the batch. Format: "<queue>/batch/<counter_value>".
ID string
// Queue is the name of the queue processing the land request. Queue name is defined in the configuration and should be unique within the system.
Queue string
// Contains is a list of land request IDs that are part of this batch.
// Request IDs will always be part of the same queue.
//
// For e.g. - [queueA/1, queueA/2, queueA/3].
//
Contains []string
// Dependencies is a list of batch IDs (and associated metadata) for this batch.
// Dependencies will always be part of the same queue.
//
// For e.g - Consider batches - queueA/batch/1, queueA/batch/2, queueA/batch/3
// such that - queueA/batch/2 and queueA/batch/3 depend on queueA/batch/1
//
// In this case, the Dependencies field for -
// - queueA/batch/1 will be empty
// - queueA/batch/2 will contain queueA/batch/1
// - queueA/batch/3 will contain queueA/batch/1
//
Dependencies []map[string]interface{}
// The state of the batch lifecycle this batch is in.
State BatchState
// Version is the version of the object. It is used for optimistic locking.
// Versioning starts at 1 and is incremented for each change to the object.
Version int32
}
9 changes: 9 additions & 0 deletions extension/storage/mysql/schema/batch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS batch (
id VARCHAR(255) NOT NULL,
queue VARCHAR(255) NOT NULL,
contains JSON NOT NULL,
dependencies JSON NOT NULL,
state VARCHAR(255) NOT NUll,
version INT NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;