migrate

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.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 (
	// IntegrationsColumns holds the columns for the "integrations" table.
	IntegrationsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "kind", Type: field.TypeString},
		{Name: "secret_name", Type: field.TypeString},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "config", Type: field.TypeBytes},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "organization_integrations", Type: field.TypeUUID},
	}
	// IntegrationsTable holds the schema information for the "integrations" table.
	IntegrationsTable = &schema.Table{
		Name:       "integrations",
		Columns:    IntegrationsColumns,
		PrimaryKey: []*schema.Column{IntegrationsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "integrations_organizations_integrations",
				Columns:    []*schema.Column{IntegrationsColumns[6]},
				RefColumns: []*schema.Column{OrganizationsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// IntegrationAttachmentsColumns holds the columns for the "integration_attachments" table.
	IntegrationAttachmentsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "config", Type: field.TypeBytes},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "integration_attachment_integration", Type: field.TypeUUID},
		{Name: "integration_attachment_workflow", Type: field.TypeUUID},
	}
	// IntegrationAttachmentsTable holds the schema information for the "integration_attachments" table.
	IntegrationAttachmentsTable = &schema.Table{
		Name:       "integration_attachments",
		Columns:    IntegrationAttachmentsColumns,
		PrimaryKey: []*schema.Column{IntegrationAttachmentsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "integration_attachments_integrations_integration",
				Columns:    []*schema.Column{IntegrationAttachmentsColumns[4]},
				RefColumns: []*schema.Column{IntegrationsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "integration_attachments_workflows_workflow",
				Columns:    []*schema.Column{IntegrationAttachmentsColumns[5]},
				RefColumns: []*schema.Column{WorkflowsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// MembershipsColumns holds the columns for the "memberships" table.
	MembershipsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "current", Type: field.TypeBool, Default: false},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "updated_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "organization_memberships", Type: field.TypeUUID},
		{Name: "user_memberships", Type: field.TypeUUID},
	}
	// MembershipsTable holds the schema information for the "memberships" table.
	MembershipsTable = &schema.Table{
		Name:       "memberships",
		Columns:    MembershipsColumns,
		PrimaryKey: []*schema.Column{MembershipsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "memberships_organizations_memberships",
				Columns:    []*schema.Column{MembershipsColumns[4]},
				RefColumns: []*schema.Column{OrganizationsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "memberships_users_memberships",
				Columns:    []*schema.Column{MembershipsColumns[5]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "membership_organization_memberships_user_memberships",
				Unique:  true,
				Columns: []*schema.Column{MembershipsColumns[4], MembershipsColumns[5]},
			},
		},
	}
	// OciRepositoriesColumns holds the columns for the "oci_repositories" table.
	OciRepositoriesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "repo", Type: field.TypeString},
		{Name: "secret_name", Type: field.TypeString},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "validation_status", Type: field.TypeEnum, Enums: []string{"OK", "Invalid"}, Default: "OK"},
		{Name: "validated_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "organization_oci_repositories", Type: field.TypeUUID},
	}
	// OciRepositoriesTable holds the schema information for the "oci_repositories" table.
	OciRepositoriesTable = &schema.Table{
		Name:       "oci_repositories",
		Columns:    OciRepositoriesColumns,
		PrimaryKey: []*schema.Column{OciRepositoriesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "oci_repositories_organizations_oci_repositories",
				Columns:    []*schema.Column{OciRepositoriesColumns[6]},
				RefColumns: []*schema.Column{OrganizationsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// OrganizationsColumns holds the columns for the "organizations" table.
	OrganizationsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString, Default: "default"},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
	}
	// OrganizationsTable holds the schema information for the "organizations" table.
	OrganizationsTable = &schema.Table{
		Name:       "organizations",
		Columns:    OrganizationsColumns,
		PrimaryKey: []*schema.Column{OrganizationsColumns[0]},
	}
	// RobotAccountsColumns holds the columns for the "robot_accounts" table.
	RobotAccountsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "revoked_at", Type: field.TypeTime, Nullable: true},
		{Name: "workflow_robotaccounts", Type: field.TypeUUID, Nullable: true},
	}
	// RobotAccountsTable holds the schema information for the "robot_accounts" table.
	RobotAccountsTable = &schema.Table{
		Name:       "robot_accounts",
		Columns:    RobotAccountsColumns,
		PrimaryKey: []*schema.Column{RobotAccountsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "robot_accounts_workflows_robotaccounts",
				Columns:    []*schema.Column{RobotAccountsColumns[4]},
				RefColumns: []*schema.Column{WorkflowsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "email", Type: field.TypeString, Unique: true},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
	}
	// WorkflowsColumns holds the columns for the "workflows" table.
	WorkflowsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "project", Type: field.TypeString, Nullable: true},
		{Name: "team", Type: field.TypeString, Nullable: true},
		{Name: "runs_count", Type: field.TypeInt, Default: 0},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "organization_id", Type: field.TypeUUID},
		{Name: "workflow_contract", Type: field.TypeUUID},
	}
	// WorkflowsTable holds the schema information for the "workflows" table.
	WorkflowsTable = &schema.Table{
		Name:       "workflows",
		Columns:    WorkflowsColumns,
		PrimaryKey: []*schema.Column{WorkflowsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflows_organizations_workflows",
				Columns:    []*schema.Column{WorkflowsColumns[7]},
				RefColumns: []*schema.Column{OrganizationsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "workflows_workflow_contracts_contract",
				Columns:    []*schema.Column{WorkflowsColumns[8]},
				RefColumns: []*schema.Column{WorkflowContractsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// WorkflowContractsColumns holds the columns for the "workflow_contracts" table.
	WorkflowContractsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "organization_workflow_contracts", Type: field.TypeUUID, Nullable: true},
	}
	// WorkflowContractsTable holds the schema information for the "workflow_contracts" table.
	WorkflowContractsTable = &schema.Table{
		Name:       "workflow_contracts",
		Columns:    WorkflowContractsColumns,
		PrimaryKey: []*schema.Column{WorkflowContractsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_contracts_organizations_workflow_contracts",
				Columns:    []*schema.Column{WorkflowContractsColumns[4]},
				RefColumns: []*schema.Column{OrganizationsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// WorkflowContractVersionsColumns holds the columns for the "workflow_contract_versions" table.
	WorkflowContractVersionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "body", Type: field.TypeBytes},
		{Name: "revision", Type: field.TypeInt, Default: 1},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "workflow_contract_versions", Type: field.TypeUUID, Nullable: true},
	}
	// WorkflowContractVersionsTable holds the schema information for the "workflow_contract_versions" table.
	WorkflowContractVersionsTable = &schema.Table{
		Name:       "workflow_contract_versions",
		Columns:    WorkflowContractVersionsColumns,
		PrimaryKey: []*schema.Column{WorkflowContractVersionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_contract_versions_workflow_contracts_versions",
				Columns:    []*schema.Column{WorkflowContractVersionsColumns[4]},
				RefColumns: []*schema.Column{WorkflowContractsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// WorkflowRunsColumns holds the columns for the "workflow_runs" table.
	WorkflowRunsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
		{Name: "finished_at", Type: field.TypeTime, Nullable: true},
		{Name: "state", Type: field.TypeEnum, Enums: []string{"initialized", "success", "error", "expired", "canceled"}, Default: "initialized"},
		{Name: "reason", Type: field.TypeString, Nullable: true, Size: 2147483647},
		{Name: "run_url", Type: field.TypeString, Nullable: true},
		{Name: "runner_type", Type: field.TypeString, Nullable: true},
		{Name: "attestation_ref", Type: field.TypeJSON, Nullable: true},
		{Name: "robot_account_workflowruns", Type: field.TypeUUID, Nullable: true},
		{Name: "workflow_workflowruns", Type: field.TypeUUID, Nullable: true},
		{Name: "workflow_run_contract_version", Type: field.TypeUUID, Nullable: true},
	}
	// WorkflowRunsTable holds the schema information for the "workflow_runs" table.
	WorkflowRunsTable = &schema.Table{
		Name:       "workflow_runs",
		Columns:    WorkflowRunsColumns,
		PrimaryKey: []*schema.Column{WorkflowRunsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "workflow_runs_robot_accounts_workflowruns",
				Columns:    []*schema.Column{WorkflowRunsColumns[8]},
				RefColumns: []*schema.Column{RobotAccountsColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "workflow_runs_workflows_workflowruns",
				Columns:    []*schema.Column{WorkflowRunsColumns[9]},
				RefColumns: []*schema.Column{WorkflowsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "workflow_runs_workflow_contract_versions_contract_version",
				Columns:    []*schema.Column{WorkflowRunsColumns[10]},
				RefColumns: []*schema.Column{WorkflowContractVersionsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "workflowrun_created_at_id",
				Unique:  false,
				Columns: []*schema.Column{WorkflowRunsColumns[1], WorkflowRunsColumns[0]},
			},
			{
				Name:    "workflowrun_created_at_state",
				Unique:  false,
				Columns: []*schema.Column{WorkflowRunsColumns[1], WorkflowRunsColumns[3]},
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		IntegrationsTable,
		IntegrationAttachmentsTable,
		MembershipsTable,
		OciRepositoriesTable,
		OrganizationsTable,
		RobotAccountsTable,
		UsersTable,
		WorkflowsTable,
		WorkflowContractsTable,
		WorkflowContractVersionsTable,
		WorkflowRunsTable,
	}
)

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