go generate ent schema

This commit is contained in:
2024-08-19 13:55:36 +02:00
parent c2369cca8a
commit 6943eb83f4
26 changed files with 7831 additions and 0 deletions

64
ent/migrate/migrate.go Normal file
View File

@ -0,0 +1,64 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"context"
"fmt"
"io"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql/schema"
)
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
)
// Schema is the API for creating, migrating and dropping a schema.
type Schema struct {
drv dialect.Driver
}
// NewSchema creates a new schema client.
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
// Create creates all schema resources.
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
return Create(ctx, s, Tables, opts...)
}
// Create creates all table resources using the given schema driver.
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
migrate, err := schema.NewMigrate(s.drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, tables...)
}
// 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)
// }
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
}

61
ent/migrate/schema.go Normal file
View File

@ -0,0 +1,61 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// AccountsColumns holds the columns for the "accounts" table.
AccountsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true, Default: "gen_random_uuid()"},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
{Name: "nickname", Type: field.TypeString},
{Name: "name", Type: field.TypeString},
{Name: "secret", Type: field.TypeBytes},
{Name: "aes", Type: field.TypeBytes, Size: 32},
{Name: "x509", Type: field.TypeBytes},
}
// AccountsTable holds the schema information for the "accounts" table.
AccountsTable = &schema.Table{
Name: "accounts",
Columns: AccountsColumns,
PrimaryKey: []*schema.Column{AccountsColumns[0]},
}
// EmailsColumns holds the columns for the "emails" table.
EmailsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true, Default: "gen_random_uuid()"},
{Name: "email", Type: field.TypeString},
{Name: "primary", Type: field.TypeBool, Default: false},
{Name: "verified", Type: field.TypeBool, Default: false},
{Name: "verification_code", Type: field.TypeString, Nullable: true},
{Name: "reset_code", Type: field.TypeString, Nullable: true},
{Name: "account_emails", Type: field.TypeUUID, Nullable: true},
}
// EmailsTable holds the schema information for the "emails" table.
EmailsTable = &schema.Table{
Name: "emails",
Columns: EmailsColumns,
PrimaryKey: []*schema.Column{EmailsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "emails_accounts_emails",
Columns: []*schema.Column{EmailsColumns[6]},
RefColumns: []*schema.Column{AccountsColumns[0]},
OnDelete: schema.SetNull,
},
},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
AccountsTable,
EmailsTable,
}
)
func init() {
EmailsTable.ForeignKeys[0].RefTable = AccountsTable
}