Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // WithGlobalUniqueID sets the universal ids options to the migration. // If this option is enabled, ent migration will allocate a 1<<32 range // for the ids of each entity (table). // Note that this option cannot be applied on tables that already exist. WithGlobalUniqueID = schema.WithGlobalUniqueID // WithDropColumn sets the drop column option to the migration. // If this option is enabled, ent migration will drop old columns // that were used for both fields and edges. This defaults to false. WithDropColumn = schema.WithDropColumn // WithDropIndex sets the drop index option to the migration. // If this option is enabled, ent migration will drop old indexes // that were defined in the schema. This defaults to false. // Note that unique constraints are defined using `UNIQUE INDEX`, // and therefore, it's recommended to enable this option to get more // flexibility in the schema changes. WithDropIndex = schema.WithDropIndex // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. WithForeignKeys = schema.WithForeignKeys )
View Source
var ( // SentencesColumns holds the columns for the "sentences" table. SentencesColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "text", Type: field.TypeString, Size: 2147483647}, {Name: "created_at", Type: field.TypeTime}, {Name: "order", Type: field.TypeInt}, {Name: "story_sentences", Type: field.TypeUUID}, } // SentencesTable holds the schema information for the "sentences" table. SentencesTable = &schema.Table{ Name: "sentences", Columns: SentencesColumns, PrimaryKey: []*schema.Column{SentencesColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "sentences_stories_sentences", Columns: []*schema.Column{SentencesColumns[4]}, RefColumns: []*schema.Column{StoriesColumns[0]}, OnDelete: schema.NoAction, }, }, } // StoriesColumns holds the columns for the "stories" table. StoriesColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "status", Type: field.TypeEnum, Enums: []string{"open", "closed", "waiting"}, Default: "open"}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, } // StoriesTable holds the schema information for the "stories" table. StoriesTable = &schema.Table{ Name: "stories", Columns: StoriesColumns, PrimaryKey: []*schema.Column{StoriesColumns[0]}, } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "ip_address", Type: field.TypeString}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ Name: "users", Columns: UsersColumns, PrimaryKey: []*schema.Column{UsersColumns[0]}, } // UserSentencesColumns holds the columns for the "user_sentences" table. UserSentencesColumns = []*schema.Column{ {Name: "user_id", Type: field.TypeUUID}, {Name: "sentence_id", Type: field.TypeUUID}, } // UserSentencesTable holds the schema information for the "user_sentences" table. UserSentencesTable = &schema.Table{ Name: "user_sentences", Columns: UserSentencesColumns, PrimaryKey: []*schema.Column{UserSentencesColumns[0], UserSentencesColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "user_sentences_user_id", Columns: []*schema.Column{UserSentencesColumns[0]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "user_sentences_sentence_id", Columns: []*schema.Column{UserSentencesColumns[1]}, RefColumns: []*schema.Column{SentencesColumns[0]}, OnDelete: schema.Cascade, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ SentencesTable, StoriesTable, UsersTable, UserSentencesTable, } )
Functions ¶
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the API for creating, migrating and dropping a schema.
Click to show internal directories.
Click to hide internal directories.