Documentation ¶
Index ¶
- Variables
- func Create(ctx context.Context, s *Schema, tables []*schema.Table, ...) error
- func Diff(ctx context.Context, url string, opts ...schema.MigrateOption) error
- func NamedDiff(ctx context.Context, url, name string, opts ...schema.MigrateOption) error
- type Schema
- func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error
- func (s *Schema) Diff(ctx context.Context, opts ...schema.MigrateOption) error
- func (s *Schema) NamedDiff(ctx context.Context, name string, opts ...schema.MigrateOption) error
- func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error
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 ( // CasBackendsColumns holds the columns for the "cas_backends" table. CasBackendsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID, Unique: true}, {Name: "location", Type: field.TypeString}, {Name: "provider", Type: field.TypeEnum, Enums: []string{"OCI", "INLINE"}}, {Name: "description", Type: field.TypeString, Nullable: true}, {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: "default", Type: field.TypeBool, Default: false}, {Name: "deleted_at", Type: field.TypeTime, Nullable: true}, {Name: "fallback", Type: field.TypeBool, Default: false}, {Name: "organization_cas_backends", Type: field.TypeUUID}, } // CasBackendsTable holds the schema information for the "cas_backends" table. CasBackendsTable = &schema.Table{ Name: "cas_backends", Columns: CasBackendsColumns, PrimaryKey: []*schema.Column{CasBackendsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "cas_backends_organizations_cas_backends", Columns: []*schema.Column{CasBackendsColumns[11]}, RefColumns: []*schema.Column{OrganizationsColumns[0]}, OnDelete: schema.Cascade, }, }, } // CasMappingsColumns holds the columns for the "cas_mappings" table. CasMappingsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID, Unique: true}, {Name: "digest", Type: field.TypeString}, {Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"}, {Name: "cas_mapping_cas_backend", Type: field.TypeUUID}, {Name: "cas_mapping_workflow_run", Type: field.TypeUUID, Nullable: true}, {Name: "cas_mapping_organization", Type: field.TypeUUID}, } // CasMappingsTable holds the schema information for the "cas_mappings" table. CasMappingsTable = &schema.Table{ Name: "cas_mappings", Columns: CasMappingsColumns, PrimaryKey: []*schema.Column{CasMappingsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "cas_mappings_cas_backends_cas_backend", Columns: []*schema.Column{CasMappingsColumns[3]}, RefColumns: []*schema.Column{CasBackendsColumns[0]}, OnDelete: schema.NoAction, }, { Symbol: "cas_mappings_workflow_runs_workflow_run", Columns: []*schema.Column{CasMappingsColumns[4]}, RefColumns: []*schema.Column{WorkflowRunsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "cas_mappings_organizations_organization", Columns: []*schema.Column{CasMappingsColumns[5]}, RefColumns: []*schema.Column{OrganizationsColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { Name: "casmapping_digest", Unique: false, Columns: []*schema.Column{CasMappingsColumns[1]}, }, }, } // IntegrationsColumns holds the columns for the "integrations" table. IntegrationsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID, Unique: true}, {Name: "kind", Type: field.TypeString}, {Name: "description", Type: field.TypeString, Nullable: true}, {Name: "secret_name", Type: field.TypeString}, {Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"}, {Name: "configuration", Type: field.TypeBytes, Nullable: true}, {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[7]}, 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: "configuration", Type: field.TypeBytes, Nullable: true}, {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]}, }, }, } // 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: "public", Type: field.TypeBool, Default: false}, {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[8]}, RefColumns: []*schema.Column{OrganizationsColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "workflows_workflow_contracts_contract", Columns: []*schema.Column{WorkflowsColumns[9]}, 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", Type: field.TypeJSON, Nullable: true}, {Name: "attestation_digest", Type: field.TypeString, 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[9]}, RefColumns: []*schema.Column{RobotAccountsColumns[0]}, OnDelete: schema.SetNull, }, { Symbol: "workflow_runs_workflows_workflowruns", Columns: []*schema.Column{WorkflowRunsColumns[10]}, RefColumns: []*schema.Column{WorkflowsColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "workflow_runs_workflow_contract_versions_contract_version", Columns: []*schema.Column{WorkflowRunsColumns[11]}, 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]}, }, }, } // WorkflowRunCasBackendsColumns holds the columns for the "workflow_run_cas_backends" table. WorkflowRunCasBackendsColumns = []*schema.Column{ {Name: "workflow_run_id", Type: field.TypeUUID}, {Name: "cas_backend_id", Type: field.TypeUUID}, } // WorkflowRunCasBackendsTable holds the schema information for the "workflow_run_cas_backends" table. WorkflowRunCasBackendsTable = &schema.Table{ Name: "workflow_run_cas_backends", Columns: WorkflowRunCasBackendsColumns, PrimaryKey: []*schema.Column{WorkflowRunCasBackendsColumns[0], WorkflowRunCasBackendsColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { Symbol: "workflow_run_cas_backends_workflow_run_id", Columns: []*schema.Column{WorkflowRunCasBackendsColumns[0]}, RefColumns: []*schema.Column{WorkflowRunsColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "workflow_run_cas_backends_cas_backend_id", Columns: []*schema.Column{WorkflowRunCasBackendsColumns[1]}, RefColumns: []*schema.Column{CasBackendsColumns[0]}, OnDelete: schema.Cascade, }, }, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ CasBackendsTable, CasMappingsTable, IntegrationsTable, IntegrationAttachmentsTable, MembershipsTable, OrganizationsTable, RobotAccountsTable, UsersTable, WorkflowsTable, WorkflowContractsTable, WorkflowContractVersionsTable, WorkflowRunsTable, WorkflowRunCasBackendsTable, } )
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.
func Diff ¶ added in v0.13.0
Diff compares the state read from a database connection or migration directory with the state defined by the Ent schema. Changes will be written to new migration files.
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is the API for creating, migrating and dropping a schema.
func (*Schema) Diff ¶ added in v0.13.0
Diff creates a migration file containing the statements to resolve the diff between the Ent schema and the connected database.
func (*Schema) NamedDiff ¶ added in v0.13.0
NamedDiff creates a named migration file containing the statements to resolve the diff between the Ent schema and the connected database.
Click to show internal directories.
Click to hide internal directories.