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 OrganizationNames
- 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
- func CoreUnits(o Options) ([]Unit, error)
- func ExtensionUnit(version, owner, name string, d []Dialect, extensions []Extension) (Unit, error)
- func OrganizationUnits(owner string, o Options) ([]Unit, error)
- func TableUnit(version, owner, name string, d []Dialect, tables []Table) (Unit, error)
- func UnitsFor(o Options, extra []Unit) ([]Unit, error)
- 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 ( TableOrganizations = DefaultPrefix + baseOrganizations TableOrgMembers = DefaultPrefix + baseOrgMembers TableOrgInvitations = DefaultPrefix + baseOrgInvites TableOrgRoles = DefaultPrefix + baseOrgRoles TableOrgTeams = DefaultPrefix + baseOrgTeams TableOrgTeamMembers = DefaultPrefix + baseOrgTeamMember )
Organization table names with the default prefix.
const ( VersionOrganizations = "20261101000001" VersionOrgMembers = "20261101000002" VersionOrgInvites = "20261101000003" VersionOrgRoles = "20261101000004" VersionOrgTeams = "20261101000005" VersionOrgColumns = "20261101000006" )
Versions of the organization migration units. A released unit never changes.
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.
func SessionOrganizationExtension ¶ added in v0.4.0
SessionOrganizationExtension returns the column that carries the active organization of one session. The column is nullable, so the unit applies to a database that already holds rows.
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
// OrgFields are host-owned columns on the organizations table. They apply
// only when the organizations plugin is enabled.
OrgFields []UserField
}
Options configure the physical schema.
func DefaultOptions ¶ added in v0.3.0
func DefaultOptions() Options
DefaultOptions returns the v1 physical schema.
type OrganizationNames ¶ added in v0.4.0
type OrganizationNames struct {
Organizations string
Members string
Invitations string
Roles string
Teams string
TeamMembers string
}
OrganizationNames returns the physical names of the organization tables.
func OrgTableNames ¶ added in v0.4.0
func OrgTableNames(o Options) OrganizationNames
OrgTableNames returns the physical organization table names for the options.
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.
func OrganizationTables ¶ added in v0.4.0
OrganizationTables returns the tables of the organizations plugin. The plugin contributes them, so an application that enables no organization gets no table.
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.
func ExtensionUnit ¶ added in v0.4.0
ExtensionUnit returns one unit that adds the columns and the indexes of the given extensions. A plugin uses it for a column on a table that another owner declared.
func OrganizationUnits ¶ added in v0.4.0
OrganizationUnits returns the migration units of the organization tables. One unit creates one table, so a host applies them in the order of the design document.
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.