migrate

package
v0.0.0-...-42c0c98 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT 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 (
	// ActionsColumns holds the columns for the "actions" table.
	ActionsColumns = []*schema.Column{
		{Name: "oid", Type: field.TypeUUID},
		{Name: "ip_address", Type: field.TypeString, Default: ""},
		{Name: "type", Type: field.TypeEnum, Enums: []string{"SIGN_IN", "FAILED_SIGN_IN", "SIGN_OUT", "API_CALL", "CONSOLE_ACCESS", "POWER_STATE", "REBOOT", "SHUTDOWN", "POWER_ON", "POWER_OFF", "CHANGE_SELF_PASSWORD", "CHANGE_PASSWORD", "CREATE_OBJECT", "UPDATE_OBJECT", "DELETE_OBJECT", "UPDATE_LOCKOUT"}},
		{Name: "message", Type: field.TypeString},
		{Name: "performed_at", Type: field.TypeTime},
		{Name: "service_account_service_account_to_actions", Type: field.TypeUUID, Nullable: true},
		{Name: "user_user_to_actions", Type: field.TypeUUID, Nullable: true},
	}
	// ActionsTable holds the schema information for the "actions" table.
	ActionsTable = &schema.Table{
		Name:       "actions",
		Columns:    ActionsColumns,
		PrimaryKey: []*schema.Column{ActionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "actions_service_accounts_ServiceAccountToActions",
				Columns:    []*schema.Column{ActionsColumns[5]},
				RefColumns: []*schema.Column{ServiceAccountsColumns[0]},
				OnDelete:   schema.Restrict,
			},
			{
				Symbol:     "actions_users_UserToActions",
				Columns:    []*schema.Column{ActionsColumns[6]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// CompetitionsColumns holds the columns for the "competitions" table.
	CompetitionsColumns = []*schema.Column{
		{Name: "oid", Type: field.TypeUUID},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "competition_competition_to_provider", Type: field.TypeUUID},
	}
	// CompetitionsTable holds the schema information for the "competitions" table.
	CompetitionsTable = &schema.Table{
		Name:       "competitions",
		Columns:    CompetitionsColumns,
		PrimaryKey: []*schema.Column{CompetitionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "competitions_providers_CompetitionToProvider",
				Columns:    []*schema.Column{CompetitionsColumns[2]},
				RefColumns: []*schema.Column{ProvidersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// ProvidersColumns holds the columns for the "providers" table.
	ProvidersColumns = []*schema.Column{
		{Name: "oid", Type: field.TypeUUID},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "type", Type: field.TypeString},
		{Name: "config", Type: field.TypeString},
	}
	// ProvidersTable holds the schema information for the "providers" table.
	ProvidersTable = &schema.Table{
		Name:       "providers",
		Columns:    ProvidersColumns,
		PrimaryKey: []*schema.Column{ProvidersColumns[0]},
	}
	// ServiceAccountsColumns holds the columns for the "service_accounts" table.
	ServiceAccountsColumns = []*schema.Column{
		{Name: "oid", Type: field.TypeUUID},
		{Name: "display_name", Type: field.TypeString},
		{Name: "api_key", Type: field.TypeUUID},
		{Name: "api_secret", Type: field.TypeUUID},
		{Name: "active", Type: field.TypeBool},
	}
	// ServiceAccountsTable holds the schema information for the "service_accounts" table.
	ServiceAccountsTable = &schema.Table{
		Name:       "service_accounts",
		Columns:    ServiceAccountsColumns,
		PrimaryKey: []*schema.Column{ServiceAccountsColumns[0]},
	}
	// ServiceTokensColumns holds the columns for the "service_tokens" table.
	ServiceTokensColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "token", Type: field.TypeString},
		{Name: "refresh_token", Type: field.TypeString},
		{Name: "issued_at", Type: field.TypeInt64},
		{Name: "service_account_service_account_to_token", Type: field.TypeUUID},
	}
	// ServiceTokensTable holds the schema information for the "service_tokens" table.
	ServiceTokensTable = &schema.Table{
		Name:       "service_tokens",
		Columns:    ServiceTokensColumns,
		PrimaryKey: []*schema.Column{ServiceTokensColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "service_tokens_service_accounts_ServiceAccountToToken",
				Columns:    []*schema.Column{ServiceTokensColumns[4]},
				RefColumns: []*schema.Column{ServiceAccountsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// TeamsColumns holds the columns for the "teams" table.
	TeamsColumns = []*schema.Column{
		{Name: "oid", Type: field.TypeUUID},
		{Name: "team_number", Type: field.TypeInt},
		{Name: "name", Type: field.TypeString, Nullable: true},
		{Name: "competition_competition_to_teams", Type: field.TypeUUID},
	}
	// TeamsTable holds the schema information for the "teams" table.
	TeamsTable = &schema.Table{
		Name:       "teams",
		Columns:    TeamsColumns,
		PrimaryKey: []*schema.Column{TeamsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "teams_competitions_CompetitionToTeams",
				Columns:    []*schema.Column{TeamsColumns[3]},
				RefColumns: []*schema.Column{CompetitionsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// TokensColumns holds the columns for the "tokens" table.
	TokensColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "token", Type: field.TypeString},
		{Name: "expire_at", Type: field.TypeInt64},
		{Name: "user_user_to_token", Type: field.TypeUUID},
	}
	// TokensTable holds the schema information for the "tokens" table.
	TokensTable = &schema.Table{
		Name:       "tokens",
		Columns:    TokensColumns,
		PrimaryKey: []*schema.Column{TokensColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "tokens_users_UserToToken",
				Columns:    []*schema.Column{TokensColumns[3]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "oid", Type: field.TypeUUID},
		{Name: "username", Type: field.TypeString},
		{Name: "password", Type: field.TypeString},
		{Name: "first_name", Type: field.TypeString, Default: ""},
		{Name: "last_name", Type: field.TypeString, Default: ""},
		{Name: "role", Type: field.TypeEnum, Enums: []string{"USER", "ADMIN"}},
		{Name: "provider", Type: field.TypeEnum, Enums: []string{"LOCAL", "GITLAB"}},
		{Name: "team_team_to_users", Type: field.TypeUUID, 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_teams_TeamToUsers",
				Columns:    []*schema.Column{UsersColumns[7]},
				RefColumns: []*schema.Column{TeamsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// VMObjectsColumns holds the columns for the "vm_objects" table.
	VMObjectsColumns = []*schema.Column{
		{Name: "oid", Type: field.TypeUUID},
		{Name: "name", Type: field.TypeString},
		{Name: "identifier", Type: field.TypeString},
		{Name: "ip_addresses", Type: field.TypeJSON, Nullable: true},
		{Name: "locked", Type: field.TypeBool, Default: false},
		{Name: "team_team_to_vm_objects", Type: field.TypeUUID, Nullable: true},
	}
	// VMObjectsTable holds the schema information for the "vm_objects" table.
	VMObjectsTable = &schema.Table{
		Name:       "vm_objects",
		Columns:    VMObjectsColumns,
		PrimaryKey: []*schema.Column{VMObjectsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "vm_objects_teams_TeamToVmObjects",
				Columns:    []*schema.Column{VMObjectsColumns[5]},
				RefColumns: []*schema.Column{TeamsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		ActionsTable,
		CompetitionsTable,
		ProvidersTable,
		ServiceAccountsTable,
		ServiceTokensTable,
		TeamsTable,
		TokensTable,
		UsersTable,
		VMObjectsTable,
	}
)

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