migrate

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 7 Imported by: 0

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 (
	// DishColumns holds the columns for the "dish" table.
	DishColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "name_de", Type: field.TypeString, Unique: true},
		{Name: "name_en", Type: field.TypeString, Nullable: true},
	}
	// DishTable holds the schema information for the "dish" table.
	DishTable = &schema.Table{
		Name:       "dish",
		Columns:    DishColumns,
		PrimaryKey: []*schema.Column{DishColumns[0]},
	}
	// DishAliasColumns holds the columns for the "dish_alias" table.
	DishAliasColumns = []*schema.Column{
		{Name: "alias_name", Type: field.TypeString},
		{Name: "normalized_alias_name", Type: field.TypeString},
		{Name: "dish", Type: field.TypeUUID},
	}
	// DishAliasTable holds the schema information for the "dish_alias" table.
	DishAliasTable = &schema.Table{
		Name:       "dish_alias",
		Columns:    DishAliasColumns,
		PrimaryKey: []*schema.Column{DishAliasColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "dish_alias_dish_aliases",
				Columns:    []*schema.Column{DishAliasColumns[2]},
				RefColumns: []*schema.Column{DishColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// ImageColumns holds the columns for the "image" table.
	ImageColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "review", Type: field.TypeUUID},
	}
	// ImageTable holds the schema information for the "image" table.
	ImageTable = &schema.Table{
		Name:       "image",
		Columns:    ImageColumns,
		PrimaryKey: []*schema.Column{ImageColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "image_review_images",
				Columns:    []*schema.Column{ImageColumns[1]},
				RefColumns: []*schema.Column{ReviewColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// LocationColumns holds the columns for the "location" table.
	LocationColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "external_id", Type: field.TypeInt, Unique: true},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "visible", Type: field.TypeBool, Default: false},
	}
	// LocationTable holds the schema information for the "location" table.
	LocationTable = &schema.Table{
		Name:       "location",
		Columns:    LocationColumns,
		PrimaryKey: []*schema.Column{LocationColumns[0]},
	}
	// OccurrenceColumns holds the columns for the "occurrence" table.
	OccurrenceColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "date", Type: field.TypeTime},
		{Name: "kj", Type: field.TypeInt, Nullable: true},
		{Name: "kcal", Type: field.TypeInt, Nullable: true},
		{Name: "fat", Type: field.TypeInt, Nullable: true},
		{Name: "saturated_fat", Type: field.TypeInt, Nullable: true},
		{Name: "carbohydrates", Type: field.TypeInt, Nullable: true},
		{Name: "sugar", Type: field.TypeInt, Nullable: true},
		{Name: "fiber", Type: field.TypeInt, Nullable: true},
		{Name: "protein", Type: field.TypeInt, Nullable: true},
		{Name: "salt", Type: field.TypeInt, Nullable: true},
		{Name: "price_student", Type: field.TypeInt, Nullable: true},
		{Name: "price_staff", Type: field.TypeInt, Nullable: true},
		{Name: "price_guest", Type: field.TypeInt, Nullable: true},
		{Name: "not_available_after", Type: field.TypeTime, Nullable: true},
		{Name: "dish", Type: field.TypeUUID},
		{Name: "location", Type: field.TypeUUID},
	}
	// OccurrenceTable holds the schema information for the "occurrence" table.
	OccurrenceTable = &schema.Table{
		Name:       "occurrence",
		Columns:    OccurrenceColumns,
		PrimaryKey: []*schema.Column{OccurrenceColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "occurrence_dish_dish_occurrences",
				Columns:    []*schema.Column{OccurrenceColumns[15]},
				RefColumns: []*schema.Column{DishColumns[0]},
				OnDelete:   schema.NoAction,
			},
			{
				Symbol:     "occurrence_location_occurrences",
				Columns:    []*schema.Column{OccurrenceColumns[16]},
				RefColumns: []*schema.Column{LocationColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// ReviewColumns holds the columns for the "review" table.
	ReviewColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "display_name", Type: field.TypeString, Nullable: true, Size: 32},
		{Name: "stars", Type: field.TypeInt},
		{Name: "text", Type: field.TypeString, Nullable: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "accepted_at", Type: field.TypeTime, Nullable: true},
		{Name: "occurrence", Type: field.TypeUUID},
	}
	// ReviewTable holds the schema information for the "review" table.
	ReviewTable = &schema.Table{
		Name:       "review",
		Columns:    ReviewColumns,
		PrimaryKey: []*schema.Column{ReviewColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "review_occurrence_reviews",
				Columns:    []*schema.Column{ReviewColumns[7]},
				RefColumns: []*schema.Column{OccurrenceColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// TagColumns holds the columns for the "tag" table.
	TagColumns = []*schema.Column{
		{Name: "key", Type: field.TypeString},
		{Name: "name", Type: field.TypeString},
		{Name: "description", Type: field.TypeString},
		{Name: "short_name", Type: field.TypeString, Nullable: true},
		{Name: "priority", Type: field.TypeEnum, Enums: []string{"HIDE", "LOW", "MEDIUM", "HIGH"}, Default: "HIDE"},
		{Name: "is_allergy", Type: field.TypeBool, Default: false},
	}
	// TagTable holds the schema information for the "tag" table.
	TagTable = &schema.Table{
		Name:       "tag",
		Columns:    TagColumns,
		PrimaryKey: []*schema.Column{TagColumns[0]},
	}
	// UserColumns holds the columns for the "user" table.
	UserColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "email", Type: field.TypeString, Unique: true},
		{Name: "password_hash", Type: field.TypeString},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
	}
	// UserTable holds the schema information for the "user" table.
	UserTable = &schema.Table{
		Name:       "user",
		Columns:    UserColumns,
		PrimaryKey: []*schema.Column{UserColumns[0]},
	}
	// OccurrenceTagsColumns holds the columns for the "occurrence_tags" table.
	OccurrenceTagsColumns = []*schema.Column{
		{Name: "occurrence", Type: field.TypeUUID},
		{Name: "tag", Type: field.TypeString},
	}
	// OccurrenceTagsTable holds the schema information for the "occurrence_tags" table.
	OccurrenceTagsTable = &schema.Table{
		Name:       "occurrence_tags",
		Columns:    OccurrenceTagsColumns,
		PrimaryKey: []*schema.Column{OccurrenceTagsColumns[0], OccurrenceTagsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "occurrence_tags_occurrence",
				Columns:    []*schema.Column{OccurrenceTagsColumns[0]},
				RefColumns: []*schema.Column{OccurrenceColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "occurrence_tags_tag",
				Columns:    []*schema.Column{OccurrenceTagsColumns[1]},
				RefColumns: []*schema.Column{TagColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// OccurrenceSideDishesColumns holds the columns for the "occurrence_side_dishes" table.
	OccurrenceSideDishesColumns = []*schema.Column{
		{Name: "occurrence", Type: field.TypeUUID},
		{Name: "dish", Type: field.TypeUUID},
	}
	// OccurrenceSideDishesTable holds the schema information for the "occurrence_side_dishes" table.
	OccurrenceSideDishesTable = &schema.Table{
		Name:       "occurrence_side_dishes",
		Columns:    OccurrenceSideDishesColumns,
		PrimaryKey: []*schema.Column{OccurrenceSideDishesColumns[0], OccurrenceSideDishesColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "occurrence_side_dishes_occurrence",
				Columns:    []*schema.Column{OccurrenceSideDishesColumns[0]},
				RefColumns: []*schema.Column{OccurrenceColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "occurrence_side_dishes_dish",
				Columns:    []*schema.Column{OccurrenceSideDishesColumns[1]},
				RefColumns: []*schema.Column{DishColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		DishTable,
		DishAliasTable,
		ImageTable,
		LocationTable,
		OccurrenceTable,
		ReviewTable,
		TagTable,
		UserTable,
		OccurrenceTagsTable,
		OccurrenceSideDishesTable,
	}
)

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 NewSchema

func NewSchema(drv dialect.Driver) *Schema

NewSchema creates a new schema client.

func (*Schema) Create

func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error

Create creates all schema resources.

func (*Schema) WriteTo

func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error

WriteTo writes the schema changes to w instead of running them against the database.

if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
	log.Fatal(err)
}

Jump to

Keyboard shortcuts

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