mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Switch Serverless from using BoltDB to Postgres as metadata store. Previously, the controller stored all metadata to BoltDB. This implements SQLDB (currently Postgres flavored) as the backing store for metadata. This will allow us to have multiple instances of the controller running for HA, and to easily inspect and repair the contents of the metadata store. Unfortunately, it was not straightforward to keep the BoltDB implementation working alongside the SQL one, so it will be removed in a later patch. Once that's done, the SQL implementation should allow for a number of simplifications of the schemar and balancer interfaces. Database migration is built directly into the application by embedding the migration files and logic from the `soda` command line tool. When connecting to the RDBMS, the app will always attempt to create the necessary database and apply any outstanding migrations. Integration tests truncate all tables upon start, but *not* at the end, so the state of the database can be inspected after integration tests. Had to refactor some of the controller's background tasks to make sure they get properly shut down on controller exit.
67 lines
2.7 KiB
Go
67 lines
2.7 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"
|
|
)
|
|
|
|
// Table is used by pop to map your tables database table to your go code.
|
|
type Table struct {
|
|
// ID will store the dax.Table.Key(), but must be string type due to pop's nonsense
|
|
ID string `json:"id" db:"id"`
|
|
Name dax.TableName `json:"name" db:"name"`
|
|
Owner string `json:"owner" db:"owner"`
|
|
UpdatedBy string `json:"updated_by" db:"updated_by"`
|
|
Database *Database `json:"database" belongs_to:"database"`
|
|
DatabaseID string `json:"database_id" db:"database_id"`
|
|
OrganizationID dax.OrganizationID `json:"organization_id" db:"organization_id"`
|
|
Description string `json:"description" db:"description"`
|
|
PartitionN int `json:"partition_n" db:"partition_n"`
|
|
Columns Columns `json:"columns" has_many:"columns" 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 *Table) String() string {
|
|
jt, _ := json.MarshalIndent(t, " ", " ") //nolint:errchkjson
|
|
return string(jt)
|
|
}
|
|
|
|
// Tables is not required by pop and may be deleted
|
|
type Tables []*Table
|
|
|
|
// String is not required by pop and may be deleted
|
|
func (t Tables) 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 *Table) Validate(tx *pop.Connection) (*validate.Errors, error) {
|
|
return validate.Validate(
|
|
&validators.StringIsPresent{Field: string(t.Name), Name: "Name"},
|
|
&validators.StringIsPresent{Field: t.Owner, Name: "Owner"},
|
|
&validators.StringIsPresent{Field: t.UpdatedBy, Name: "UpdatedBy"},
|
|
&validators.StringIsPresent{Field: t.Description, Name: "Description"},
|
|
&validators.IntIsPresent{Field: t.PartitionN, Name: "PartitionN"},
|
|
), nil
|
|
}
|
|
|
|
// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
|
|
// This method is not required and may be deleted.
|
|
func (t *Table) 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 *Table) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
|
|
return validate.NewErrors(), nil
|
|
}
|