migrate

package
v0.0.0-...-1971f33 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: GPL-3.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 (
	// BalancesColumns holds the columns for the "balances" table.
	BalancesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "token_id", Type: field.TypeInt, Nullable: true, SchemaType: map[string]string{"postgres": "numeric"}},
		{Name: "balance", Type: field.TypeInt, SchemaType: map[string]string{"postgres": "numeric"}},
		{Name: "balance_account", Type: field.TypeString, Nullable: true},
		{Name: "balance_contract", Type: field.TypeString, Nullable: true},
	}
	// BalancesTable holds the schema information for the "balances" table.
	BalancesTable = &schema.Table{
		Name:       "balances",
		Columns:    BalancesColumns,
		PrimaryKey: []*schema.Column{BalancesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "balances_contracts_account",
				Columns:    []*schema.Column{BalancesColumns[3]},
				RefColumns: []*schema.Column{ContractsColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "balances_contracts_contract",
				Columns:    []*schema.Column{BalancesColumns[4]},
				RefColumns: []*schema.Column{ContractsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// BlocksColumns holds the columns for the "blocks" table.
	BlocksColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "block_hash", Type: field.TypeString, Unique: true},
		{Name: "parent_block_hash", Type: field.TypeString},
		{Name: "block_number", Type: field.TypeUint64, Unique: true},
		{Name: "state_root", Type: field.TypeString},
		{Name: "status", Type: field.TypeEnum, Enums: []string{"ACCEPTED_ON_L1", "ACCEPTED_ON_L2"}},
		{Name: "timestamp", Type: field.TypeTime},
	}
	// BlocksTable holds the schema information for the "blocks" table.
	BlocksTable = &schema.Table{
		Name:       "blocks",
		Columns:    BlocksColumns,
		PrimaryKey: []*schema.Column{BlocksColumns[0]},
	}
	// ContractsColumns holds the columns for the "contracts" table.
	ContractsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "type", Type: field.TypeEnum, Enums: []string{"UNKNOWN", "ERC20", "ERC721"}, Default: "UNKNOWN"},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
	}
	// ContractsTable holds the schema information for the "contracts" table.
	ContractsTable = &schema.Table{
		Name:       "contracts",
		Columns:    ContractsColumns,
		PrimaryKey: []*schema.Column{ContractsColumns[0]},
	}
	// EventsColumns holds the columns for the "events" table.
	EventsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "from", Type: field.TypeString},
		{Name: "keys", Type: field.TypeJSON},
		{Name: "data", Type: field.TypeJSON},
		{Name: "transaction_events", Type: field.TypeString, Nullable: true},
	}
	// EventsTable holds the schema information for the "events" table.
	EventsTable = &schema.Table{
		Name:       "events",
		Columns:    EventsColumns,
		PrimaryKey: []*schema.Column{EventsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "events_transactions_events",
				Columns:    []*schema.Column{EventsColumns[4]},
				RefColumns: []*schema.Column{TransactionsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// TransactionsColumns holds the columns for the "transactions" table.
	TransactionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "contract_address", Type: field.TypeString},
		{Name: "entry_point_selector", Type: field.TypeString, Nullable: true},
		{Name: "transaction_hash", Type: field.TypeString},
		{Name: "calldata", Type: field.TypeJSON},
		{Name: "signature", Type: field.TypeJSON, Nullable: true},
		{Name: "nonce", Type: field.TypeString, Nullable: true},
		{Name: "block_transactions", Type: field.TypeString, Nullable: true},
		{Name: "contract_transactions", Type: field.TypeString, Nullable: true},
	}
	// TransactionsTable holds the schema information for the "transactions" table.
	TransactionsTable = &schema.Table{
		Name:       "transactions",
		Columns:    TransactionsColumns,
		PrimaryKey: []*schema.Column{TransactionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "transactions_blocks_transactions",
				Columns:    []*schema.Column{TransactionsColumns[7]},
				RefColumns: []*schema.Column{BlocksColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "transactions_contracts_transactions",
				Columns:    []*schema.Column{TransactionsColumns[8]},
				RefColumns: []*schema.Column{ContractsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// TransactionReceiptsColumns holds the columns for the "transaction_receipts" table.
	TransactionReceiptsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeString, Unique: true},
		{Name: "transaction_hash", Type: field.TypeString},
		{Name: "status", Type: field.TypeEnum, Enums: []string{"UNKNOWN", "RECEIVED", "PENDING", "ACCEPTED_ON_L2", "ACCEPTED_ON_L1", "REJECTED"}},
		{Name: "status_data", Type: field.TypeString},
		{Name: "messages_sent", Type: field.TypeJSON},
		{Name: "l1_origin_message", Type: field.TypeJSON},
		{Name: "block_transaction_receipts", Type: field.TypeString, Nullable: true},
		{Name: "transaction_receipt", Type: field.TypeString, Unique: true},
	}
	// TransactionReceiptsTable holds the schema information for the "transaction_receipts" table.
	TransactionReceiptsTable = &schema.Table{
		Name:       "transaction_receipts",
		Columns:    TransactionReceiptsColumns,
		PrimaryKey: []*schema.Column{TransactionReceiptsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "transaction_receipts_blocks_transaction_receipts",
				Columns:    []*schema.Column{TransactionReceiptsColumns[6]},
				RefColumns: []*schema.Column{BlocksColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:     "transaction_receipts_transactions_receipt",
				Columns:    []*schema.Column{TransactionReceiptsColumns[7]},
				RefColumns: []*schema.Column{TransactionsColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		BalancesTable,
		BlocksTable,
		ContractsTable,
		EventsTable,
		TransactionsTable,
		TransactionReceiptsTable,
	}
)

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