migrate

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2022 License: AGPL-3.0 Imports: 6 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
	// WithFixture sets the foreign-key renaming option to the migration when upgrading
	// ent from v0.1.0 (issue-#285). Defaults to false.
	WithFixture = schema.WithFixture
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// BadgesColumns holds the columns for the "badges" table.
	BadgesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "type", Type: field.TypeString, Unique: true},
		{Name: "active", Type: field.TypeBool, Default: true},
		{Name: "meta", Type: field.TypeJSON, Nullable: true},
	}
	// BadgesTable holds the schema information for the "badges" table.
	BadgesTable = &schema.Table{
		Name:       "badges",
		Columns:    BadgesColumns,
		PrimaryKey: []*schema.Column{BadgesColumns[0]},
	}
	// ChallengesColumns holds the columns for the "challenges" table.
	ChallengesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "content", Type: field.TypeString, Unique: true, Size: 140},
		{Name: "description", Type: field.TypeString, Nullable: true, Size: 280},
		{Name: "outcome", Type: field.TypeBool, Nullable: true},
		{Name: "published", Type: field.TypeBool, Default: true},
		{Name: "start_time", Type: field.TypeTime},
		{Name: "end_time", Type: field.TypeTime},
		{Name: "type", Type: field.TypeEnum, Enums: []string{"bool"}, Default: "bool"},
		{Name: "user_challenges", Type: field.TypeUUID, Nullable: true},
	}
	// ChallengesTable holds the schema information for the "challenges" table.
	ChallengesTable = &schema.Table{
		Name:       "challenges",
		Columns:    ChallengesColumns,
		PrimaryKey: []*schema.Column{ChallengesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "challenges_users_challenges",
				Columns:    []*schema.Column{ChallengesColumns[10]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// PredictionsColumns holds the columns for the "predictions" table.
	PredictionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "prognosis", Type: field.TypeBool},
		{Name: "meta", Type: field.TypeJSON, Nullable: true},
		{Name: "challenge_predictions", Type: field.TypeUUID},
		{Name: "user_predictions", Type: field.TypeUUID},
	}
	// PredictionsTable holds the schema information for the "predictions" table.
	PredictionsTable = &schema.Table{
		Name:       "predictions",
		Columns:    PredictionsColumns,
		PrimaryKey: []*schema.Column{PredictionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "predictions_challenges_predictions",
				Columns:    []*schema.Column{PredictionsColumns[5]},
				RefColumns: []*schema.Column{ChallengesColumns[0]},
				OnDelete:   schema.NoAction,
			},
			{
				Symbol:     "predictions_users_predictions",
				Columns:    []*schema.Column{PredictionsColumns[6]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "prediction_challenge_predictions_user_predictions",
				Unique:  true,
				Columns: []*schema.Column{PredictionsColumns[5], PredictionsColumns[6]},
			},
		},
	}
	// ProofsColumns holds the columns for the "proofs" table.
	ProofsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "content", Type: field.TypeString, Size: 280},
		{Name: "link", Type: field.TypeString},
		{Name: "meta", Type: field.TypeJSON, Nullable: true},
		{Name: "challenge_proofs", Type: field.TypeUUID},
	}
	// ProofsTable holds the schema information for the "proofs" table.
	ProofsTable = &schema.Table{
		Name:       "proofs",
		Columns:    ProofsColumns,
		PrimaryKey: []*schema.Column{ProofsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "proofs_challenges_proofs",
				Columns:    []*schema.Column{ProofsColumns[6]},
				RefColumns: []*schema.Column{ChallengesColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "email", Type: field.TypeString, Unique: true},
		{Name: "picture", Type: field.TypeString, Nullable: true, Default: "https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp&f=y"},
		{Name: "admin", Type: field.TypeBool, Default: false},
		{Name: "password_hash", Type: field.TypeString},
		{Name: "locale", Type: field.TypeEnum, Enums: []string{"en", "ru"}, Default: "ru"},
		{Name: "meta", Type: field.TypeJSON, Nullable: true},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
	}
	// UserSessionsColumns holds the columns for the "user_sessions" table.
	UserSessionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "sid", Type: field.TypeString, Unique: true},
		{Name: "ip", Type: field.TypeString},
		{Name: "user_agent", Type: field.TypeString},
		{Name: "last_activity", Type: field.TypeTime},
		{Name: "active", Type: field.TypeBool, Default: false},
		{Name: "meta", Type: field.TypeJSON, Nullable: true},
		{Name: "user_sessions", Type: field.TypeUUID},
	}
	// UserSessionsTable holds the schema information for the "user_sessions" table.
	UserSessionsTable = &schema.Table{
		Name:       "user_sessions",
		Columns:    UserSessionsColumns,
		PrimaryKey: []*schema.Column{UserSessionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "user_sessions_users_sessions",
				Columns:    []*schema.Column{UserSessionsColumns[9]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "usersession_active",
				Unique:  false,
				Columns: []*schema.Column{UserSessionsColumns[7]},
			},
		},
	}
	// UserBadgesColumns holds the columns for the "user_badges" table.
	UserBadgesColumns = []*schema.Column{
		{Name: "user_id", Type: field.TypeUUID},
		{Name: "badge_id", Type: field.TypeInt},
	}
	// UserBadgesTable holds the schema information for the "user_badges" table.
	UserBadgesTable = &schema.Table{
		Name:       "user_badges",
		Columns:    UserBadgesColumns,
		PrimaryKey: []*schema.Column{UserBadgesColumns[0], UserBadgesColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "user_badges_user_id",
				Columns:    []*schema.Column{UserBadgesColumns[0]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "user_badges_badge_id",
				Columns:    []*schema.Column{UserBadgesColumns[1]},
				RefColumns: []*schema.Column{BadgesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		BadgesTable,
		ChallengesTable,
		PredictionsTable,
		ProofsTable,
		UsersTable,
		UserSessionsTable,
		UserBadgesTable,
	}
)

Functions

This section is empty.

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