migrate

package
v0.0.0-...-3c02646 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MPL-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 (
	// ActivationsColumns holds the columns for the "activations" table.
	ActivationsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "internal_comments", Type: field.TypeString, Nullable: true},
		{Name: "comments", Type: field.TypeString, Nullable: true},
	}
	// ActivationsTable holds the schema information for the "activations" table.
	ActivationsTable = &schema.Table{
		Name:        "activations",
		Columns:     ActivationsColumns,
		PrimaryKey:  []*schema.Column{ActivationsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// AuthSessionsColumns holds the columns for the "auth_sessions" table.
	AuthSessionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
	}
	// AuthSessionsTable holds the schema information for the "auth_sessions" table.
	AuthSessionsTable = &schema.Table{
		Name:        "auth_sessions",
		Columns:     AuthSessionsColumns,
		PrimaryKey:  []*schema.Column{AuthSessionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// MapLayersColumns holds the columns for the "map_layers" table.
	MapLayersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "url_template", Type: field.TypeString},
		{Name: "is_public", Type: field.TypeBool},
		{Name: "map_layer_metadata", Type: field.TypeInt, Nullable: true},
		{Name: "map_layer_map_type", Type: field.TypeInt, Nullable: true},
	}
	// MapLayersTable holds the schema information for the "map_layers" table.
	MapLayersTable = &schema.Table{
		Name:       "map_layers",
		Columns:    MapLayersColumns,
		PrimaryKey: []*schema.Column{MapLayersColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "map_layers_metadata_metadata",
				Columns: []*schema.Column{MapLayersColumns[6]},

				RefColumns: []*schema.Column{MetadataColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:  "map_layers_map_types_map_type",
				Columns: []*schema.Column{MapLayersColumns[7]},

				RefColumns: []*schema.Column{MapTypesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// MapTypesColumns holds the columns for the "map_types" table.
	MapTypesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "min_zoom", Type: field.TypeInt},
		{Name: "max_zoom", Type: field.TypeInt},
		{Name: "min_x", Type: field.TypeFloat64},
		{Name: "min_y", Type: field.TypeFloat64},
		{Name: "max_x", Type: field.TypeFloat64},
		{Name: "max_y", Type: field.TypeFloat64},
	}
	// MapTypesTable holds the schema information for the "map_types" table.
	MapTypesTable = &schema.Table{
		Name:        "map_types",
		Columns:     MapTypesColumns,
		PrimaryKey:  []*schema.Column{MapTypesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// MetadataColumns holds the columns for the "metadata" table.
	MetadataColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "data", Type: field.TypeJSON},
		{Name: "map_type_metadata", Type: field.TypeInt, Unique: true, Nullable: true},
		{Name: "user_metadata", Type: field.TypeInt, Unique: true, Nullable: true},
	}
	// MetadataTable holds the schema information for the "metadata" table.
	MetadataTable = &schema.Table{
		Name:       "metadata",
		Columns:    MetadataColumns,
		PrimaryKey: []*schema.Column{MetadataColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "metadata_map_types_metadata",
				Columns: []*schema.Column{MetadataColumns[2]},

				RefColumns: []*schema.Column{MapTypesColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:  "metadata_users_metadata",
				Columns: []*schema.Column{MetadataColumns[3]},

				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// PlayersColumns holds the columns for the "players" table.
	PlayersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "total_minutes", Type: field.TypeInt},
		{Name: "session_started_at", Type: field.TypeTime, Nullable: true},
		{Name: "session_ended_at", Type: field.TypeTime, Nullable: true},
		{Name: "last_seen_at", Type: field.TypeTime, Nullable: true},
		{Name: "player_metadata", Type: field.TypeInt, Nullable: true},
		{Name: "player_user", Type: field.TypeInt, Nullable: true},
	}
	// PlayersTable holds the schema information for the "players" table.
	PlayersTable = &schema.Table{
		Name:       "players",
		Columns:    PlayersColumns,
		PrimaryKey: []*schema.Column{PlayersColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "players_metadata_metadata",
				Columns: []*schema.Column{PlayersColumns[8]},

				RefColumns: []*schema.Column{MetadataColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:  "players_users_user",
				Columns: []*schema.Column{PlayersColumns[9]},

				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// PlayerIdentifiersColumns holds the columns for the "player_identifiers" table.
	PlayerIdentifiersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "type", Type: field.TypeString},
		{Name: "identifier", Type: field.TypeString},
		{Name: "player_identifier_metadata", Type: field.TypeInt, Nullable: true},
		{Name: "player_identifier_player", Type: field.TypeInt, Nullable: true},
	}
	// PlayerIdentifiersTable holds the schema information for the "player_identifiers" table.
	PlayerIdentifiersTable = &schema.Table{
		Name:       "player_identifiers",
		Columns:    PlayerIdentifiersColumns,
		PrimaryKey: []*schema.Column{PlayerIdentifiersColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "player_identifiers_metadata_metadata",
				Columns: []*schema.Column{PlayerIdentifiersColumns[5]},

				RefColumns: []*schema.Column{MetadataColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:  "player_identifiers_players_player",
				Columns: []*schema.Column{PlayerIdentifiersColumns[6]},

				RefColumns: []*schema.Column{PlayersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "playeridentifier_type_identifier_player_identifier_player",
				Unique:  true,
				Columns: []*schema.Column{PlayerIdentifiersColumns[3], PlayerIdentifiersColumns[4], PlayerIdentifiersColumns[6]},
			},
		},
	}
	// ServersColumns holds the columns for the "servers" table.
	ServersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "api_username", Type: field.TypeString, Nullable: true},
		{Name: "api_secret", Type: field.TypeString, Nullable: true},
		{Name: "api_address", Type: field.TypeString, Nullable: true},
		{Name: "api_port", Type: field.TypeString, Nullable: true},
		{Name: "server_metadata", Type: field.TypeInt, Nullable: true},
		{Name: "server_server_type", Type: field.TypeInt, Nullable: true},
		{Name: "server_map_type", Type: field.TypeInt, Nullable: true},
	}
	// ServersTable holds the schema information for the "servers" table.
	ServersTable = &schema.Table{
		Name:       "servers",
		Columns:    ServersColumns,
		PrimaryKey: []*schema.Column{ServersColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "servers_metadata_metadata",
				Columns: []*schema.Column{ServersColumns[8]},

				RefColumns: []*schema.Column{MetadataColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:  "servers_server_types_server_type",
				Columns: []*schema.Column{ServersColumns[9]},

				RefColumns: []*schema.Column{ServerTypesColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:  "servers_map_types_map_type",
				Columns: []*schema.Column{ServersColumns[10]},

				RefColumns: []*schema.Column{MapTypesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ServerTypesColumns holds the columns for the "server_types" table.
	ServerTypesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "key", Type: field.TypeString, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "description", Type: field.TypeString, Nullable: true, Size: 2147483647},
	}
	// ServerTypesTable holds the schema information for the "server_types" table.
	ServerTypesTable = &schema.Table{
		Name:        "server_types",
		Columns:     ServerTypesColumns,
		PrimaryKey:  []*schema.Column{ServerTypesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// SessionsColumns holds the columns for the "sessions" table.
	SessionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "create_time", Type: field.TypeTime},
		{Name: "update_time", Type: field.TypeTime},
		{Name: "ip_address", Type: field.TypeString},
		{Name: "browser_name", Type: field.TypeString},
		{Name: "browser_version", Type: field.TypeString},
		{Name: "device_os", Type: field.TypeString},
		{Name: "device_type", Type: field.TypeString},
		{Name: "terminated_at", Type: field.TypeTime, Nullable: true},
		{Name: "token_session", Type: field.TypeInt, Unique: true, Nullable: true},
		{Name: "user_sessions", Type: field.TypeInt, Nullable: true},
	}
	// SessionsTable holds the schema information for the "sessions" table.
	SessionsTable = &schema.Table{
		Name:       "sessions",
		Columns:    SessionsColumns,
		PrimaryKey: []*schema.Column{SessionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "sessions_tokens_session",
				Columns: []*schema.Column{SessionsColumns[9]},

				RefColumns: []*schema.Column{TokensColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:  "sessions_users_sessions",
				Columns: []*schema.Column{SessionsColumns[10]},

				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// TokensColumns holds the columns for the "tokens" table.
	TokensColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "expired_at", Type: field.TypeTime},
		{Name: "blocked_at", Type: field.TypeTime, Nullable: true},
		{Name: "claims", Type: field.TypeString, Size: 2147483647},
	}
	// TokensTable holds the schema information for the "tokens" table.
	TokensTable = &schema.Table{
		Name:        "tokens",
		Columns:     TokensColumns,
		PrimaryKey:  []*schema.Column{TokensColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "name", Type: field.TypeString},
		{Name: "email", Type: field.TypeString},
		{Name: "password", Type: field.TypeString, Nullable: true},
		{Name: "is_system", Type: field.TypeBool},
		{Name: "disabled_at", Type: field.TypeTime, Nullable: true},
		{Name: "disabled_reason", Type: field.TypeString, Nullable: true, Size: 2147483647},
		{Name: "activated_at", Type: field.TypeTime, Nullable: true},
		{Name: "activation_comment", Type: field.TypeString, Nullable: true, Size: 2147483647},
		{Name: "activation_user", Type: field.TypeInt, Nullable: true},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "users_activations_user",
				Columns: []*schema.Column{UsersColumns[11]},

				RefColumns: []*schema.Column{ActivationsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ActivationActorColumns holds the columns for the "activation_actor" table.
	ActivationActorColumns = []*schema.Column{
		{Name: "activation_id", Type: field.TypeInt},
		{Name: "user_id", Type: field.TypeInt},
	}
	// ActivationActorTable holds the schema information for the "activation_actor" table.
	ActivationActorTable = &schema.Table{
		Name:       "activation_actor",
		Columns:    ActivationActorColumns,
		PrimaryKey: []*schema.Column{ActivationActorColumns[0], ActivationActorColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "activation_actor_activation_id",
				Columns: []*schema.Column{ActivationActorColumns[0]},

				RefColumns: []*schema.Column{ActivationsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:  "activation_actor_user_id",
				Columns: []*schema.Column{ActivationActorColumns[1]},

				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// PlayerServersColumns holds the columns for the "player_servers" table.
	PlayerServersColumns = []*schema.Column{
		{Name: "player_id", Type: field.TypeInt},
		{Name: "server_id", Type: field.TypeInt},
	}
	// PlayerServersTable holds the schema information for the "player_servers" table.
	PlayerServersTable = &schema.Table{
		Name:       "player_servers",
		Columns:    PlayerServersColumns,
		PrimaryKey: []*schema.Column{PlayerServersColumns[0], PlayerServersColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "player_servers_player_id",
				Columns: []*schema.Column{PlayerServersColumns[0]},

				RefColumns: []*schema.Column{PlayersColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:  "player_servers_server_id",
				Columns: []*schema.Column{PlayerServersColumns[1]},

				RefColumns: []*schema.Column{ServersColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		ActivationsTable,
		AuthSessionsTable,
		MapLayersTable,
		MapTypesTable,
		MetadataTable,
		PlayersTable,
		PlayerIdentifiersTable,
		ServersTable,
		ServerTypesTable,
		SessionsTable,
		TokensTable,
		UsersTable,
		ActivationActorTable,
		PlayerServersTable,
	}
)

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