featurebase/dax/models/database.go
Matthew Jaffee 8fe73146c8
Sqldb rip boltdb (#2341)
* 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
2023-03-22 08:54:13 -05:00

60 lines
2.3 KiB
Go

package models
import (
"encoding/json"
"time"
"github.com/featurebasedb/featurebase/v3/dax"
"github.com/gobuffalo/pop/v6"
"github.com/gobuffalo/validate/v3"
)
// Database is used by pop to map your databases database table to your go code.
type Database struct {
// should be DatabaseID, but pop doesn't allow ID to be a custom type
ID string `json:"id" db:"id"`
Name dax.DatabaseName `json:"name" db:"name"`
WorkersMin int `json:"workers_min" db:"workers_min"`
WorkersMax int `json:"workers_max" db:"workers_max"`
Description string `json:"description" db:"description"`
Owner string `json:"owner" db:"owner"`
UpdatedBy string `json:"updated_by" db:"updated_by"`
Tables Tables `json:"tables" has_many:"tables" order_by:"name asc"`
Organization *Organization `json:"organization" belongs_to:"organization"`
OrganizationID string `json:"organization_id" db:"organization_id"`
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 (d Database) String() string {
jd, _ := json.MarshalIndent(d, " ", " ") //nolint:errchkjson
return string(jd)
}
// Databases is not required by pop and may be deleted
type Databases []Database
// String is not required by pop and may be deleted
func (d Databases) String() string {
jd, _ := json.Marshal(d) //nolint:errchkjson
return string(jd)
}
// 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 (d *Database) Validate(tx *pop.Connection) (*validate.Errors, error) {
return validate.NewErrors(), nil
}
// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
// This method is not required and may be deleted.
func (d *Database) 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 (d *Database) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
return validate.NewErrors(), nil
}