migrate

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: GPL-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
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// GuildsColumns holds the columns for the "guilds" table.
	GuildsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "name", Type: field.TypeString},
		{Name: "locale", Type: field.TypeString, Default: "ja"},
		{Name: "level_up_message", Type: field.TypeString, Default: "{user}がレベルアップしたよ!🥳\n**{before_level} レベル → {after_level} レベル**"},
		{Name: "level_up_channel", Type: field.TypeUint64, Nullable: true},
		{Name: "level_up_exclude_channel", Type: field.TypeJSON, Nullable: true},
		{Name: "level_mee6_imported", Type: field.TypeBool, Default: false},
		{Name: "level_role", Type: field.TypeJSON, Nullable: true},
		{Name: "permissions", Type: field.TypeJSON},
		{Name: "remind_count", Type: field.TypeInt, Default: 0},
		{Name: "role_panel_edit_times", Type: field.TypeJSON, Default: "[]"},
		{Name: "bump_enabled", Type: field.TypeBool, Default: true},
		{Name: "bump_message_title", Type: field.TypeString, Default: "Bumpを検知しました"},
		{Name: "bump_message", Type: field.TypeString, Default: "2時間後に通知します"},
		{Name: "bump_remind_message_title", Type: field.TypeString, Default: "Bumpの時間です"},
		{Name: "bump_remind_message", Type: field.TypeString, Default: "</bump:947088344167366698>でBumpしましょう"},
		{Name: "up_enabled", Type: field.TypeBool, Default: true},
		{Name: "up_message_title", Type: field.TypeString, Default: "UPを検知しました"},
		{Name: "up_message", Type: field.TypeString, Default: "1時間後に通知します"},
		{Name: "up_remind_message_title", Type: field.TypeString, Default: "UPの時間です"},
		{Name: "up_remind_message", Type: field.TypeString, Default: "</dissoku up:828002256690610256>でUPしましょう"},
		{Name: "bump_mention", Type: field.TypeUint64, Nullable: true},
		{Name: "up_mention", Type: field.TypeUint64, Nullable: true},
		{Name: "user_own_guilds", Type: field.TypeUint64},
	}
	// GuildsTable holds the schema information for the "guilds" table.
	GuildsTable = &schema.Table{
		Name:       "guilds",
		Columns:    GuildsColumns,
		PrimaryKey: []*schema.Column{GuildsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "guilds_users_own_guilds",
				Columns:    []*schema.Column{GuildsColumns[23]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// MembersColumns holds the columns for the "members" table.
	MembersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "permission", Type: field.TypeJSON, Nullable: true},
		{Name: "xp", Type: field.TypeUint64, Default: 0},
		{Name: "last_xp", Type: field.TypeTime, Nullable: true},
		{Name: "message_count", Type: field.TypeUint64, Default: 0},
		{Name: "last_notified_level", Type: field.TypeUint64, Nullable: true},
		{Name: "guild_members", Type: field.TypeUint64},
		{Name: "user_id", Type: field.TypeUint64},
	}
	// MembersTable holds the schema information for the "members" table.
	MembersTable = &schema.Table{
		Name:       "members",
		Columns:    MembersColumns,
		PrimaryKey: []*schema.Column{MembersColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "members_guilds_members",
				Columns:    []*schema.Column{MembersColumns[6]},
				RefColumns: []*schema.Column{GuildsColumns[0]},
				OnDelete:   schema.NoAction,
			},
			{
				Symbol:     "members_users_guilds",
				Columns:    []*schema.Column{MembersColumns[7]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// MessagePinsColumns holds the columns for the "message_pins" table.
	MessagePinsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "channel_id", Type: field.TypeUint64, Unique: true},
		{Name: "content", Type: field.TypeString, Nullable: true},
		{Name: "embeds", Type: field.TypeJSON, Nullable: true},
		{Name: "before_id", Type: field.TypeUint64, Nullable: true},
		{Name: "rate_limit", Type: field.TypeJSON},
		{Name: "guild_message_pins", Type: field.TypeUint64},
	}
	// MessagePinsTable holds the schema information for the "message_pins" table.
	MessagePinsTable = &schema.Table{
		Name:       "message_pins",
		Columns:    MessagePinsColumns,
		PrimaryKey: []*schema.Column{MessagePinsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "message_pins_guilds_message_pins",
				Columns:    []*schema.Column{MessagePinsColumns[6]},
				RefColumns: []*schema.Column{GuildsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// MessageRemindsColumns holds the columns for the "message_reminds" table.
	MessageRemindsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "channel_id", Type: field.TypeUint64},
		{Name: "author_id", Type: field.TypeUint64},
		{Name: "time", Type: field.TypeTime},
		{Name: "content", Type: field.TypeString},
		{Name: "name", Type: field.TypeString},
		{Name: "guild_reminds", Type: field.TypeUint64},
	}
	// MessageRemindsTable holds the schema information for the "message_reminds" table.
	MessageRemindsTable = &schema.Table{
		Name:       "message_reminds",
		Columns:    MessageRemindsColumns,
		PrimaryKey: []*schema.Column{MessageRemindsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "message_reminds_guilds_reminds",
				Columns:    []*schema.Column{MessageRemindsColumns[6]},
				RefColumns: []*schema.Column{GuildsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// RolePanelsColumns holds the columns for the "role_panels" table.
	RolePanelsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "description", Type: field.TypeString},
		{Name: "roles", Type: field.TypeJSON, Nullable: true},
		{Name: "updated_at", Type: field.TypeTime, Nullable: true},
		{Name: "applied_at", Type: field.TypeTime, Nullable: true},
		{Name: "guild_role_panels", Type: field.TypeUint64},
	}
	// RolePanelsTable holds the schema information for the "role_panels" table.
	RolePanelsTable = &schema.Table{
		Name:       "role_panels",
		Columns:    RolePanelsColumns,
		PrimaryKey: []*schema.Column{RolePanelsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "role_panels_guilds_role_panels",
				Columns:    []*schema.Column{RolePanelsColumns[6]},
				RefColumns: []*schema.Column{GuildsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// RolePanelEditsColumns holds the columns for the "role_panel_edits" table.
	RolePanelEditsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "channel_id", Type: field.TypeUint64},
		{Name: "emoji_author", Type: field.TypeUint64, Nullable: true},
		{Name: "token", Type: field.TypeString, Nullable: true},
		{Name: "selected_role", Type: field.TypeUint64, Nullable: true},
		{Name: "modified", Type: field.TypeBool, Default: false},
		{Name: "name", Type: field.TypeString, Nullable: true},
		{Name: "description", Type: field.TypeString, Nullable: true},
		{Name: "roles", Type: field.TypeJSON, Nullable: true},
		{Name: "guild_role_panel_edits", Type: field.TypeUint64},
		{Name: "role_panel_edit", Type: field.TypeUUID, Unique: true},
	}
	// RolePanelEditsTable holds the schema information for the "role_panel_edits" table.
	RolePanelEditsTable = &schema.Table{
		Name:       "role_panel_edits",
		Columns:    RolePanelEditsColumns,
		PrimaryKey: []*schema.Column{RolePanelEditsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "role_panel_edits_guilds_role_panel_edits",
				Columns:    []*schema.Column{RolePanelEditsColumns[9]},
				RefColumns: []*schema.Column{GuildsColumns[0]},
				OnDelete:   schema.NoAction,
			},
			{
				Symbol:     "role_panel_edits_role_panels_edit",
				Columns:    []*schema.Column{RolePanelEditsColumns[10]},
				RefColumns: []*schema.Column{RolePanelsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// RolePanelPlacedsColumns holds the columns for the "role_panel_placeds" table.
	RolePanelPlacedsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "message_id", Type: field.TypeUint64, Nullable: true},
		{Name: "channel_id", Type: field.TypeUint64},
		{Name: "type", Type: field.TypeEnum, Nullable: true, Enums: []string{"button", "reaction", "select_menu"}},
		{Name: "button_type", Type: field.TypeInt, Default: 1},
		{Name: "show_name", Type: field.TypeBool, Default: false},
		{Name: "folding_select_menu", Type: field.TypeBool, Default: true},
		{Name: "hide_notice", Type: field.TypeBool, Default: false},
		{Name: "use_display_name", Type: field.TypeBool, Default: false},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "uses", Type: field.TypeInt, Default: 0},
		{Name: "name", Type: field.TypeString},
		{Name: "description", Type: field.TypeString},
		{Name: "roles", Type: field.TypeJSON, Nullable: true},
		{Name: "updated_at", Type: field.TypeTime, Nullable: true},
		{Name: "guild_role_panel_placements", Type: field.TypeUint64},
		{Name: "role_panel_placements", Type: field.TypeUUID},
	}
	// RolePanelPlacedsTable holds the schema information for the "role_panel_placeds" table.
	RolePanelPlacedsTable = &schema.Table{
		Name:       "role_panel_placeds",
		Columns:    RolePanelPlacedsColumns,
		PrimaryKey: []*schema.Column{RolePanelPlacedsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "role_panel_placeds_guilds_role_panel_placements",
				Columns:    []*schema.Column{RolePanelPlacedsColumns[15]},
				RefColumns: []*schema.Column{GuildsColumns[0]},
				OnDelete:   schema.NoAction,
			},
			{
				Symbol:     "role_panel_placeds_role_panels_placements",
				Columns:    []*schema.Column{RolePanelPlacedsColumns[16]},
				RefColumns: []*schema.Column{RolePanelsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "name", Type: field.TypeString},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "locale", Type: field.TypeString, Default: "ja"},
		{Name: "xp", Type: field.TypeUint64, Default: 0},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
	}
	// WordSuffixesColumns holds the columns for the "word_suffixes" table.
	WordSuffixesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "suffix", Type: field.TypeString},
		{Name: "expired", Type: field.TypeTime, Nullable: true},
		{Name: "rule", Type: field.TypeEnum, Enums: []string{"webhook", "warn", "delete"}, Default: "webhook"},
		{Name: "user_word_suffix", Type: field.TypeUint64},
		{Name: "guild_id", Type: field.TypeUint64, Nullable: true},
	}
	// WordSuffixesTable holds the schema information for the "word_suffixes" table.
	WordSuffixesTable = &schema.Table{
		Name:       "word_suffixes",
		Columns:    WordSuffixesColumns,
		PrimaryKey: []*schema.Column{WordSuffixesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "word_suffixes_users_word_suffix",
				Columns:    []*schema.Column{WordSuffixesColumns[4]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
			{
				Symbol:     "word_suffixes_guilds_guild",
				Columns:    []*schema.Column{WordSuffixesColumns[5]},
				RefColumns: []*schema.Column{GuildsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		GuildsTable,
		MembersTable,
		MessagePinsTable,
		MessageRemindsTable,
		RolePanelsTable,
		RolePanelEditsTable,
		RolePanelPlacedsTable,
		UsersTable,
		WordSuffixesTable,
	}
)

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