ent: github.com/facebookincubator/ent/dialect/sql/schema Index | Files

package schema

import "github.com/facebookincubator/ent/dialect/sql/schema"

Package schema contains all schema migration logic for SQL dialects.


Package Files

migrate.go mysql.go postgres.go schema.go sqlite.go writer.go


const (
    // TypeTable defines the table name holding the type information.
    TypeTable = "ent_types"
    // MaxTypes defines the max number of types can be created when
    // defining universal ids. The left 16-bits are reserved.
    MaxTypes = math.MaxUint16
const (
    // DefaultStringLen describes the default length for string/varchar types.
    DefaultStringLen int64 = 255
    // Null is the string representation of NULL in SQL.
    Null = "NULL"
    // PrimaryKey is the string representation of PKs in SQL.
    PrimaryKey = "PRI"
    // UniqueKey is the string representation of PKs in SQL.
    UniqueKey = "UNI"

type Column Uses

type Column struct {
    Name       string            // column name.
    Type       field.Type        // column type.
    SchemaType map[string]string // optional schema type per dialect.
    Attr       string            // extra attributes.
    Size       int64             // max size parameter for string, blob, etc.
    Key        string            // key definition (PRI, UNI or MUL).
    Unique     bool              // column with unique constraint.
    Increment  bool              // auto increment attribute.
    Nullable   bool              // null or not null attribute.
    Default    interface{}       // default value.
    Enums      []string          // enum values.
    // contains filtered or unexported fields

Column schema definition for SQL dialects.

func (*Column) ConvertibleTo Uses

func (c *Column) ConvertibleTo(d *Column) bool

ConvertibleTo reports whether a column can be converted to the new column without altering its data.

func (Column) FloatType Uses

func (c Column) FloatType() bool

FloatType reports of the given type is a float type (float32, float64).

func (Column) IntType Uses

func (c Column) IntType() bool

IntType reports whether the column is an int type (int8 ... int64).

func (*Column) PrimaryKey Uses

func (c *Column) PrimaryKey() bool

PrimaryKey returns boolean indicates if this column is on of the primary key columns. Used by the migration tool when parsing the `DESCRIBE TABLE` output Go objects.

func (*Column) ScanDefault Uses

func (c *Column) ScanDefault(value string) error

ScanDefault scans the default value string to its interface type.

func (Column) UintType Uses

func (c Column) UintType() bool

UintType reports of the given type is a uint type (int8 ... int64).

func (*Column) UniqueKey Uses

func (c *Column) UniqueKey() bool

UniqueKey returns boolean indicates if this column is a unique key. Used by the migration tool when parsing the `DESCRIBE TABLE` output Go objects.

type ForeignKey Uses

type ForeignKey struct {
    Symbol     string          // foreign-key name. Generated if empty.
    Columns    []*Column       // table column
    RefTable   *Table          // referenced table.
    RefColumns []*Column       // referenced columns.
    OnUpdate   ReferenceOption // action on update.
    OnDelete   ReferenceOption // action on delete.

ForeignKey definition for creation.

func (ForeignKey) DSL Uses

func (fk ForeignKey) DSL() *sql.ForeignKeyBuilder

DSL returns a default DSL query for a foreign-key.

type Index Uses

type Index struct {
    Name    string    // index name.
    Unique  bool      // uniqueness.
    Columns []*Column // actual table columns.
    // contains filtered or unexported fields

Index definition for table index.

func (*Index) Builder Uses

func (i *Index) Builder(table string) *sql.IndexBuilder

Builder returns the query builder for index creation. The DSL is identical in all dialects.

func (*Index) DropBuilder Uses

func (i *Index) DropBuilder(table string) *sql.DropIndexBuilder

DropBuilder returns the query builder for the drop index.

type Indexes Uses

type Indexes []*Index

Indexes used for scanning all sql.Rows into a list of indexes, because multiple sql rows can represent the same index (multi-columns indexes).

type Migrate Uses

type Migrate struct {
    // contains filtered or unexported fields

Migrate runs the migrations logic for the SQL dialects.

func NewMigrate Uses

func NewMigrate(d dialect.Driver, opts ...MigrateOption) (*Migrate, error)

NewMigrate create a migration structure for the given SQL driver.

func (*Migrate) Create Uses

func (m *Migrate) Create(ctx context.Context, tables ...*Table) error

Create creates all schema resources in the database. It works in an "append-only" mode, which means, it only create tables, append column to tables or modifying column type.

Column can be modified by turning into a NULL from NOT NULL, or having a type conversion not resulting data altering. From example, changing varchar(255) to varchar(120) is invalid, but changing varchar(120) to varchar(255) is valid. For more info, see the convert function below.

Note that SQLite dialect does not support (this moment) the "append-only" mode describe above, since it's used only for testing.

type MigrateOption Uses

type MigrateOption func(*Migrate)

MigrateOption allows for managing schema configuration using functional options.

func WithDropColumn Uses

func WithDropColumn(b bool) MigrateOption

WithDropColumn sets the columns dropping option to the migration. Defaults to false.

func WithDropIndex Uses

func WithDropIndex(b bool) MigrateOption

WithDropIndex sets the indexes dropping option to the migration. Defaults to false.

func WithFixture Uses

func WithFixture(b bool) MigrateOption

WithFixture sets the foreign-key renaming option to the migration when upgrading ent from v0.1.0 (issue-#285). Defaults to false.

func WithGlobalUniqueID Uses

func WithGlobalUniqueID(b bool) MigrateOption

WithGlobalUniqueID sets the universal ids options to the migration. Defaults to false.

type MySQL Uses

type MySQL struct {
    // contains filtered or unexported fields

MySQL is a MySQL migration driver.

type Postgres Uses

type Postgres struct {
    // contains filtered or unexported fields

Postgres is a postgres migration driver.

type ReferenceOption Uses

type ReferenceOption string

ReferenceOption for constraint actions.

const (
    NoAction   ReferenceOption = "NO ACTION"
    Restrict   ReferenceOption = "RESTRICT"
    Cascade    ReferenceOption = "CASCADE"
    SetNull    ReferenceOption = "SET NULL"
    SetDefault ReferenceOption = "SET DEFAULT"

Reference options.

func (ReferenceOption) ConstName Uses

func (r ReferenceOption) ConstName() string

ConstName returns the constant name of a reference option. It's used by entc for printing the constant name in templates.

type SQLite Uses

type SQLite struct {

SQLite is an SQLite migration driver.

type Table Uses

type Table struct {
    Name    string
    Columns []*Column

    Indexes     []*Index
    PrimaryKey  []*Column
    ForeignKeys []*ForeignKey
    // contains filtered or unexported fields

Table schema definition for SQL dialects.

func NewTable Uses

func NewTable(name string) *Table

NewTable returns a new table with the given name.

func (*Table) AddColumn Uses

func (t *Table) AddColumn(c *Column) *Table

AddColumn adds a new column to the table.

func (*Table) AddForeignKey Uses

func (t *Table) AddForeignKey(fk *ForeignKey) *Table

AddForeignKey adds a foreign key to the table.

func (*Table) AddIndex Uses

func (t *Table) AddIndex(name string, unique bool, columns []string) *Table

AddIndex creates and adds a new index to the table from the given options.

func (*Table) AddPrimary Uses

func (t *Table) AddPrimary(c *Column) *Table

AddPrimary adds a new primary key to the table.

type WriteDriver Uses

type WriteDriver struct {
    dialect.Driver // underlying driver.
    io.Writer      // target for exec statements.

WriteDriver is a driver that writes all driver exec operations to its writer.

func (*WriteDriver) Commit Uses

func (w *WriteDriver) Commit() error

Commit writes the transaction commit.

func (*WriteDriver) Exec Uses

func (w *WriteDriver) Exec(_ context.Context, query string, _, _ interface{}) error

Exec writes its query and calls the underlying driver Exec method.

func (*WriteDriver) Rollback Uses

func (w *WriteDriver) Rollback() error

Rollback writes the transaction rollback.

func (*WriteDriver) Tx Uses

func (w *WriteDriver) Tx(context.Context) (dialect.Tx, error)

Tx writes the transaction start.

Package schema imports 11 packages (graph) and is imported by 4 packages. Updated 2020-09-24. Refresh now. Tools for package owners.