mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
* serverless sqldb use same env for test config as normal * rip boltdb implementation of controller backend out it was replaced by postgres and no longer works properly. This involved migrating a number of tests which only worked with boltdb, which exposed several ways in which the postgres implementation had slightly different behavior from the bolt one: 1. ordering of results in some cases, and 2. (more importantly) erroring when a record to delete was not found. The bolt implementation silently ignored it when things to delete weren't found, so we make some changes to match that behavior. Also stopped propagating CreatedAt and UpdatedAt from DB tables into dax types. These were breaking existing tests. Perhaps it would be better to actually use them, but for now they will only exist at the DB level. This change set also moves the insertion of the directive_versions record out of migrations and into the startup/connection code. Having this in the migrations was a bit ugly because you couldn't just truncate all the tables and have everything work from scratch. Inserting it during startup is fairly innocuous, and will just continue on if it already exists. * update directive_version test I changed the initial value to 0 so that the first version that gets sent out is 1
56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/featurebasedb/featurebase/v3/dax"
|
|
"github.com/gobuffalo/pop/v6"
|
|
"github.com/gobuffalo/validate/v3"
|
|
"github.com/gobuffalo/validate/v3/validators"
|
|
"github.com/gofrs/uuid"
|
|
)
|
|
|
|
// Node represents a host or server that is available to work on jobs.
|
|
type Node struct {
|
|
ID uuid.UUID `json:"id" db:"id"`
|
|
Address dax.Address `json:"address" db:"address"`
|
|
NodeRoles NodeRoles `json:"node_roles" has_many:"node_roles" order_by:"created_at asc"`
|
|
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
|
|
}
|
|
|
|
// String is not required by pop and may be deleted
|
|
func (t *Node) String() string {
|
|
jt, _ := json.MarshalIndent(t, " ", " ") //nolint:errchkjson
|
|
return string(jt)
|
|
}
|
|
|
|
// Nodes is not required by pop and may be deleted
|
|
type Nodes []*Node
|
|
|
|
// String is not required by pop and may be deleted
|
|
func (t Nodes) String() string {
|
|
jt, _ := json.MarshalIndent(t, " ", " ") //nolint:errchkjson
|
|
return string(jt)
|
|
}
|
|
|
|
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
|
|
// This method is not required and may be deleted.
|
|
func (t *Node) Validate(tx *pop.Connection) (*validate.Errors, error) {
|
|
return validate.Validate(
|
|
&validators.StringIsPresent{Field: string(t.Address), Name: "Address"},
|
|
), nil
|
|
}
|
|
|
|
// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
|
|
// This method is not required and may be deleted.
|
|
func (t *Node) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) {
|
|
return validate.NewErrors(), nil
|
|
}
|
|
|
|
// ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method.
|
|
// This method is not required and may be deleted.
|
|
func (t *Node) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
|
|
return validate.NewErrors(), nil
|
|
}
|