migrate

package
v0.0.0-...-910bef7 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 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 (
	// ActorsColumns holds the columns for the "actors" table.
	ActorsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// ActorsTable holds the schema information for the "actors" table.
	ActorsTable = &schema.Table{
		Name:       "actors",
		Columns:    ActorsColumns,
		PrimaryKey: []*schema.Column{ActorsColumns[0]},
	}
	// AlbumsColumns holds the columns for the "albums" table.
	AlbumsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "title", Type: field.TypeString},
		{Name: "date", Type: field.TypeString, Size: 20},
		{Name: "description", Type: field.TypeString, Nullable: true},
		{Name: "images_albums", Type: field.TypeUint64},
	}
	// AlbumsTable holds the schema information for the "albums" table.
	AlbumsTable = &schema.Table{
		Name:       "albums",
		Columns:    AlbumsColumns,
		PrimaryKey: []*schema.Column{AlbumsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "albums_images_albums",
				Columns:    []*schema.Column{AlbumsColumns[6]},
				RefColumns: []*schema.Column{ImagesColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// ArtistsColumns holds the columns for the "artists" table.
	ArtistsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "name", Type: field.TypeString, Unique: true},
	}
	// ArtistsTable holds the schema information for the "artists" table.
	ArtistsTable = &schema.Table{
		Name:       "artists",
		Columns:    ArtistsColumns,
		PrimaryKey: []*schema.Column{ArtistsColumns[0]},
	}
	// AudiobooksColumns holds the columns for the "audiobooks" table.
	AudiobooksColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// AudiobooksTable holds the schema information for the "audiobooks" table.
	AudiobooksTable = &schema.Table{
		Name:       "audiobooks",
		Columns:    AudiobooksColumns,
		PrimaryKey: []*schema.Column{AudiobooksColumns[0]},
	}
	// CategorysColumns holds the columns for the "categorys" table.
	CategorysColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// CategorysTable holds the schema information for the "categorys" table.
	CategorysTable = &schema.Table{
		Name:       "categorys",
		Columns:    CategorysColumns,
		PrimaryKey: []*schema.Column{CategorysColumns[0]},
	}
	// DevicesColumns holds the columns for the "devices" table.
	DevicesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "ip", Type: field.TypeString},
		{Name: "device", Type: field.TypeString},
		{Name: "users_devices", Type: field.TypeUint64, Nullable: true},
	}
	// DevicesTable holds the schema information for the "devices" table.
	DevicesTable = &schema.Table{
		Name:       "devices",
		Columns:    DevicesColumns,
		PrimaryKey: []*schema.Column{DevicesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "devices_users_devices",
				Columns:    []*schema.Column{DevicesColumns[5]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// DirectorsColumns holds the columns for the "directors" table.
	DirectorsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// DirectorsTable holds the schema information for the "directors" table.
	DirectorsTable = &schema.Table{
		Name:       "directors",
		Columns:    DirectorsColumns,
		PrimaryKey: []*schema.Column{DirectorsColumns[0]},
	}
	// FilesColumns holds the columns for the "files" table.
	FilesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "hash", Type: field.TypeString, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "size", Type: field.TypeUint64},
	}
	// FilesTable holds the schema information for the "files" table.
	FilesTable = &schema.Table{
		Name:       "files",
		Columns:    FilesColumns,
		PrimaryKey: []*schema.Column{FilesColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "files_hash",
				Unique:  true,
				Columns: []*schema.Column{FilesColumns[1]},
			},
		},
	}
	// ImagesColumns holds the columns for the "images" table.
	ImagesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "width", Type: field.TypeInt32},
		{Name: "height", Type: field.TypeInt32},
		{Name: "files_images", Type: field.TypeUint64},
	}
	// ImagesTable holds the schema information for the "images" table.
	ImagesTable = &schema.Table{
		Name:       "images",
		Columns:    ImagesColumns,
		PrimaryKey: []*schema.Column{ImagesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "images_files_images",
				Columns:    []*schema.Column{ImagesColumns[5]},
				RefColumns: []*schema.Column{FilesColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// MusicsColumns holds the columns for the "musics" table.
	MusicsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "description", Type: field.TypeString, Nullable: true, Size: 280},
		{Name: "files_musics", Type: field.TypeUint64},
	}
	// MusicsTable holds the schema information for the "musics" table.
	MusicsTable = &schema.Table{
		Name:       "musics",
		Columns:    MusicsColumns,
		PrimaryKey: []*schema.Column{MusicsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "musics_files_musics",
				Columns:    []*schema.Column{MusicsColumns[5]},
				RefColumns: []*schema.Column{FilesColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// OidcsColumns holds the columns for the "oidcs" table.
	OidcsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "configuration_endpoint", Type: field.TypeString},
	}
	// OidcsTable holds the schema information for the "oidcs" table.
	OidcsTable = &schema.Table{
		Name:       "oidcs",
		Columns:    OidcsColumns,
		PrimaryKey: []*schema.Column{OidcsColumns[0]},
	}
	// PlaylistsColumns holds the columns for the "playlists" table.
	PlaylistsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "description", Type: field.TypeString, Nullable: true},
		{Name: "private", Type: field.TypeBool, Default: false},
		{Name: "images_playlists", Type: field.TypeUint64, Nullable: true},
		{Name: "users_playlists", Type: field.TypeUint64},
	}
	// PlaylistsTable holds the schema information for the "playlists" table.
	PlaylistsTable = &schema.Table{
		Name:       "playlists",
		Columns:    PlaylistsColumns,
		PrimaryKey: []*schema.Column{PlaylistsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "playlists_images_playlists",
				Columns:    []*schema.Column{PlaylistsColumns[6]},
				RefColumns: []*schema.Column{ImagesColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "playlists_users_playlists",
				Columns:    []*schema.Column{PlaylistsColumns[7]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUint64, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "username", Type: field.TypeString, Unique: true, Size: 255},
		{Name: "password", Type: field.TypeString, Nullable: true},
		{Name: "email", Type: field.TypeString, Unique: true, Nullable: true},
		{Name: "name", Type: field.TypeString, Nullable: true},
		{Name: "bio", Type: field.TypeString, Nullable: true},
		{Name: "avatar", Type: field.TypeString, Nullable: true},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
	}
	// VideosColumns holds the columns for the "videos" table.
	VideosColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// VideosTable holds the schema information for the "videos" table.
	VideosTable = &schema.Table{
		Name:       "videos",
		Columns:    VideosColumns,
		PrimaryKey: []*schema.Column{VideosColumns[0]},
	}
	// AlbumsMusicsColumns holds the columns for the "albums_musics" table.
	AlbumsMusicsColumns = []*schema.Column{
		{Name: "albums_id", Type: field.TypeUint64},
		{Name: "musics_id", Type: field.TypeUint64},
	}
	// AlbumsMusicsTable holds the schema information for the "albums_musics" table.
	AlbumsMusicsTable = &schema.Table{
		Name:       "albums_musics",
		Columns:    AlbumsMusicsColumns,
		PrimaryKey: []*schema.Column{AlbumsMusicsColumns[0], AlbumsMusicsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "albums_musics_albums_id",
				Columns:    []*schema.Column{AlbumsMusicsColumns[0]},
				RefColumns: []*schema.Column{AlbumsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "albums_musics_musics_id",
				Columns:    []*schema.Column{AlbumsMusicsColumns[1]},
				RefColumns: []*schema.Column{MusicsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// ArtistsMusicsColumns holds the columns for the "artists_musics" table.
	ArtistsMusicsColumns = []*schema.Column{
		{Name: "artists_id", Type: field.TypeUint64},
		{Name: "musics_id", Type: field.TypeUint64},
	}
	// ArtistsMusicsTable holds the schema information for the "artists_musics" table.
	ArtistsMusicsTable = &schema.Table{
		Name:       "artists_musics",
		Columns:    ArtistsMusicsColumns,
		PrimaryKey: []*schema.Column{ArtistsMusicsColumns[0], ArtistsMusicsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "artists_musics_artists_id",
				Columns:    []*schema.Column{ArtistsMusicsColumns[0]},
				RefColumns: []*schema.Column{ArtistsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "artists_musics_musics_id",
				Columns:    []*schema.Column{ArtistsMusicsColumns[1]},
				RefColumns: []*schema.Column{MusicsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// ArtistsAlbumsColumns holds the columns for the "artists_albums" table.
	ArtistsAlbumsColumns = []*schema.Column{
		{Name: "artists_id", Type: field.TypeUint64},
		{Name: "albums_id", Type: field.TypeUint64},
	}
	// ArtistsAlbumsTable holds the schema information for the "artists_albums" table.
	ArtistsAlbumsTable = &schema.Table{
		Name:       "artists_albums",
		Columns:    ArtistsAlbumsColumns,
		PrimaryKey: []*schema.Column{ArtistsAlbumsColumns[0], ArtistsAlbumsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "artists_albums_artists_id",
				Columns:    []*schema.Column{ArtistsAlbumsColumns[0]},
				RefColumns: []*schema.Column{ArtistsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "artists_albums_albums_id",
				Columns:    []*schema.Column{ArtistsAlbumsColumns[1]},
				RefColumns: []*schema.Column{AlbumsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// PlaylistsMusicsColumns holds the columns for the "playlists_musics" table.
	PlaylistsMusicsColumns = []*schema.Column{
		{Name: "playlists_id", Type: field.TypeUint64},
		{Name: "musics_id", Type: field.TypeUint64},
	}
	// PlaylistsMusicsTable holds the schema information for the "playlists_musics" table.
	PlaylistsMusicsTable = &schema.Table{
		Name:       "playlists_musics",
		Columns:    PlaylistsMusicsColumns,
		PrimaryKey: []*schema.Column{PlaylistsMusicsColumns[0], PlaylistsMusicsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "playlists_musics_playlists_id",
				Columns:    []*schema.Column{PlaylistsMusicsColumns[0]},
				RefColumns: []*schema.Column{PlaylistsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "playlists_musics_musics_id",
				Columns:    []*schema.Column{PlaylistsMusicsColumns[1]},
				RefColumns: []*schema.Column{MusicsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// UsersAlbumsColumns holds the columns for the "users_albums" table.
	UsersAlbumsColumns = []*schema.Column{
		{Name: "users_id", Type: field.TypeUint64},
		{Name: "albums_id", Type: field.TypeUint64},
	}
	// UsersAlbumsTable holds the schema information for the "users_albums" table.
	UsersAlbumsTable = &schema.Table{
		Name:       "users_albums",
		Columns:    UsersAlbumsColumns,
		PrimaryKey: []*schema.Column{UsersAlbumsColumns[0], UsersAlbumsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "users_albums_users_id",
				Columns:    []*schema.Column{UsersAlbumsColumns[0]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "users_albums_albums_id",
				Columns:    []*schema.Column{UsersAlbumsColumns[1]},
				RefColumns: []*schema.Column{AlbumsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// UsersMusicsColumns holds the columns for the "users_musics" table.
	UsersMusicsColumns = []*schema.Column{
		{Name: "users_id", Type: field.TypeUint64},
		{Name: "musics_id", Type: field.TypeUint64},
	}
	// UsersMusicsTable holds the schema information for the "users_musics" table.
	UsersMusicsTable = &schema.Table{
		Name:       "users_musics",
		Columns:    UsersMusicsColumns,
		PrimaryKey: []*schema.Column{UsersMusicsColumns[0], UsersMusicsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "users_musics_users_id",
				Columns:    []*schema.Column{UsersMusicsColumns[0]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "users_musics_musics_id",
				Columns:    []*schema.Column{UsersMusicsColumns[1]},
				RefColumns: []*schema.Column{MusicsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		ActorsTable,
		AlbumsTable,
		ArtistsTable,
		AudiobooksTable,
		CategorysTable,
		DevicesTable,
		DirectorsTable,
		FilesTable,
		ImagesTable,
		MusicsTable,
		OidcsTable,
		PlaylistsTable,
		UsersTable,
		VideosTable,
		AlbumsMusicsTable,
		ArtistsMusicsTable,
		ArtistsAlbumsTable,
		PlaylistsMusicsTable,
		UsersAlbumsTable,
		UsersMusicsTable,
	}
)

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