schema

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 3 Imported by: 0

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

View Source
const (
	TableUsers        = "auth_users"
	TableCredentials  = "auth_credentials"
	TableAccounts     = "auth_accounts"
	TableSessions     = "auth_sessions"
	TableTokens       = "auth_tokens"
	TableOAuthStates  = "auth_oauth_states"
	TableTOTP         = "auth_totp"
	TableTOTPRecovery = "auth_totp_recovery"
)

Core table names.

View Source
const MigrationTable = "auth_schema_migrations"

MigrationTable holds the applied statement IDs.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name       string
	Type       Type
	Nullable   bool
	PrimaryKey bool
}

Column describes one column.

type Dialect

type Dialect string

Dialect selects the SQL flavor of a renderer.

const (
	Postgres Dialect = "postgres"
	SQLite   Dialect = "sqlite"
)

Supported dialects.

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 Index

type Index struct {
	Name    string
	Columns []string
	Unique  bool
}

Index describes one index.

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema is the effective set of tables.

func New

func New() *Schema

New returns an empty schema.

func NewCore

func NewCore() (*Schema, error)

NewCore returns a schema that already contains the core tables.

func (*Schema) Add

func (s *Schema) Add(t Table) error

Add registers a table. It reports an error when the name is already taken.

func (*Schema) Table

func (s *Schema) Table(name string) (Table, bool)

Table returns one table by name.

func (*Schema) Tables

func (s *Schema) Tables() []Table

Tables returns every table sorted by name. The order is deterministic and does not depend on registration order.

type Statement

type Statement struct {
	ID  string
	SQL string
}

Statement is one identified DDL statement.

The ID is stable across runs and identifies the statement in the applied migration record.

func Render

func Render(d Dialect, s *Schema) ([]Statement, error)

Render returns the deterministic DDL for the schema in one dialect. The result is a pure function of the schema and needs no database connection.

type Table

type Table struct {
	Name        string
	Columns     []Column
	Indexes     []Index
	ForeignKeys []ForeignKey
}

Table describes one table.

func Core

func Core() []Table

Core returns the core Auth-All schema.

type Type

type Type string

Type is a database-independent column type.

const (
	TypeText      Type = "text"
	TypeTimestamp Type = "timestamp"
	TypeInt       Type = "int"
	TypeBool      Type = "bool"
)

Supported column types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL