Documentation
¶
Overview ¶
Package schema defines the declarative, schema-driven data model for GoModularAuth.
In GoModularAuth, persistent schemas are defined centrally and can be extended by plugin modules (e.g. adding two_factor_enabled to users, or registering new models like passkeys or organizations). Database adapters consume the compiled Schema to execute queries, map fields, and generate or execute database migrations.
Index ¶
Constants ¶
const ( ModelUsers = "users" ModelAccounts = "accounts" ModelCredentials = "credentials" ModelSessions = "sessions" ModelVerifications = "verifications" )
Core model names.
Variables ¶
var ( // ErrModelNotFound indicates the requested model does not exist in the schema. ErrModelNotFound = errors.New("schema: model not found") // ErrModelExists indicates a model with the same name is already registered. ErrModelExists = errors.New("schema: model already exists") // ErrFieldExists indicates a field already exists in the model. ErrFieldExists = errors.New("schema: field already exists") // ErrInvalidField indicates a field definition is invalid. ErrInvalidField = errors.New("schema: invalid field") // ErrInvalidModel indicates a model definition is invalid. ErrInvalidModel = errors.New("schema: invalid model") // ErrInvalidReference indicates a foreign key reference targets a nonexistent model or field. ErrInvalidReference = errors.New("schema: invalid foreign key reference") )
Functions ¶
This section is empty.
Types ¶
type DataType ¶
type DataType string
DataType represents the canonical data types supported across all storage engines.
type Field ¶
type Field struct {
Name string
DBName string // Column name in database; defaults to Name if empty
Type DataType
Required bool
Unique bool
Indexed bool
Default any
References *Reference
}
Field describes a single column or property within a Model.
func (Field) EffectiveDBName ¶
EffectiveDBName returns the database column name, defaulting to Name if DBName is empty.
type Model ¶
type Model struct {
Name string
TableName string
PrimaryKey string
Fields map[string]Field
Indexes []Index
}
Model represents a domain entity table or collection in the storage engine.
func AccountModel ¶
func AccountModel() *Model
AccountModel returns the canonical core schema definition for the accounts table.
func CredentialModel ¶
func CredentialModel() *Model
CredentialModel returns the canonical core schema definition for the credentials table.
func NewModel ¶
NewModel creates an empty Model initialized with the given name, table name, and primary key.
func SessionModel ¶
func SessionModel() *Model
SessionModel returns the canonical core schema definition for the sessions table.
func UserModel ¶
func UserModel() *Model
UserModel returns the canonical core schema definition for the users table.
func VerificationModel ¶
func VerificationModel() *Model
VerificationModel returns the canonical core schema definition for the verification tokens table.
type Reference ¶
type Reference struct {
Model string
Field string
OnDelete string // e.g. "CASCADE", "SET NULL", "RESTRICT"
}
Reference defines a relational foreign key constraint to another model.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema aggregates all Models in the authentication engine and manages extensions.
func DefaultCoreSchema ¶
DefaultCoreSchema initializes and returns a Schema populated with all core models and validated.
func (*Schema) ExtendModel ¶
ExtendModel allows plugins to inject new fields into an existing model.