migrate

package
v0.0.0-...-4d10510 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: AGPL-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
	// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
	WithForeignKeys = schema.WithForeignKeys
)
View Source
var (
	// AgeKeysColumns holds the columns for the "age_keys" table.
	AgeKeysColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "key", Type: field.TypeBytes},
		{Name: "created", Type: field.TypeTime},
		{Name: "updated", Type: field.TypeTime},
		{Name: "owner", Type: field.TypeUUID, Unique: true},
	}
	// AgeKeysTable holds the schema information for the "age_keys" table.
	AgeKeysTable = &schema.Table{
		Name:       "age_keys",
		Columns:    AgeKeysColumns,
		PrimaryKey: []*schema.Column{AgeKeysColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "age_keys_users_agekey",
				Columns:    []*schema.Column{AgeKeysColumns[4]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// HibPsColumns holds the columns for the "hib_ps" table.
	HibPsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "title", Type: field.TypeString, Unique: true},
		{Name: "domain", Type: field.TypeString},
		{Name: "breach_date", Type: field.TypeString},
		{Name: "added_date", Type: field.TypeTime},
		{Name: "modified_date", Type: field.TypeTime},
		{Name: "pwn_count", Type: field.TypeInt},
		{Name: "description", Type: field.TypeString, Nullable: true},
		{Name: "dataclasses", Type: field.TypeJSON},
		{Name: "is_verified", Type: field.TypeBool, Default: false},
		{Name: "is_fabricated", Type: field.TypeBool, Default: false},
		{Name: "is_sensitive", Type: field.TypeBool, Default: false},
		{Name: "is_retired", Type: field.TypeBool, Default: false},
		{Name: "is_spam_list", Type: field.TypeBool, Default: false},
		{Name: "is_malware", Type: field.TypeBool, Default: false},
		{Name: "logo_path", Type: field.TypeString, Nullable: true},
		{Name: "tracked_breaches_hibp", Type: field.TypeUUID, Nullable: true},
	}
	// HibPsTable holds the schema information for the "hib_ps" table.
	HibPsTable = &schema.Table{
		Name:       "hib_ps",
		Columns:    HibPsColumns,
		PrimaryKey: []*schema.Column{HibPsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "hib_ps_tracked_breaches_hibp",
				Columns:    []*schema.Column{HibPsColumns[17]},
				RefColumns: []*schema.Column{TrackedBreachesColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// LocalBreachesColumns holds the columns for the "local_breaches" table.
	LocalBreachesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "name", Type: field.TypeString, Unique: true},
		{Name: "date", Type: field.TypeTime},
		{Name: "description", Type: field.TypeString, Nullable: true},
		{Name: "is_verified", Type: field.TypeBool},
		{Name: "contains_passwords", Type: field.TypeBool},
		{Name: "contains_hashes", Type: field.TypeBool},
		{Name: "contains_emails", Type: field.TypeBool},
		{Name: "contains_usernames", Type: field.TypeBool},
		{Name: "hash_type", Type: field.TypeString, Nullable: true},
		{Name: "hash_salted", Type: field.TypeBool, Nullable: true},
		{Name: "hash_peppered", Type: field.TypeBool, Nullable: true},
		{Name: "data", Type: field.TypeJSON, Nullable: true},
		{Name: "created_at", Type: field.TypeTime},
	}
	// LocalBreachesTable holds the schema information for the "local_breaches" table.
	LocalBreachesTable = &schema.Table{
		Name:       "local_breaches",
		Columns:    LocalBreachesColumns,
		PrimaryKey: []*schema.Column{LocalBreachesColumns[0]},
	}
	// SearchQueriesColumns holds the columns for the "search_queries" table.
	SearchQueriesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "query", Type: field.TypeString},
		{Name: "created", Type: field.TypeTime},
		{Name: "owner", Type: field.TypeUUID},
	}
	// SearchQueriesTable holds the schema information for the "search_queries" table.
	SearchQueriesTable = &schema.Table{
		Name:       "search_queries",
		Columns:    SearchQueriesColumns,
		PrimaryKey: []*schema.Column{SearchQueriesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "search_queries_users_search_queries",
				Columns:    []*schema.Column{SearchQueriesColumns[3]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// SettingsColumns holds the columns for the "settings" table.
	SettingsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "hibp_api_key", Type: field.TypeString, Unique: true, Nullable: true},
		{Name: "dehashed_api_key", Type: field.TypeString, Unique: true, Nullable: true},
		{Name: "searches", Type: field.TypeUint64, Default: 0},
	}
	// SettingsTable holds the schema information for the "settings" table.
	SettingsTable = &schema.Table{
		Name:       "settings",
		Columns:    SettingsColumns,
		PrimaryKey: []*schema.Column{SettingsColumns[0]},
	}
	// SetupsColumns holds the columns for the "setups" table.
	SetupsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "set_up_at", Type: field.TypeTime},
	}
	// SetupsTable holds the schema information for the "setups" table.
	SetupsTable = &schema.Table{
		Name:       "setups",
		Columns:    SetupsColumns,
		PrimaryKey: []*schema.Column{SetupsColumns[0]},
	}
	// TrackedBreachesColumns holds the columns for the "tracked_breaches" table.
	TrackedBreachesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "breach", Type: field.TypeUUID},
		{Name: "online", Type: field.TypeBool, Default: true},
		{Name: "owner", Type: field.TypeUUID},
	}
	// TrackedBreachesTable holds the schema information for the "tracked_breaches" table.
	TrackedBreachesTable = &schema.Table{
		Name:       "tracked_breaches",
		Columns:    TrackedBreachesColumns,
		PrimaryKey: []*schema.Column{TrackedBreachesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "tracked_breaches_users_tracked_breaches",
				Columns:    []*schema.Column{TrackedBreachesColumns[3]},
				RefColumns: []*schema.Column{UsersColumns[0]},
				OnDelete:   schema.NoAction,
			},
		},
	}
	// UsersColumns holds the columns for the "users" table.
	UsersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID, Unique: true},
		{Name: "username", Type: field.TypeString, Unique: true},
		{Name: "email", Type: field.TypeString, Unique: true},
		{Name: "password", Type: field.TypeBytes},
		{Name: "is_admin", Type: field.TypeBool, Default: false},
		{Name: "is_active", Type: field.TypeBool, Default: true},
		{Name: "created_at", Type: field.TypeTime},
		{Name: "updated_at", Type: field.TypeTime},
		{Name: "last_login", Type: field.TypeTime},
	}
	// UsersTable holds the schema information for the "users" table.
	UsersTable = &schema.Table{
		Name:       "users",
		Columns:    UsersColumns,
		PrimaryKey: []*schema.Column{UsersColumns[0]},
	}
	// TrackedBreachesLocalbreachColumns holds the columns for the "tracked_breaches_localbreach" table.
	TrackedBreachesLocalbreachColumns = []*schema.Column{
		{Name: "tracked_breaches_id", Type: field.TypeUUID},
		{Name: "local_breach_id", Type: field.TypeUUID},
	}
	// TrackedBreachesLocalbreachTable holds the schema information for the "tracked_breaches_localbreach" table.
	TrackedBreachesLocalbreachTable = &schema.Table{
		Name:       "tracked_breaches_localbreach",
		Columns:    TrackedBreachesLocalbreachColumns,
		PrimaryKey: []*schema.Column{TrackedBreachesLocalbreachColumns[0], TrackedBreachesLocalbreachColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:     "tracked_breaches_localbreach_tracked_breaches_id",
				Columns:    []*schema.Column{TrackedBreachesLocalbreachColumns[0]},
				RefColumns: []*schema.Column{TrackedBreachesColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:     "tracked_breaches_localbreach_local_breach_id",
				Columns:    []*schema.Column{TrackedBreachesLocalbreachColumns[1]},
				RefColumns: []*schema.Column{LocalBreachesColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		AgeKeysTable,
		HibPsTable,
		LocalBreachesTable,
		SearchQueriesTable,
		SettingsTable,
		SetupsTable,
		TrackedBreachesTable,
		UsersTable,
		TrackedBreachesLocalbreachTable,
	}
)

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