schema

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blueprint

type Blueprint interface {
	// BigIncrements Create a new auto-incrementing big integer (8-byte) column on the table.
	BigIncrements(column string) ColumnDefinition
	// BigInteger Create a new big integer (8-byte) column on the table.
	BigInteger(column string) ColumnDefinition
	// Build Execute the blueprint to build / modify the table.
	Build(query orm.Query, grammar Grammar) error
	// Char Create a new char column on the table.
	Char(column string, length ...int) ColumnDefinition
	// Create Indicate that the table needs to be created.
	Create()
	// Date Create a new date column on the table.
	Date(column string) ColumnDefinition
	// DateTime Create a new date-time column on the table.
	DateTime(column string, precision ...int) ColumnDefinition
	// DateTimeTz Create a new date-time column (with time zone) on the table.
	DateTimeTz(column string, precision ...int) ColumnDefinition
	// Decimal Create a new decimal column on the table.
	Decimal(column string) ColumnDefinition
	// Double Create a new double column on the table.
	Double(column string) ColumnDefinition
	// Drop Indicate that the table should be dropped.
	Drop()
	// DropColumn Indicate that the given columns should be dropped.
	DropColumn(column ...string)
	// DropForeign Indicate that the given foreign key should be dropped.
	DropForeign(column ...string)
	// DropForeignByName Indicate that the given foreign key should be dropped.
	DropForeignByName(name string)
	// DropFullText Indicate that the given fulltext index should be dropped.
	DropFullText(column ...string)
	// DropFullTextByName Indicate that the given fulltext index should be dropped.
	DropFullTextByName(name string)
	// DropIfExists Indicate that the table should be dropped if it exists.
	DropIfExists()
	// DropIndex Indicate that the given index should be dropped.
	DropIndex(column ...string)
	// DropIndexByName Indicate that the given index should be dropped.
	DropIndexByName(name string)
	// DropPrimary Indicate that the given primary key should be dropped.
	DropPrimary(column ...string)
	// DropSoftDeletes Indicate that the soft delete column should be dropped.
	DropSoftDeletes(column ...string)
	// DropSoftDeletesTz Indicate that the soft delete column should be dropped.
	DropSoftDeletesTz(column ...string)
	// DropTimestamps Indicate that the timestamp columns should be dropped.
	DropTimestamps()
	// DropTimestampsTz Indicate that the timestamp columns should be dropped.
	DropTimestampsTz()
	// DropUnique Indicate that the given unique key should be dropped.
	DropUnique(column ...string)
	// DropUniqueByName Indicate that the given unique key should be dropped.
	DropUniqueByName(name string)
	// Enum Create a new enum column on the table.
	Enum(column string, array []any) ColumnDefinition
	// Float Create a new float column on the table.
	Float(column string, precision ...int) ColumnDefinition
	// Foreign Specify a foreign key for the table.
	Foreign(column ...string) ForeignKeyDefinition
	// FullText Specify a fulltext for the table.
	FullText(column ...string) IndexDefinition
	// GetAddedColumns Get the added columns.
	GetAddedColumns() []ColumnDefinition
	// GetCommands Get the commands.
	GetCommands() []*Command
	// GetTableName Get the table name with prefix.
	GetTableName() string
	// HasCommand Determine if the blueprint has a specific command.
	HasCommand(command string) bool
	// ID Create a new auto-incrementing big integer (8-byte) column on the table.
	ID(column ...string) ColumnDefinition
	// Increments Create a new auto-incrementing integer (4-byte) column on the table.
	Increments(column string) ColumnDefinition
	// Index Specify an index for the table.
	Index(column ...string) IndexDefinition
	// Integer Create a new integer (4-byte) column on the table.
	Integer(column string) ColumnDefinition
	// IntegerIncrements Create a new auto-incrementing integer (4-byte) column on the table.
	IntegerIncrements(column string) ColumnDefinition
	// Json Create a new json column on the table.
	Json(column string) ColumnDefinition
	// Jsonb Create a new jsonb column on the table.
	Jsonb(column string) ColumnDefinition
	// LongText Create a new long text column on the table.
	LongText(column string) ColumnDefinition
	// MediumIncrements Create a new auto-incrementing medium integer (3-byte) column on the table.
	MediumIncrements(column string) ColumnDefinition
	// MediumInteger Create a new medium integer (3-byte) column on the table.
	MediumInteger(column string) ColumnDefinition
	// MediumText Create a new medium text column on the table.
	MediumText(column string) ColumnDefinition
	// Primary Specify the primary key(s) for the table.
	Primary(column ...string)
	// Rename the table to a given name.
	Rename(to string)
	// RenameIndex Indicate that the given indexes should be renamed.
	RenameIndex(from, to string)
	// SetTable Set the table that the blueprint operates on.
	SetTable(name string)
	// SmallIncrements Create a new auto-incrementing small integer (2-byte) column on the table.
	SmallIncrements(column string) ColumnDefinition
	// SmallInteger Create a new small integer (2-byte) column on the table.
	SmallInteger(column string) ColumnDefinition
	// SoftDeletes Add a "deleted at" timestamp for the table.
	SoftDeletes(column ...string) ColumnDefinition
	// SoftDeletesTz Add a "deleted at" timestampTz for the table.
	SoftDeletesTz(column ...string) ColumnDefinition
	// String Create a new string column on the table.
	String(column string, length ...int) ColumnDefinition
	// Text Create a new text column on the table.
	Text(column string) ColumnDefinition
	// Time Create a new time column on the table.
	Time(column string, precision ...int) ColumnDefinition
	// TimeTz Create a new time column (with time zone) on the table.
	TimeTz(column string, precision ...int) ColumnDefinition
	// Timestamp Create a new time column on the table.
	Timestamp(column string, precision ...int) ColumnDefinition
	// Timestamps Add nullable creation and update timestamps to the table.
	Timestamps(precision ...int)
	// TimestampsTz Add creation and update timestampTz columns to the table.
	TimestampsTz(precision ...int)
	// TimestampTz Create a new time column (with time zone) on the table.
	TimestampTz(column string, precision ...int) ColumnDefinition
	// TinyIncrements Create a new auto-incrementing tiny integer (1-byte) column on the table.
	TinyIncrements(column string) ColumnDefinition
	// TinyInteger Create a new tiny integer (1-byte) column on the table.
	TinyInteger(column string) ColumnDefinition
	// TinyText Create a new tiny text column on the table.
	TinyText(column string) ColumnDefinition
	// ToSql Get the raw SQL statements for the blueprint.
	ToSql(grammar Grammar) []string
	// Unique Specify a unique index for the table.
	Unique(column ...string) IndexDefinition
	// UnsignedBigInteger Create a new unsigned big integer (8-byte) column on the table.
	UnsignedBigInteger(column string) ColumnDefinition
	// UnsignedInteger Create a new unsigned integer (4-byte) column on the table.
	UnsignedInteger(column string) ColumnDefinition
	// UnsignedMediumInteger Create a new unsigned medium integer (3-byte) column on the table.
	UnsignedMediumInteger(column string) ColumnDefinition
	// UnsignedSmallInteger Create a new unsigned small integer (2-byte) column on the table.
	UnsignedSmallInteger(column string) ColumnDefinition
	// UnsignedTinyInteger Create a new unsigned tiny integer (1-byte) column on the table.
	UnsignedTinyInteger(column string) ColumnDefinition
}

type Column

type Column struct {
	Autoincrement bool
	Collation     string
	Comment       string
	Default       string
	Name          string
	Nullable      bool
	Type          string
	TypeName      string
}

type ColumnDefinition

type ColumnDefinition interface {
	// AutoIncrement set the column as auto increment
	AutoIncrement() ColumnDefinition
	// Comment sets the comment value
	Comment(comment string) ColumnDefinition
	// Default set the default value
	Default(def any) ColumnDefinition
	// GetAllowed returns the allowed value
	GetAllowed() []any
	// GetAutoIncrement returns the autoIncrement value
	GetAutoIncrement() bool
	// GetComment returns the comment value
	GetComment() (comment string)
	// GetDefault returns the default value
	GetDefault() any
	// GetLength returns the length value
	GetLength() int
	// GetName returns the name value
	GetName() string
	// GetNullable returns the nullable value
	GetNullable() bool
	// GetOnUpdate returns the onUpdate value
	GetOnUpdate() any
	// GetPlaces returns the places value
	GetPlaces() int
	// GetPrecision returns the precision value
	GetPrecision() int
	// GetTotal returns the total value
	GetTotal() int
	// GetType returns the type value
	GetType() string
	// GetUnsigned returns the unsigned value
	GetUnsigned() bool
	// GetUseCurrent returns the useCurrent value
	GetUseCurrent() bool
	// GetUseCurrentOnUpdate returns the useCurrentOnUpdate value
	GetUseCurrentOnUpdate() bool
	// IsSetComment returns true if the comment value is set
	IsSetComment() bool
	// OnUpdate sets the column to use the value on update (Mysql only)
	OnUpdate(value any) ColumnDefinition
	// Places set the decimal places
	Places(places int) ColumnDefinition
	// Total set the decimal total
	Total(total int) ColumnDefinition
	// Nullable allow NULL values to be inserted into the column
	Nullable() ColumnDefinition
	// Unsigned set the column as unsigned
	Unsigned() ColumnDefinition
	// UseCurrent set the column to use the current timestamp
	UseCurrent() ColumnDefinition
	// UseCurrentOnUpdate set the column to use the current timestamp on update (Mysql only)
	UseCurrentOnUpdate() ColumnDefinition
}

type Command

type Command struct {
	Algorithm          string
	Column             ColumnDefinition
	Columns            []string
	Deferrable         *bool
	From               string
	Index              string
	InitiallyImmediate *bool
	Language           string
	Name               string
	On                 string
	OnDelete           string
	OnUpdate           string
	References         []string
	ShouldBeSkipped    bool
	To                 string
	Value              string
}

type CommonSchema

type CommonSchema interface {
	// GetTables Get the tables that belong to the database.
	GetTables() ([]Table, error)
	// GetViews Get the views that belong to the database.
	GetViews() ([]View, error)
}

type Connection

type Connection interface {
	// Connection Get the connection for the migration.
	Connection() string
}

type DBColumn

type DBColumn struct {
	Autoincrement bool
	Collation     string
	Comment       string
	Default       string
	Extra         string
	Length        int
	Name          string
	Nullable      string
	Places        int
	Precision     int
	Primary       bool
	Type          string
	TypeName      string
}

type DBForeignKey

type DBForeignKey struct {
	Name           string
	Columns        string
	ForeignSchema  string
	ForeignTable   string
	ForeignColumns string
	OnUpdate       string
	OnDelete       string
}

type DBIndex

type DBIndex struct {
	Columns string
	Name    string
	Primary bool
	Type    string
	Unique  bool
}

type DriverSchema

type DriverSchema interface {
	// DropAllTables Drop all tables from the schema.
	DropAllTables() error
	// DropAllTypes Drop all types from the schema.
	DropAllTypes() error
	// DropAllViews Drop all views from the schema.
	DropAllViews() error
	// GetColumns Get the columns for a given table.
	GetColumns(table string) ([]Column, error)
	// GetIndexes Get the indexes for a given table.
	GetIndexes(table string) ([]Index, error)
	// GetTypes Get the types that belong to the database.
	GetTypes() ([]Type, error)
}

type ForeignKey

type ForeignKey struct {
	Name           string
	Columns        []string
	ForeignSchema  string
	ForeignTable   string
	ForeignColumns []string
	OnUpdate       string
	OnDelete       string
}

type ForeignKeyDefinition

type ForeignKeyDefinition interface {
	CascadeOnDelete() ForeignKeyDefinition
	CascadeOnUpdate() ForeignKeyDefinition
	On(table string) ForeignKeyDefinition
	Name(name string) ForeignKeyDefinition
	NoActionOnDelete() ForeignKeyDefinition
	NoActionOnUpdate() ForeignKeyDefinition
	NullOnDelete() ForeignKeyDefinition
	References(columns ...string) ForeignKeyDefinition
	RestrictOnDelete() ForeignKeyDefinition
	RestrictOnUpdate() ForeignKeyDefinition
}

type Grammar

type Grammar interface {
	// CompileAdd Compile an add column command.
	CompileAdd(blueprint Blueprint, command *Command) string
	// CompileColumns Compile the query to determine the columns.
	CompileColumns(schema, table string) string
	// CompileComment Compile a column comment command.
	CompileComment(blueprint Blueprint, command *Command) string
	// CompileCreate Compile a create table command.
	CompileCreate(blueprint Blueprint) string
	// CompileDrop Compile a drop table command.
	CompileDrop(blueprint Blueprint) string
	// CompileDropAllDomains Compile the SQL needed to drop all domains.
	CompileDropAllDomains(domains []string) string
	// CompileDropAllTables Compile the SQL needed to drop all tables.
	CompileDropAllTables(tables []string) string
	// CompileDropAllTypes Compile the SQL needed to drop all types.
	CompileDropAllTypes(types []string) string
	// CompileDropAllViews Compile the SQL needed to drop all views.
	CompileDropAllViews(views []string) string
	// CompileDropColumn Compile a drop column command.
	CompileDropColumn(blueprint Blueprint, command *Command) []string
	// CompileDropForeign Compile a drop foreign key command.
	CompileDropForeign(blueprint Blueprint, command *Command) string
	// CompileDropFullText Compile a drop fulltext index command.
	CompileDropFullText(blueprint Blueprint, command *Command) string
	// CompileDropIfExists Compile a drop table (if exists) command.
	CompileDropIfExists(blueprint Blueprint) string
	// CompileDropIndex Compile a drop index command.
	CompileDropIndex(blueprint Blueprint, command *Command) string
	// CompileDropPrimary Compile a drop primary key command.
	CompileDropPrimary(blueprint Blueprint, command *Command) string
	// CompileDropUnique Compile a drop unique key command.
	CompileDropUnique(blueprint Blueprint, command *Command) string
	// CompileForeign Compile a foreign key command.
	CompileForeign(blueprint Blueprint, command *Command) string
	// CompileForeignKeys Compile the query to determine the foreign keys.
	CompileForeignKeys(schema, table string) string
	// CompileFullText Compile a fulltext index key command.
	CompileFullText(blueprint Blueprint, command *Command) string
	// CompileIndex Compile a plain index key command.
	CompileIndex(blueprint Blueprint, command *Command) string
	// CompileIndexes Compile the query to determine the indexes.
	CompileIndexes(schema, table string) string
	// CompilePrimary Compile a primary key command.
	CompilePrimary(blueprint Blueprint, command *Command) string
	// CompileRename Compile a rename table command.
	CompileRename(blueprint Blueprint, command *Command) string
	// CompileRenameIndex Compile a rename index command.
	CompileRenameIndex(schema Schema, blueprint Blueprint, command *Command) []string
	// CompileTables Compile the query to determine the tables.
	CompileTables(database string) string
	// CompileTypes Compile the query to determine the types.
	CompileTypes() string
	// CompileUnique Compile a unique key command.
	CompileUnique(blueprint Blueprint, command *Command) string
	// CompileViews Compile the query to determine the views.
	CompileViews(database string) string
	// GetAttributeCommands Get the commands for the schema build.
	GetAttributeCommands() []string
	// TypeBigInteger Create the column definition for a big integer type.
	TypeBigInteger(column ColumnDefinition) string
	// TypeChar Create the column definition for a char type.
	TypeChar(column ColumnDefinition) string
	// TypeDate Create the column definition for a date type.
	TypeDate(column ColumnDefinition) string
	// TypeDateTime Create the column definition for a date-time type.
	TypeDateTime(column ColumnDefinition) string
	// TypeDateTimeTz Create the column definition for a date-time (with time zone) type.
	TypeDateTimeTz(column ColumnDefinition) string
	// TypeDecimal Create the column definition for a decimal type.
	TypeDecimal(column ColumnDefinition) string
	// TypeDouble Create the column definition for a double type.
	TypeDouble(column ColumnDefinition) string
	// TypeEnum Create the column definition for an enumeration type.
	TypeEnum(column ColumnDefinition) string
	// TypeFloat Create the column definition for a float type.
	TypeFloat(column ColumnDefinition) string
	// TypeInteger Create the column definition for an integer type.
	TypeInteger(column ColumnDefinition) string
	// TypeJson Create the column definition for a json type.
	TypeJson(column ColumnDefinition) string
	// TypeJsonb Create the column definition for a jsonb type.
	TypeJsonb(column ColumnDefinition) string
	// TypeLongText Create the column definition for a long text type.
	TypeLongText(column ColumnDefinition) string
	// TypeMediumInteger Create the column definition for a medium integer type.
	TypeMediumInteger(column ColumnDefinition) string
	// TypeMediumText Create the column definition for a medium text type.
	TypeMediumText(column ColumnDefinition) string
	// TypeText Create the column definition for a text type.
	TypeText(column ColumnDefinition) string
	// TypeTime Create the column definition for a time type.
	TypeTime(column ColumnDefinition) string
	// TypeTimeTz Create the column definition for a time (with time zone) type.
	TypeTimeTz(column ColumnDefinition) string
	// TypeTimestamp Create the column definition for a timestamp type.
	TypeTimestamp(column ColumnDefinition) string
	// TypeTimestampTz Create the column definition for a timestamp (with time zone) type.
	TypeTimestampTz(column ColumnDefinition) string
	// TypeTinyInteger Create the column definition for a tiny integer type.
	TypeTinyInteger(column ColumnDefinition) string
	// TypeTinyText Create the column definition for a tiny text type.
	TypeTinyText(column ColumnDefinition) string
	// TypeSmallInteger Create the column definition for a small integer type.
	TypeSmallInteger(column ColumnDefinition) string
	// TypeString Create the column definition for a string type.
	TypeString(column ColumnDefinition) string
}

type Index

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

type IndexConfig

type IndexConfig struct {
	Algorithm string
	Name      string
	Language  string
}

type IndexDefinition

type IndexDefinition interface {
	Algorithm(algorithm string) IndexDefinition
	Deferrable() IndexDefinition
	InitiallyImmediate() IndexDefinition
	Language(name string) IndexDefinition
	Name(name string) IndexDefinition
}

type Migration

type Migration interface {
	// Signature Get the migration signature.
	Signature() string
	// Up Run the migrations.
	Up() error
	// Down Reverse the migrations.
	Down() error
}

type Processor

type Processor interface {
	ProcessColumns(dbColumns []DBColumn) []Column
	ProcessForeignKeys(dbIndexes []DBForeignKey) []ForeignKey
	ProcessIndexes(dbIndexes []DBIndex) []Index
}

type Schema

type Schema interface {
	CommonSchema
	DriverSchema
	// Connection Get the connection for the schema.
	Connection(name string) Schema
	// Create a new table on the schema.
	Create(table string, callback func(table Blueprint)) error
	// Drop a table from the schema.
	Drop(table string) error
	// DropColumns Drop columns from a table on the schema.
	DropColumns(table string, columns []string) error
	// DropIfExists Drop a table from the schema if exists.
	DropIfExists(table string) error
	// GetColumnListing Get the column listing for a given table.
	GetColumnListing(table string) []string
	// GetConnection Get the connection of the schema.
	GetConnection() string
	// GetForeignKeys Get the foreign keys for a given table.
	GetForeignKeys(table string) ([]ForeignKey, error)
	// GetIndexListing Get the names of the indexes for a given table.
	GetIndexListing(table string) []string
	// GetTableListing Get the table listing for the database.
	GetTableListing() []string
	// HasColumn Determine if the given table has a given column.
	HasColumn(table, column string) bool
	// HasColumns Determine if the given table has given columns.
	HasColumns(table string, columns []string) bool
	// HasIndex Determine if the given table has a given index.
	HasIndex(table, index string) bool
	// HasTable Determine if the given table exists.
	HasTable(name string) bool
	// HasType Determine if the given type exists.
	HasType(name string) bool
	// HasView Determine if the given view exists.
	HasView(name string) bool
	// Migrations Get the migrations.
	Migrations() []Migration
	// Orm Get the orm instance.
	Orm() orm.Orm
	// Register migrations.
	Register([]Migration)
	// Rename a table on the schema.
	Rename(from, to string) error
	// SetConnection Set the connection of the schema.
	SetConnection(name string)
	// Sql Execute a sql directly.
	Sql(sql string) error
	// Table Modify a table on the schema.
	Table(table string, callback func(table Blueprint)) error
}

type Table

type Table struct {
	Collation string
	Comment   string
	Engine    string
	Name      string
	Schema    string
	Size      int
}

type Type

type Type struct {
	Category string
	Implicit bool
	Name     string
	Schema   string
	Type     string
}

type View

type View struct {
	Name       string
	Schema     string
	Definition string
}

Jump to

Keyboard shortcuts

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