schema

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseSchema

type BaseSchema struct{}

BaseSchema is the base for AdonisJS Lucid-style migrations. Embed it in your migration struct and implement TableName, Up, and Down.

type CreateUsers struct {
    schema.BaseSchema
}

func (m *CreateUsers) TableName() string { return "users" }

func (m *CreateUsers) Up(db *lucid.DB) error {
    return schema.New(db).CreateTable("users", func(t *schema.Table) {
        t.Increments("id")
        t.Timestamps()
    })
}

func (m *CreateUsers) Down(db *lucid.DB) error {
    return schema.New(db).DropTable("users")
}

type Schema

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

Schema holds the database connection for migrations.

func New

func New(db *lucid.DB) *Schema

New creates a Schema for the given DB.

func (*Schema) AlterTable

func (s *Schema) AlterTable(name string, fn func(*Table)) error

AlterTable alters an existing table (add column). Use in migrations for schema changes.

func (*Schema) CreateTable

func (s *Schema) CreateTable(name string, fn func(*Table)) error

CreateTable creates a table with the given name. The callback receives a Table builder to define columns.

func (*Schema) DropTable

func (s *Schema) DropTable(name string) error

DropTable drops the table.

type Table

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

Table builds column definitions for CreateTable.

func (*Table) After

func (t *Table) After(_ string) *Table

After is a no-op placeholder for column positioning (MySQL) in ALTER TABLE.

func (*Table) BigIncrements

func (t *Table) BigIncrements(name string) *Table

BigIncrements adds a bigint auto-increment primary key.

func (*Table) BigInteger

func (t *Table) BigInteger(name string) *Table

BigInteger adds a bigint column.

func (*Table) Binary

func (t *Table) Binary(name string) *Table

Binary adds a binary/BLOB column.

func (*Table) Boolean

func (t *Table) Boolean(name string) *Table

Boolean adds a boolean column.

func (*Table) Check

func (t *Table) Check(_ string) *Table

Check is a no-op placeholder for future CHECK constraint support.

func (*Table) Comment

func (t *Table) Comment(text string) *Table

Comment sets a comment for the last column.

func (*Table) CompositeIndex

func (t *Table) CompositeIndex(cols []string) *Table

CompositeIndex registers a non-unique index for multiple columns.

func (*Table) Date

func (t *Table) Date(name string) *Table

Date adds a DATE column.

func (*Table) DateTime

func (t *Table) DateTime(name string) *Table

DateTime adds a DATETIME column.

func (*Table) Decimal

func (t *Table) Decimal(name string, precision, scale int) *Table

Decimal adds a decimal column.

func (*Table) Default

func (t *Table) Default(val string) *Table

Default sets the default value for the last column.

func (*Table) Enum

func (t *Table) Enum(name string, _ []string) *Table

Enum adds an enum-like column. Backed by VARCHAR; values are not enforced at DB level.

func (*Table) First

func (t *Table) First() *Table

First is a no-op placeholder for column positioning (MySQL) in ALTER TABLE.

func (*Table) Float

func (t *Table) Float(name string, precision, scale int) *Table

Float adds a float column.

func (*Table) ForeignId

func (t *Table) ForeignId(column, references string) *Table

ForeignId adds a foreign key column (e.g. user_id) referencing table.id.

func (*Table) Generated

func (t *Table) Generated(_ string, _ string) *Table

Generated is a no-op placeholder for generated columns.

func (*Table) ID

func (t *Table) ID() *Table

ID is a shorthand for an auto-increment primary key named "id".

func (*Table) Increments

func (t *Table) Increments(name string) *Table

Increments adds an auto-increment primary key (id).

func (*Table) Index

func (t *Table) Index(column string) *Table

Index registers a non-unique index for the given column. If column is empty, the last defined column is used.

func (*Table) Integer

func (t *Table) Integer(name string) *Table

Integer adds an integer column.

func (*Table) JSON

func (t *Table) JSON(name string) *Table

JSON adds a JSON column.

func (*Table) JSONB

func (t *Table) JSONB(name string) *Table

JSONB adds a JSONB column (primarily for Postgres).

func (*Table) LegacyTimestamp

func (t *Table) LegacyTimestamp(name string) *Table

LegacyTimestamp adds a legacy TIMESTAMP column. Use this only when you explicitly need the database's TIMESTAMP semantics.

func (*Table) LongText

func (t *Table) LongText(name string) *Table

LongText adds a long text column.

func (*Table) NotNull

func (t *Table) NotNull() *Table

NotNull marks the last column as NOT NULL.

func (*Table) Nullable

func (t *Table) Nullable() *Table

Nullable marks the last column as nullable.

func (*Table) Primary

func (t *Table) Primary() *Table

Primary marks the last column as PRIMARY KEY.

func (*Table) SmallInteger

func (t *Table) SmallInteger(name string) *Table

SmallInteger adds a smallint column.

func (*Table) SoftDeletes

func (t *Table) SoftDeletes() *Table

SoftDeletes adds deleted_at column (nullable) for GORM soft delete.

func (*Table) String

func (t *Table) String(name string, size int) *Table

String adds a varchar column.

func (*Table) Text

func (t *Table) Text(name string) *Table

Text adds a text column.

func (*Table) Time

func (t *Table) Time(name string) *Table

Time adds a TIME column.

func (*Table) Timestamp

func (t *Table) Timestamp(name string) *Table

Timestamp adds a timestamp column (created_at, updated_at).

func (*Table) Timestamps

func (t *Table) Timestamps() *Table

Timestamps adds created_at and updated_at columns.

func (*Table) UUID

func (t *Table) UUID(name string) *Table

UUID adds a UUID column.

func (*Table) UUIDPrimary

func (t *Table) UUIDPrimary() *Table

UUIDPrimary adds a UUID primary key named "id".

func (*Table) Unique

func (t *Table) Unique() *Table

Unique marks the last column as UNIQUE.

func (*Table) UniqueComposite

func (t *Table) UniqueComposite(cols []string) *Table

UniqueComposite registers a unique index for multiple columns.

func (*Table) Unsigned

func (t *Table) Unsigned() *Table

Unsigned marks the last numeric column as UNSIGNED.

Jump to

Keyboard shortcuts

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