migrate

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 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 (
	// AttestationsColumns holds the columns for the "attestations" table.
	AttestationsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "type", Type: field.TypeString},
		{Name: "attestation_collection_attestations", Type: field.TypeUUID},
	}
	// AttestationsTable holds the schema information for the "attestations" table.
	AttestationsTable = &schema.Table{
		Name:       "attestations",
		Columns:    AttestationsColumns,
		PrimaryKey: []*schema.Column{AttestationsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "attestations_attestation_collections_attestations",
				Columns:    []*schema.Column{AttestationsColumns[2]},
				RefColumns: []*schema.Column{AttestationCollectionsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "attestation_type",
				Unique:  false,
				Columns: []*schema.Column{AttestationsColumns[1]},
			},
		},
	}
	// AttestationCollectionsColumns holds the columns for the "attestation_collections" table.
	AttestationCollectionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "statement_attestation_collections", Type: field.TypeUUID, Unique: true},
	}
	// AttestationCollectionsTable holds the schema information for the "attestation_collections" table.
	AttestationCollectionsTable = &schema.Table{
		Name:       "attestation_collections",
		Columns:    AttestationCollectionsColumns,
		PrimaryKey: []*schema.Column{AttestationCollectionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "attestation_collections_statements_attestation_collections",
				Columns:    []*schema.Column{AttestationCollectionsColumns[2]},
				RefColumns: []*schema.Column{StatementsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "attestationcollection_name",
				Unique:  false,
				Columns: []*schema.Column{AttestationCollectionsColumns[1]},
			},
		},
	}
	// AttestationPoliciesColumns holds the columns for the "attestation_policies" table.
	AttestationPoliciesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "statement_policy", Type: field.TypeUUID, Unique: true, Nullable: true},
	}
	// AttestationPoliciesTable holds the schema information for the "attestation_policies" table.
	AttestationPoliciesTable = &schema.Table{
		Name:       "attestation_policies",
		Columns:    AttestationPoliciesColumns,
		PrimaryKey: []*schema.Column{AttestationPoliciesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "attestation_policies_statements_policy",
				Columns:    []*schema.Column{AttestationPoliciesColumns[2]},
				RefColumns: []*schema.Column{StatementsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "attestationpolicy_name",
				Unique:  false,
				Columns: []*schema.Column{AttestationPoliciesColumns[1]},
			},
		},
	}
	// DssesColumns holds the columns for the "dsses" table.
	DssesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "gitoid_sha256", Type: field.TypeString, Unique: true},
		{Name: "payload_type", Type: field.TypeString},
		{Name: "dsse_statement", Type: field.TypeUUID, Nullable: true},
	}
	// DssesTable holds the schema information for the "dsses" table.
	DssesTable = &schema.Table{
		Name:       "dsses",
		Columns:    DssesColumns,
		PrimaryKey: []*schema.Column{DssesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "dsses_statements_statement",
				Columns:    []*schema.Column{DssesColumns[3]},
				RefColumns: []*schema.Column{StatementsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// PayloadDigestsColumns holds the columns for the "payload_digests" table.
	PayloadDigestsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "algorithm", Type: field.TypeString},
		{Name: "value", Type: field.TypeString},
		{Name: "dsse_payload_digests", Type: field.TypeUUID, Nullable: true},
	}
	// PayloadDigestsTable holds the schema information for the "payload_digests" table.
	PayloadDigestsTable = &schema.Table{
		Name:       "payload_digests",
		Columns:    PayloadDigestsColumns,
		PrimaryKey: []*schema.Column{PayloadDigestsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "payload_digests_dsses_payload_digests",
				Columns:    []*schema.Column{PayloadDigestsColumns[3]},
				RefColumns: []*schema.Column{DssesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "payloaddigest_value",
				Unique:  false,
				Columns: []*schema.Column{PayloadDigestsColumns[2]},
			},
		},
	}
	// SignaturesColumns holds the columns for the "signatures" table.
	SignaturesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "key_id", Type: field.TypeString},
		{Name: "signature", Type: field.TypeString, SchemaType: map[string]string{"mysql": "text"}},
		{Name: "dsse_signatures", Type: field.TypeUUID, Nullable: true},
	}
	// SignaturesTable holds the schema information for the "signatures" table.
	SignaturesTable = &schema.Table{
		Name:       "signatures",
		Columns:    SignaturesColumns,
		PrimaryKey: []*schema.Column{SignaturesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "signatures_dsses_signatures",
				Columns:    []*schema.Column{SignaturesColumns[3]},
				RefColumns: []*schema.Column{DssesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "signature_key_id",
				Unique:  false,
				Columns: []*schema.Column{SignaturesColumns[1]},
			},
		},
	}
	// StatementsColumns holds the columns for the "statements" table.
	StatementsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "predicate", Type: field.TypeString},
	}
	// StatementsTable holds the schema information for the "statements" table.
	StatementsTable = &schema.Table{
		Name:       "statements",
		Columns:    StatementsColumns,
		PrimaryKey: []*schema.Column{StatementsColumns[0]},
		Indexes: []*schema.Index{
			{
				Name:    "statement_predicate",
				Unique:  false,
				Columns: []*schema.Column{StatementsColumns[1]},
			},
		},
	}
	// SubjectsColumns holds the columns for the "subjects" table.
	SubjectsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString},
		{Name: "statement_subjects", Type: field.TypeUUID, Nullable: true},
	}
	// SubjectsTable holds the schema information for the "subjects" table.
	SubjectsTable = &schema.Table{
		Name:       "subjects",
		Columns:    SubjectsColumns,
		PrimaryKey: []*schema.Column{SubjectsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "subjects_statements_subjects",
				Columns:    []*schema.Column{SubjectsColumns[2]},
				RefColumns: []*schema.Column{StatementsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "subject_name",
				Unique:  false,
				Columns: []*schema.Column{SubjectsColumns[1]},
			},
		},
	}
	// SubjectDigestsColumns holds the columns for the "subject_digests" table.
	SubjectDigestsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "algorithm", Type: field.TypeString},
		{Name: "value", Type: field.TypeString},
		{Name: "subject_subject_digests", Type: field.TypeUUID, Nullable: true},
	}
	// SubjectDigestsTable holds the schema information for the "subject_digests" table.
	SubjectDigestsTable = &schema.Table{
		Name:       "subject_digests",
		Columns:    SubjectDigestsColumns,
		PrimaryKey: []*schema.Column{SubjectDigestsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "subject_digests_subjects_subject_digests",
				Columns:    []*schema.Column{SubjectDigestsColumns[3]},
				RefColumns: []*schema.Column{SubjectsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "subjectdigest_value",
				Unique:  false,
				Columns: []*schema.Column{SubjectDigestsColumns[2]},
			},
		},
	}
	// TimestampsColumns holds the columns for the "timestamps" table.
	TimestampsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "type", Type: field.TypeString},
		{Name: "timestamp", Type: field.TypeTime},
		{Name: "signature_timestamps", Type: field.TypeUUID, Nullable: true},
	}
	// TimestampsTable holds the schema information for the "timestamps" table.
	TimestampsTable = &schema.Table{
		Name:       "timestamps",
		Columns:    TimestampsColumns,
		PrimaryKey: []*schema.Column{TimestampsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "timestamps_signatures_timestamps",
				Columns:    []*schema.Column{TimestampsColumns[3]},
				RefColumns: []*schema.Column{SignaturesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		AttestationsTable,
		AttestationCollectionsTable,
		AttestationPoliciesTable,
		DssesTable,
		PayloadDigestsTable,
		SignaturesTable,
		StatementsTable,
		SubjectsTable,
		SubjectDigestsTable,
		TimestampsTable,
	}
)

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