Documentation
¶
Overview ¶
Package schema describes the Auth-All database schema independently from a specific database engine. Core and plugins contribute tables. A dialect renderer turns the effective schema into deterministic SQL.
Index ¶
- Constants
- type Column
- type Dialect
- type Extension
- type ForeignKey
- type IDType
- type Index
- type Names
- type Options
- type Schema
- func (s *Schema) Add(t Table) error
- func (s *Schema) AddUnit(u Unit) error
- func (s *Schema) Extend(e Extension) error
- func (s *Schema) Names() Names
- func (s *Schema) Options() Options
- func (s *Schema) Table(name string) (Table, bool)
- func (s *Schema) Tables() []Table
- func (s *Schema) Units() ([]Unit, error)
- type Statement
- type Table
- type Type
- type Unit
- type UserField
Constants ¶
const ( TableUsers = DefaultPrefix + baseUsers TableCredentials = DefaultPrefix + baseCredentials TableAccounts = DefaultPrefix + baseAccounts TableSessions = DefaultPrefix + baseSessions TableTokens = DefaultPrefix + baseTokens TableOAuthStates = DefaultPrefix + baseOAuthStates TableTOTP = DefaultPrefix + baseTOTP TableTOTPRecovery = DefaultPrefix + baseTOTPRecovery )
Core table names. They hold the v1 names, which the default prefix produces. A schema with another prefix uses Schema.Names instead.
const DefaultPrefix = "auth_"
DefaultPrefix is the prefix of every Auth-All object when the host sets no other value. It keeps the v1 names.
const MigrationTable = DefaultPrefix + baseMigrations
MigrationTable holds the applied statement IDs. It is the v1 name. A schema with another prefix uses Names().Migrations instead.
const OwnerCore = "core"
OwnerCore names the owner of the core migration units.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
Name string
Type Type
Nullable bool
PrimaryKey bool
// Default is the rendered SQL default. An empty value adds no default.
Default string
}
Column describes one column.
type Extension ¶ added in v0.3.0
type Extension struct {
// Table is the physical name of the target table.
Table string
// Columns are the added columns. An added column is nullable, or it has a
// default, because the target table can already hold rows.
Columns []Column
// Indexes are the added indexes.
Indexes []Index
}
Extension adds columns and indexes to a table that another owner declared.
type ForeignKey ¶
type ForeignKey struct {
Column string
RefTable string
RefColumn string
OnDelete string // CASCADE or SET NULL. Empty means no action.
}
ForeignKey describes one foreign key constraint.
type IDType ¶ added in v0.3.0
type IDType string
IDType selects the physical type of every primary key and foreign key.
type Names ¶ added in v0.3.0
type Names struct {
Users string
Credentials string
Accounts string
Sessions string
Tokens string
OAuthStates string
TOTP string
TOTPRecovery string
APIKeys string
RateLimits string
Bootstrap string
Migrations string
}
Names holds the physical name of every Auth-All table.
func DefaultNames ¶ added in v0.3.0
func DefaultNames() Names
DefaultNames returns the v1 table names.
func TableNames ¶ added in v0.3.0
TableNames returns the physical table names for the options.
type Options ¶ added in v0.3.0
type Options struct {
// Prefix starts every table name, index name, and record table name.
Prefix string
// IDType selects the physical type of the identifier columns.
IDType IDType
// UserFields are host-owned columns on the users table.
UserFields []UserField
}
Options configure the physical schema.
func DefaultOptions ¶ added in v0.3.0
func DefaultOptions() Options
DefaultOptions returns the v1 physical schema.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the effective set of tables.
func NewCore ¶
NewCore returns a schema that already contains the core tables with the v1 physical options.
func NewCoreWithOptions ¶ added in v0.3.0
NewCoreWithOptions returns a schema that already contains the core tables for the given physical options.
func NewWithOptions ¶ added in v0.3.0
NewWithOptions returns an empty schema with the given physical options.
func (*Schema) AddUnit ¶ added in v0.3.0
AddUnit registers one migration unit. A unit that creates a table must also name the table in Creates.
func (*Schema) Extend ¶ added in v0.3.0
Extend adds columns and indexes to a table that another owner declared.
type Statement ¶
Statement is one identified DDL statement.
The ID is stable across runs and identifies the statement in the applied migration record.
type Table ¶
type Table struct {
Name string
Columns []Column
Indexes []Index
ForeignKeys []ForeignKey
}
Table describes one table.
func CoreTables ¶ added in v0.3.0
CoreTables returns the effective core Auth-All schema for the given physical options. It is the v1 tables plus every later core extension.
type Unit ¶ added in v0.3.0
type Unit struct {
// Version is a 14-digit timestamp. It orders the units.
Version string
// Owner is OwnerCore or a plugin identifier.
Owner string
// Name is the unit name without the version.
Name string
// Up holds the forward statements of each dialect.
Up map[Dialect][]Statement
// Down holds the reverse statements of each dialect.
Down map[Dialect][]Statement
// Creates names the tables that the unit creates. The schema uses it to
// find a table that no unit covers.
Creates []string
}
Unit is one versioned and immutable set of DDL statements with one owner.
A released unit never changes. A later release adds a new unit instead, so a host that applied the earlier file keeps a valid database.
type UserField ¶ added in v0.3.0
type UserField struct {
// Name is the column name.
Name string
// Type is the column type.
Type Type
// Nullable allows a null value.
Nullable bool
// Default is the rendered SQL default. An empty value adds no default.
Default string
// Input allows an HTTP route to write the field. The default is false.
Input bool
// Returned allows a response to carry the field. The default is false.
Returned bool
}
UserField is one host-owned column on the users table.