ent seteup
This commit is contained in:
64
db/ent/migrate/migrate.go
Normal file
64
db/ent/migrate/migrate.go
Normal 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...)
|
||||
}
|
203
db/ent/migrate/schema.go
Normal file
203
db/ent/migrate/schema.go
Normal file
@@ -0,0 +1,203 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// AccessControlsColumns holds the columns for the "access_controls" table.
|
||||
AccessControlsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "ptype", Type: field.TypeString, Default: ""},
|
||||
{Name: "v0", Type: field.TypeString, Default: ""},
|
||||
{Name: "v1", Type: field.TypeString, Default: ""},
|
||||
{Name: "v2", Type: field.TypeString, Default: ""},
|
||||
{Name: "v3", Type: field.TypeString, Default: ""},
|
||||
{Name: "v4", Type: field.TypeString, Default: ""},
|
||||
{Name: "v5", Type: field.TypeString, Default: ""},
|
||||
}
|
||||
// AccessControlsTable holds the schema information for the "access_controls" table.
|
||||
AccessControlsTable = &schema.Table{
|
||||
Name: "access_controls",
|
||||
Columns: AccessControlsColumns,
|
||||
PrimaryKey: []*schema.Column{AccessControlsColumns[0]},
|
||||
}
|
||||
// AuditsColumns holds the columns for the "audits" table.
|
||||
AuditsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "ent_name", Type: field.TypeString, Size: 50},
|
||||
{Name: "ent_id", Type: field.TypeInt64},
|
||||
{Name: "operation", Type: field.TypeEnum, Enums: []string{"Create", "Update", "UpdateOne", "Delete", "DeleteOne"}},
|
||||
{Name: "description", Type: field.TypeString, Size: 1000},
|
||||
{Name: "ip", Type: field.TypeString, Nullable: true, Size: 40},
|
||||
{Name: "user_name", Type: field.TypeString, Nullable: true, Size: 150},
|
||||
{Name: "user_id", Type: field.TypeInt64, Nullable: true},
|
||||
}
|
||||
// AuditsTable holds the schema information for the "audits" table.
|
||||
AuditsTable = &schema.Table{
|
||||
Name: "audits",
|
||||
Columns: AuditsColumns,
|
||||
PrimaryKey: []*schema.Column{AuditsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "audits_users_audit_logs",
|
||||
Columns: []*schema.Column{AuditsColumns[8]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "audit_ent_name_ent_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{AuditsColumns[2], AuditsColumns[3]},
|
||||
},
|
||||
{
|
||||
Name: "audit_operation",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{AuditsColumns[4]},
|
||||
},
|
||||
{
|
||||
Name: "audit_ip",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{AuditsColumns[6]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// RolesColumns holds the columns for the "roles" table.
|
||||
RolesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
}
|
||||
// RolesTable holds the schema information for the "roles" table.
|
||||
RolesTable = &schema.Table{
|
||||
Name: "roles",
|
||||
Columns: RolesColumns,
|
||||
PrimaryKey: []*schema.Column{RolesColumns[0]},
|
||||
}
|
||||
// TodosColumns holds the columns for the "todos" table.
|
||||
TodosColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
}
|
||||
// TodosTable holds the schema information for the "todos" table.
|
||||
TodosTable = &schema.Table{
|
||||
Name: "todos",
|
||||
Columns: TodosColumns,
|
||||
PrimaryKey: []*schema.Column{TodosColumns[0]},
|
||||
}
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "email", Type: field.TypeString, Unique: true},
|
||||
{Name: "email_verified", Type: field.TypeBool, Default: false},
|
||||
{Name: "phone", Type: field.TypeString, Size: 20},
|
||||
{Name: "phone_verified", Type: field.TypeBool, Default: false},
|
||||
{Name: "pwd_salt", Type: field.TypeString},
|
||||
{Name: "pwd_hash", Type: field.TypeString},
|
||||
{Name: "login_failed_count", Type: field.TypeUint8, Nullable: true, Default: 0},
|
||||
{Name: "login_attempt_on", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "login_locked_until", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "first_name", Type: field.TypeString, Size: 30},
|
||||
{Name: "middle_name", Type: field.TypeString, Size: 30},
|
||||
{Name: "last_name", Type: field.TypeString, Size: 30},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"Pending", "Active", "InActive"}, Default: "Pending"},
|
||||
}
|
||||
// UsersTable holds the schema information for the "users" table.
|
||||
UsersTable = &schema.Table{
|
||||
Name: "users",
|
||||
Columns: UsersColumns,
|
||||
PrimaryKey: []*schema.Column{UsersColumns[0]},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "user_created_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[1]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
Desc: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user_updated_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[2]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
Desc: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user_phone",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[5]},
|
||||
},
|
||||
{
|
||||
Name: "user_status",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[15]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// UserSessionsColumns holds the columns for the "user_sessions" table.
|
||||
UserSessionsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||
{Name: "issued_at", Type: field.TypeTime},
|
||||
{Name: "expires_at", Type: field.TypeTime},
|
||||
{Name: "invalidated", Type: field.TypeBool, Nullable: true, Default: false},
|
||||
{Name: "user_agent", Type: field.TypeString, Size: 50},
|
||||
{Name: "ip", Type: field.TypeString, Size: 40},
|
||||
{Name: "user_id", Type: field.TypeInt64},
|
||||
}
|
||||
// UserSessionsTable holds the schema information for the "user_sessions" table.
|
||||
UserSessionsTable = &schema.Table{
|
||||
Name: "user_sessions",
|
||||
Columns: UserSessionsColumns,
|
||||
PrimaryKey: []*schema.Column{UserSessionsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "user_sessions_users_sessions",
|
||||
Columns: []*schema.Column{UserSessionsColumns[6]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "usersession_expires_at",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UserSessionsColumns[2]},
|
||||
},
|
||||
{
|
||||
Name: "usersession_invalidated",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UserSessionsColumns[3]},
|
||||
},
|
||||
{
|
||||
Name: "usersession_ip",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UserSessionsColumns[5]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
AccessControlsTable,
|
||||
AuditsTable,
|
||||
RolesTable,
|
||||
TodosTable,
|
||||
UsersTable,
|
||||
UserSessionsTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
AuditsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
UserSessionsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
}
|
Reference in New Issue
Block a user