Documentation
¶
Index ¶
- Variables
- func Create(ctx context.Context, s *Schema, tables []*schema.Table, ...) error
- func Diff(ctx context.Context, url string, opts ...schema.MigrateOption) error
- func NamedDiff(ctx context.Context, url, name string, opts ...schema.MigrateOption) error
- type Schema
- func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error
- func (s *Schema) Diff(ctx context.Context, opts ...schema.MigrateOption) error
- func (s *Schema) NamedDiff(ctx context.Context, name string, opts ...schema.MigrateOption) error
- func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error
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 ( // AnnotationsColumns holds the columns for the "annotations" table. AnnotationsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "json_data", Type: field.TypeJSON}, {Name: "annotation_namespace_id", Type: field.TypeString}, {Name: "metadata_id", Type: field.TypeString}, } // AnnotationsTable holds the schema information for the "annotations" table. AnnotationsTable = &schema.Table{ Name: "annotations", Columns: AnnotationsColumns, PrimaryKey: []*schema.Column{AnnotationsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "annotations_annotation_namespaces_namespace", Columns: []*schema.Column{AnnotationsColumns[4]}, RefColumns: []*schema.Column{AnnotationNamespacesColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "annotations_metadata_metadata", Columns: []*schema.Column{AnnotationsColumns[5]}, RefColumns: []*schema.Column{MetadataColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "annotation_created_at", Unique: false, Columns: []*schema.Column{AnnotationsColumns[1]}, }, { Name: "annotation_updated_at", Unique: false, Columns: []*schema.Column{AnnotationsColumns[2]}, }, { Name: "annotation_metadata_id_annotation_namespace_id", Unique: true, Columns: []*schema.Column{AnnotationsColumns[5], AnnotationsColumns[4]}, }, { Name: "annotation_annotation_namespace_id_json_data", Unique: false, Columns: []*schema.Column{AnnotationsColumns[4], AnnotationsColumns[3]}, Annotation: &entsql.IndexAnnotation{ Types: map[string]string{ "postgres": "GIN", }, }, }, }, } // AnnotationNamespacesColumns holds the columns for the "annotation_namespaces" table. AnnotationNamespacesColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "name", Type: field.TypeString}, {Name: "owner_id", Type: field.TypeString}, {Name: "private", Type: field.TypeBool, Default: false}, } // AnnotationNamespacesTable holds the schema information for the "annotation_namespaces" table. AnnotationNamespacesTable = &schema.Table{ Name: "annotation_namespaces", Columns: AnnotationNamespacesColumns, PrimaryKey: []*schema.Column{AnnotationNamespacesColumns[0]}, Indexes: []*schema.Index{ { Name: "annotationnamespace_created_at", Unique: false, Columns: []*schema.Column{AnnotationNamespacesColumns[1]}, }, { Name: "annotationnamespace_updated_at", Unique: false, Columns: []*schema.Column{AnnotationNamespacesColumns[2]}, }, { Name: "annotationnamespace_owner_id", Unique: false, Columns: []*schema.Column{AnnotationNamespacesColumns[4]}, }, { Name: "annotationnamespace_owner_id_name", Unique: true, Columns: []*schema.Column{AnnotationNamespacesColumns[4], AnnotationNamespacesColumns[3]}, }, }, } // MetadataColumns holds the columns for the "metadata" table. MetadataColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "node_id", Type: field.TypeString, Unique: true}, } // MetadataTable holds the schema information for the "metadata" table. MetadataTable = &schema.Table{ Name: "metadata", Columns: MetadataColumns, PrimaryKey: []*schema.Column{MetadataColumns[0]}, Indexes: []*schema.Index{ { Name: "metadata_created_at", Unique: false, Columns: []*schema.Column{MetadataColumns[1]}, }, { Name: "metadata_updated_at", Unique: false, Columns: []*schema.Column{MetadataColumns[2]}, }, }, } // StatusColumns holds the columns for the "status" table. StatusColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "source", Type: field.TypeString}, {Name: "json_data", Type: field.TypeJSON}, {Name: "status_namespace_id", Type: field.TypeString}, {Name: "metadata_id", Type: field.TypeString}, } // StatusTable holds the schema information for the "status" table. StatusTable = &schema.Table{ Name: "status", Columns: StatusColumns, PrimaryKey: []*schema.Column{StatusColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "status_status_namespaces_namespace", Columns: []*schema.Column{StatusColumns[5]}, RefColumns: []*schema.Column{StatusNamespacesColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "status_metadata_metadata", Columns: []*schema.Column{StatusColumns[6]}, RefColumns: []*schema.Column{MetadataColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "status_created_at", Unique: false, Columns: []*schema.Column{StatusColumns[1]}, }, { Name: "status_updated_at", Unique: false, Columns: []*schema.Column{StatusColumns[2]}, }, { Name: "status_metadata_id_status_namespace_id", Unique: false, Columns: []*schema.Column{StatusColumns[6], StatusColumns[5]}, }, { Name: "status_metadata_id_status_namespace_id_source", Unique: true, Columns: []*schema.Column{StatusColumns[6], StatusColumns[5], StatusColumns[3]}, }, { Name: "status_status_namespace_id_json_data", Unique: false, Columns: []*schema.Column{StatusColumns[5], StatusColumns[4]}, Annotation: &entsql.IndexAnnotation{ Types: map[string]string{ "postgres": "GIN", }, }, }, }, } // StatusNamespacesColumns holds the columns for the "status_namespaces" table. StatusNamespacesColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, {Name: "name", Type: field.TypeString}, {Name: "resource_provider_id", Type: field.TypeString}, {Name: "private", Type: field.TypeBool, Default: false}, } // StatusNamespacesTable holds the schema information for the "status_namespaces" table. StatusNamespacesTable = &schema.Table{ Name: "status_namespaces", Columns: StatusNamespacesColumns, PrimaryKey: []*schema.Column{StatusNamespacesColumns[0]}, Indexes: []*schema.Index{ { Name: "statusnamespace_created_at", Unique: false, Columns: []*schema.Column{StatusNamespacesColumns[1]}, }, { Name: "statusnamespace_updated_at", Unique: false, Columns: []*schema.Column{StatusNamespacesColumns[2]}, }, { Name: "statusnamespace_resource_provider_id", Unique: false, Columns: []*schema.Column{StatusNamespacesColumns[4]}, }, { Name: "statusnamespace_resource_provider_id_name", Unique: true, Columns: []*schema.Column{StatusNamespacesColumns[4], StatusNamespacesColumns[3]}, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ AnnotationsTable, AnnotationNamespacesTable, MetadataTable, StatusTable, StatusNamespacesTable, } )
Functions ¶
func Create ¶
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error
Create creates all table resources using the given schema driver.
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the API for creating, migrating and dropping a schema.
func (*Schema) Diff ¶
Diff creates a migration file containing the statements to resolve the diff between the Ent schema and the connected database.
func (*Schema) NamedDiff ¶
NamedDiff creates a named migration file containing the statements to resolve the diff between the Ent schema and the connected database.
Click to show internal directories.
Click to hide internal directories.