migrate

package
v0.0.0-...-b7d53eb Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 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
	// 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 (
	// APIAuditsColumns holds the columns for the "api_audits" table.
	APIAuditsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Size: 255},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "plane", Type: field.TypeString},
		{Name: "hashed_grant_token", Type: field.TypeString, Nullable: true},
		{Name: "domain", Type: field.TypeString, Nullable: true},
		{Name: "http_path", Type: field.TypeString, Nullable: true},
		{Name: "http_method", Type: field.TypeString, Nullable: true},
		{Name: "sent_http_status", Type: field.TypeInt, Nullable: true},
	}
	// APIAuditsTable holds the schema information for the "api_audits" table.
	APIAuditsTable = &schema.Table{
		Name:        "api_audits",
		Columns:     APIAuditsColumns,
		PrimaryKey:  []*schema.Column{APIAuditsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
		Indexes: []*schema.Index{
			{
				Name:    "apiaudit_id",
				Unique:  true,
				Columns: []*schema.Column{APIAuditsColumns[0]},
			},
			{
				Name:    "apiaudit_created_at",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[1]},
			},
			{
				Name:    "apiaudit_updated_at",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[2]},
			},
			{
				Name:    "apiaudit_deleted_at",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[3]},
			},
			{
				Name:    "apiaudit_plane",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[4]},
			},
			{
				Name:    "apiaudit_hashed_grant_token",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[5]},
			},
			{
				Name:    "apiaudit_domain",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[6]},
			},
			{
				Name:    "apiaudit_http_path",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[7]},
			},
			{
				Name:    "apiaudit_http_method",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[8]},
			},
			{
				Name:    "apiaudit_sent_http_status",
				Unique:  false,
				Columns: []*schema.Column{APIAuditsColumns[9]},
			},
		},
	}
	// FactsColumns holds the columns for the "facts" table.
	FactsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Size: 255},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "hashed_value", Type: field.TypeString},
		{Name: "encrypted_value", Type: field.TypeString},
		{Name: "domain", Type: field.TypeString},
		{Name: "fact_type_facts", Type: field.TypeString, Nullable: true, Size: 255},
		{Name: "scope_facts", Type: field.TypeString, Nullable: true, Size: 255},
	}
	// FactsTable holds the schema information for the "facts" table.
	FactsTable = &schema.Table{
		Name:       "facts",
		Columns:    FactsColumns,
		PrimaryKey: []*schema.Column{FactsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "facts_fact_types_facts",
				Columns:    []*schema.Column{FactsColumns[7]},
				RefColumns: []*schema.Column{FactTypesColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "facts_scopes_facts",
				Columns:    []*schema.Column{FactsColumns[8]},
				RefColumns: []*schema.Column{ScopesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
		Indexes: []*schema.Index{
			{
				Name:    "fact_id",
				Unique:  true,
				Columns: []*schema.Column{FactsColumns[0]},
			},
			{
				Name:    "fact_created_at",
				Unique:  false,
				Columns: []*schema.Column{FactsColumns[1]},
			},
			{
				Name:    "fact_updated_at",
				Unique:  false,
				Columns: []*schema.Column{FactsColumns[2]},
			},
			{
				Name:    "fact_deleted_at",
				Unique:  false,
				Columns: []*schema.Column{FactsColumns[3]},
			},
			{
				Name:    "fact_hashed_value",
				Unique:  false,
				Columns: []*schema.Column{FactsColumns[4]},
			},
			{
				Name:    "fact_domain",
				Unique:  false,
				Columns: []*schema.Column{FactsColumns[6]},
			},
		},
	}
	// FactTypesColumns holds the columns for the "fact_types" table.
	FactTypesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Size: 255},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "slug", Type: field.TypeString},
		{Name: "built_in", Type: field.TypeBool, Default: false},
		{Name: "validation", Type: field.TypeString, Nullable: true},
	}
	// FactTypesTable holds the schema information for the "fact_types" table.
	FactTypesTable = &schema.Table{
		Name:        "fact_types",
		Columns:     FactTypesColumns,
		PrimaryKey:  []*schema.Column{FactTypesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
		Indexes: []*schema.Index{
			{
				Name:    "facttype_id",
				Unique:  true,
				Columns: []*schema.Column{FactTypesColumns[0]},
			},
			{
				Name:    "facttype_created_at",
				Unique:  false,
				Columns: []*schema.Column{FactTypesColumns[1]},
			},
			{
				Name:    "facttype_updated_at",
				Unique:  false,
				Columns: []*schema.Column{FactTypesColumns[2]},
			},
			{
				Name:    "facttype_deleted_at",
				Unique:  false,
				Columns: []*schema.Column{FactTypesColumns[3]},
			},
			{
				Name:    "facttype_slug",
				Unique:  true,
				Columns: []*schema.Column{FactTypesColumns[4]},
			},
		},
	}
	// GrantsColumns holds the columns for the "grants" table.
	GrantsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Size: 255},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "hashed_grant_token", Type: field.TypeString},
		{Name: "domain", Type: field.TypeString},
		{Name: "version", Type: field.TypeString},
		{Name: "allowed_http_methods", Type: field.TypeString},
		{Name: "paths", Type: field.TypeJSON},
	}
	// GrantsTable holds the schema information for the "grants" table.
	GrantsTable = &schema.Table{
		Name:        "grants",
		Columns:     GrantsColumns,
		PrimaryKey:  []*schema.Column{GrantsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
		Indexes: []*schema.Index{
			{
				Name:    "grant_id",
				Unique:  true,
				Columns: []*schema.Column{GrantsColumns[0]},
			},
			{
				Name:    "grant_created_at",
				Unique:  false,
				Columns: []*schema.Column{GrantsColumns[1]},
			},
			{
				Name:    "grant_updated_at",
				Unique:  false,
				Columns: []*schema.Column{GrantsColumns[2]},
			},
			{
				Name:    "grant_deleted_at",
				Unique:  false,
				Columns: []*schema.Column{GrantsColumns[3]},
			},
			{
				Name:    "grant_hashed_grant_token",
				Unique:  false,
				Columns: []*schema.Column{GrantsColumns[4]},
			},
			{
				Name:    "grant_domain",
				Unique:  false,
				Columns: []*schema.Column{GrantsColumns[5]},
			},
		},
	}
	// ScopesColumns holds the columns for the "scopes" table.
	ScopesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Size: 255},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "deleted_at", Type: field.TypeTime, Nullable: true},
		{Name: "custom_id", Type: field.TypeString},
		{Name: "nonce", Type: field.TypeString},
		{Name: "domain", Type: field.TypeString},
	}
	// ScopesTable holds the schema information for the "scopes" table.
	ScopesTable = &schema.Table{
		Name:        "scopes",
		Columns:     ScopesColumns,
		PrimaryKey:  []*schema.Column{ScopesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
		Indexes: []*schema.Index{
			{
				Name:    "scope_id",
				Unique:  true,
				Columns: []*schema.Column{ScopesColumns[0]},
			},
			{
				Name:    "scope_created_at",
				Unique:  false,
				Columns: []*schema.Column{ScopesColumns[1]},
			},
			{
				Name:    "scope_updated_at",
				Unique:  false,
				Columns: []*schema.Column{ScopesColumns[2]},
			},
			{
				Name:    "scope_deleted_at",
				Unique:  false,
				Columns: []*schema.Column{ScopesColumns[3]},
			},
			{
				Name:    "scope_custom_id",
				Unique:  true,
				Columns: []*schema.Column{ScopesColumns[4]},
			},
			{
				Name:    "scope_domain",
				Unique:  false,
				Columns: []*schema.Column{ScopesColumns[6]},
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		APIAuditsTable,
		FactsTable,
		FactTypesTable,
		GrantsTable,
		ScopesTable,
	}
)

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