From 8920d40dbca8debf1cd38e6dfd691a94a8f1a195 Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Thu, 19 Oct 2023 16:26:54 -0700 Subject: [PATCH] Fix access token --- packages/api/internal/db/ent/accesstoken.go | 19 +--- .../db/ent/accesstoken/accesstoken.go | 14 +-- .../api/internal/db/ent/accesstoken/where.go | 94 ++++--------------- .../api/internal/db/ent/accesstoken_create.go | 36 ++++--- .../api/internal/db/ent/accesstoken_delete.go | 2 +- .../api/internal/db/ent/accesstoken_query.go | 28 +++--- .../api/internal/db/ent/accesstoken_update.go | 4 +- packages/api/internal/db/ent/client.go | 8 +- .../api/internal/db/ent/migrate/schema.go | 3 +- packages/api/internal/db/ent/mutation.go | 72 +++----------- .../internal/db/ent/schema/access_token.go | 2 +- packages/api/internal/db/ent/user.go | 12 +-- 12 files changed, 82 insertions(+), 212 deletions(-) diff --git a/packages/api/internal/db/ent/accesstoken.go b/packages/api/internal/db/ent/accesstoken.go index 29b760243..7a8447de4 100644 --- a/packages/api/internal/db/ent/accesstoken.go +++ b/packages/api/internal/db/ent/accesstoken.go @@ -17,9 +17,7 @@ import ( type AccessToken struct { config `json:"-"` // ID of the ent. - ID int `json:"id,omitempty"` - // AccessToken holds the value of the "access_token" field. - AccessToken string `json:"access_token,omitempty"` + ID string `json:"id,omitempty"` // UserID holds the value of the "user_id" field. UserID uuid.UUID `json:"user_id,omitempty"` // CreatedAt holds the value of the "created_at" field. @@ -54,8 +52,6 @@ func (*AccessToken) scanValues(columns []string) ([]any, error) { for i := range columns { switch columns[i] { case accesstoken.FieldID: - values[i] = new(sql.NullInt64) - case accesstoken.FieldAccessToken: values[i] = new(sql.NullString) case accesstoken.FieldCreatedAt: values[i] = new(sql.NullTime) @@ -77,16 +73,10 @@ func (at *AccessToken) assignValues(columns []string, values []any) error { for i := range columns { switch columns[i] { case accesstoken.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - at.ID = int(value.Int64) - case accesstoken.FieldAccessToken: if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field access_token", values[i]) + return fmt.Errorf("unexpected type %T for field id", values[i]) } else if value.Valid { - at.AccessToken = value.String + at.ID = value.String } case accesstoken.FieldUserID: if value, ok := values[i].(*uuid.UUID); !ok { @@ -141,9 +131,6 @@ func (at *AccessToken) String() string { var builder strings.Builder builder.WriteString("AccessToken(") builder.WriteString(fmt.Sprintf("id=%v, ", at.ID)) - builder.WriteString("access_token=") - builder.WriteString(at.AccessToken) - builder.WriteString(", ") builder.WriteString("user_id=") builder.WriteString(fmt.Sprintf("%v", at.UserID)) builder.WriteString(", ") diff --git a/packages/api/internal/db/ent/accesstoken/accesstoken.go b/packages/api/internal/db/ent/accesstoken/accesstoken.go index 0ca0b745e..3b4319cb4 100644 --- a/packages/api/internal/db/ent/accesstoken/accesstoken.go +++ b/packages/api/internal/db/ent/accesstoken/accesstoken.go @@ -11,15 +11,15 @@ const ( // Label holds the string label denoting the accesstoken type in the database. Label = "access_token" // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldAccessToken holds the string denoting the access_token field in the database. - FieldAccessToken = "access_token" + FieldID = "access_token" // FieldUserID holds the string denoting the user_id field in the database. FieldUserID = "user_id" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" // EdgeUsers holds the string denoting the users edge name in mutations. EdgeUsers = "users" + // UserFieldID holds the string denoting the ID field of the User. + UserFieldID = "id" // Table holds the table name of the accesstoken in the database. Table = "access_tokens" // UsersTable is the table that holds the users relation/edge. @@ -34,7 +34,6 @@ const ( // Columns holds all SQL columns for accesstoken fields. var Columns = []string{ FieldID, - FieldAccessToken, FieldUserID, FieldCreatedAt, } @@ -57,11 +56,6 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// ByAccessToken orders the results by the access_token field. -func ByAccessToken(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldAccessToken, opts...).ToFunc() -} - // ByUserID orders the results by the user_id field. func ByUserID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldUserID, opts...).ToFunc() @@ -88,7 +82,7 @@ func ByUsers(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { func newUsersStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(UsersInverseTable, FieldID), + sqlgraph.To(UsersInverseTable, UserFieldID), sqlgraph.Edge(sqlgraph.O2M, false, UsersTable, UsersColumn), ) } diff --git a/packages/api/internal/db/ent/accesstoken/where.go b/packages/api/internal/db/ent/accesstoken/where.go index d717e3f89..0ecb23e0d 100644 --- a/packages/api/internal/db/ent/accesstoken/where.go +++ b/packages/api/internal/db/ent/accesstoken/where.go @@ -13,53 +13,58 @@ import ( ) // ID filters vertices based on their ID field. -func ID(id int) predicate.AccessToken { +func ID(id string) predicate.AccessToken { return predicate.AccessToken(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.AccessToken { +func IDEQ(id string) predicate.AccessToken { return predicate.AccessToken(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.AccessToken { +func IDNEQ(id string) predicate.AccessToken { return predicate.AccessToken(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.AccessToken { +func IDIn(ids ...string) predicate.AccessToken { return predicate.AccessToken(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.AccessToken { +func IDNotIn(ids ...string) predicate.AccessToken { return predicate.AccessToken(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.AccessToken { +func IDGT(id string) predicate.AccessToken { return predicate.AccessToken(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.AccessToken { +func IDGTE(id string) predicate.AccessToken { return predicate.AccessToken(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.AccessToken { +func IDLT(id string) predicate.AccessToken { return predicate.AccessToken(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.AccessToken { +func IDLTE(id string) predicate.AccessToken { return predicate.AccessToken(sql.FieldLTE(FieldID, id)) } -// AccessToken applies equality check predicate on the "access_token" field. It's identical to AccessTokenEQ. -func AccessToken(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldEQ(FieldAccessToken, v)) +// IDEqualFold applies the EqualFold predicate on the ID field. +func IDEqualFold(id string) predicate.AccessToken { + return predicate.AccessToken(sql.FieldEqualFold(FieldID, id)) +} + +// IDContainsFold applies the ContainsFold predicate on the ID field. +func IDContainsFold(id string) predicate.AccessToken { + return predicate.AccessToken(sql.FieldContainsFold(FieldID, id)) } // UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. @@ -72,71 +77,6 @@ func CreatedAt(v time.Time) predicate.AccessToken { return predicate.AccessToken(sql.FieldEQ(FieldCreatedAt, v)) } -// AccessTokenEQ applies the EQ predicate on the "access_token" field. -func AccessTokenEQ(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldEQ(FieldAccessToken, v)) -} - -// AccessTokenNEQ applies the NEQ predicate on the "access_token" field. -func AccessTokenNEQ(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldNEQ(FieldAccessToken, v)) -} - -// AccessTokenIn applies the In predicate on the "access_token" field. -func AccessTokenIn(vs ...string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldIn(FieldAccessToken, vs...)) -} - -// AccessTokenNotIn applies the NotIn predicate on the "access_token" field. -func AccessTokenNotIn(vs ...string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldNotIn(FieldAccessToken, vs...)) -} - -// AccessTokenGT applies the GT predicate on the "access_token" field. -func AccessTokenGT(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldGT(FieldAccessToken, v)) -} - -// AccessTokenGTE applies the GTE predicate on the "access_token" field. -func AccessTokenGTE(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldGTE(FieldAccessToken, v)) -} - -// AccessTokenLT applies the LT predicate on the "access_token" field. -func AccessTokenLT(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldLT(FieldAccessToken, v)) -} - -// AccessTokenLTE applies the LTE predicate on the "access_token" field. -func AccessTokenLTE(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldLTE(FieldAccessToken, v)) -} - -// AccessTokenContains applies the Contains predicate on the "access_token" field. -func AccessTokenContains(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldContains(FieldAccessToken, v)) -} - -// AccessTokenHasPrefix applies the HasPrefix predicate on the "access_token" field. -func AccessTokenHasPrefix(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldHasPrefix(FieldAccessToken, v)) -} - -// AccessTokenHasSuffix applies the HasSuffix predicate on the "access_token" field. -func AccessTokenHasSuffix(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldHasSuffix(FieldAccessToken, v)) -} - -// AccessTokenEqualFold applies the EqualFold predicate on the "access_token" field. -func AccessTokenEqualFold(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldEqualFold(FieldAccessToken, v)) -} - -// AccessTokenContainsFold applies the ContainsFold predicate on the "access_token" field. -func AccessTokenContainsFold(v string) predicate.AccessToken { - return predicate.AccessToken(sql.FieldContainsFold(FieldAccessToken, v)) -} - // UserIDEQ applies the EQ predicate on the "user_id" field. func UserIDEQ(v uuid.UUID) predicate.AccessToken { return predicate.AccessToken(sql.FieldEQ(FieldUserID, v)) diff --git a/packages/api/internal/db/ent/accesstoken_create.go b/packages/api/internal/db/ent/accesstoken_create.go index 134ff9359..f2eecd518 100644 --- a/packages/api/internal/db/ent/accesstoken_create.go +++ b/packages/api/internal/db/ent/accesstoken_create.go @@ -22,12 +22,6 @@ type AccessTokenCreate struct { hooks []Hook } -// SetAccessToken sets the "access_token" field. -func (atc *AccessTokenCreate) SetAccessToken(s string) *AccessTokenCreate { - atc.mutation.SetAccessToken(s) - return atc -} - // SetUserID sets the "user_id" field. func (atc *AccessTokenCreate) SetUserID(u uuid.UUID) *AccessTokenCreate { atc.mutation.SetUserID(u) @@ -40,6 +34,12 @@ func (atc *AccessTokenCreate) SetCreatedAt(t time.Time) *AccessTokenCreate { return atc } +// SetID sets the "id" field. +func (atc *AccessTokenCreate) SetID(s string) *AccessTokenCreate { + atc.mutation.SetID(s) + return atc +} + // AddUserIDs adds the "users" edge to the User entity by IDs. func (atc *AccessTokenCreate) AddUserIDs(ids ...uuid.UUID) *AccessTokenCreate { atc.mutation.AddUserIDs(ids...) @@ -89,9 +89,6 @@ func (atc *AccessTokenCreate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (atc *AccessTokenCreate) check() error { - if _, ok := atc.mutation.AccessToken(); !ok { - return &ValidationError{Name: "access_token", err: errors.New(`ent: missing required field "AccessToken.access_token"`)} - } if _, ok := atc.mutation.UserID(); !ok { return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "AccessToken.user_id"`)} } @@ -112,8 +109,13 @@ func (atc *AccessTokenCreate) sqlSave(ctx context.Context) (*AccessToken, error) } return nil, err } - id := _spec.ID.Value.(int64) - _node.ID = int(id) + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(string); ok { + _node.ID = id + } else { + return nil, fmt.Errorf("unexpected AccessToken.ID type: %T", _spec.ID.Value) + } + } atc.mutation.id = &_node.ID atc.mutation.done = true return _node, nil @@ -122,12 +124,12 @@ func (atc *AccessTokenCreate) sqlSave(ctx context.Context) (*AccessToken, error) func (atc *AccessTokenCreate) createSpec() (*AccessToken, *sqlgraph.CreateSpec) { var ( _node = &AccessToken{config: atc.config} - _spec = sqlgraph.NewCreateSpec(accesstoken.Table, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeInt)) + _spec = sqlgraph.NewCreateSpec(accesstoken.Table, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeString)) ) _spec.Schema = atc.schemaConfig.AccessToken - if value, ok := atc.mutation.AccessToken(); ok { - _spec.SetField(accesstoken.FieldAccessToken, field.TypeString, value) - _node.AccessToken = value + if id, ok := atc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id } if value, ok := atc.mutation.UserID(); ok { _spec.SetField(accesstoken.FieldUserID, field.TypeUUID, value) @@ -201,10 +203,6 @@ func (atcb *AccessTokenCreateBulk) Save(ctx context.Context) ([]*AccessToken, er return nil, err } mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } mutation.done = true return nodes[i], nil }) diff --git a/packages/api/internal/db/ent/accesstoken_delete.go b/packages/api/internal/db/ent/accesstoken_delete.go index 58056e194..4dbb7b936 100644 --- a/packages/api/internal/db/ent/accesstoken_delete.go +++ b/packages/api/internal/db/ent/accesstoken_delete.go @@ -41,7 +41,7 @@ func (atd *AccessTokenDelete) ExecX(ctx context.Context) int { } func (atd *AccessTokenDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(accesstoken.Table, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeInt)) + _spec := sqlgraph.NewDeleteSpec(accesstoken.Table, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeString)) _spec.Node.Schema = atd.schemaConfig.AccessToken ctx = internal.NewSchemaConfigContext(ctx, atd.schemaConfig) if ps := atd.mutation.predicates; len(ps) > 0 { diff --git a/packages/api/internal/db/ent/accesstoken_query.go b/packages/api/internal/db/ent/accesstoken_query.go index 81965f57d..561e9807a 100644 --- a/packages/api/internal/db/ent/accesstoken_query.go +++ b/packages/api/internal/db/ent/accesstoken_query.go @@ -110,8 +110,8 @@ func (atq *AccessTokenQuery) FirstX(ctx context.Context) *AccessToken { // FirstID returns the first AccessToken ID from the query. // Returns a *NotFoundError when no AccessToken ID was found. -func (atq *AccessTokenQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int +func (atq *AccessTokenQuery) FirstID(ctx context.Context) (id string, err error) { + var ids []string if ids, err = atq.Limit(1).IDs(setContextOp(ctx, atq.ctx, "FirstID")); err != nil { return } @@ -123,7 +123,7 @@ func (atq *AccessTokenQuery) FirstID(ctx context.Context) (id int, err error) { } // FirstIDX is like FirstID, but panics if an error occurs. -func (atq *AccessTokenQuery) FirstIDX(ctx context.Context) int { +func (atq *AccessTokenQuery) FirstIDX(ctx context.Context) string { id, err := atq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -161,8 +161,8 @@ func (atq *AccessTokenQuery) OnlyX(ctx context.Context) *AccessToken { // OnlyID is like Only, but returns the only AccessToken ID in the query. // Returns a *NotSingularError when more than one AccessToken ID is found. // Returns a *NotFoundError when no entities are found. -func (atq *AccessTokenQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int +func (atq *AccessTokenQuery) OnlyID(ctx context.Context) (id string, err error) { + var ids []string if ids, err = atq.Limit(2).IDs(setContextOp(ctx, atq.ctx, "OnlyID")); err != nil { return } @@ -178,7 +178,7 @@ func (atq *AccessTokenQuery) OnlyID(ctx context.Context) (id int, err error) { } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (atq *AccessTokenQuery) OnlyIDX(ctx context.Context) int { +func (atq *AccessTokenQuery) OnlyIDX(ctx context.Context) string { id, err := atq.OnlyID(ctx) if err != nil { panic(err) @@ -206,7 +206,7 @@ func (atq *AccessTokenQuery) AllX(ctx context.Context) []*AccessToken { } // IDs executes the query and returns a list of AccessToken IDs. -func (atq *AccessTokenQuery) IDs(ctx context.Context) (ids []int, err error) { +func (atq *AccessTokenQuery) IDs(ctx context.Context) (ids []string, err error) { if atq.ctx.Unique == nil && atq.path != nil { atq.Unique(true) } @@ -218,7 +218,7 @@ func (atq *AccessTokenQuery) IDs(ctx context.Context) (ids []int, err error) { } // IDsX is like IDs, but panics if an error occurs. -func (atq *AccessTokenQuery) IDsX(ctx context.Context) []int { +func (atq *AccessTokenQuery) IDsX(ctx context.Context) []string { ids, err := atq.IDs(ctx) if err != nil { panic(err) @@ -302,12 +302,12 @@ func (atq *AccessTokenQuery) WithUsers(opts ...func(*UserQuery)) *AccessTokenQue // Example: // // var v []struct { -// AccessToken string `json:"access_token,omitempty"` +// UserID uuid.UUID `json:"user_id,omitempty"` // Count int `json:"count,omitempty"` // } // // client.AccessToken.Query(). -// GroupBy(accesstoken.FieldAccessToken). +// GroupBy(accesstoken.FieldUserID). // Aggregate(ent.Count()). // Scan(ctx, &v) func (atq *AccessTokenQuery) GroupBy(field string, fields ...string) *AccessTokenGroupBy { @@ -325,11 +325,11 @@ func (atq *AccessTokenQuery) GroupBy(field string, fields ...string) *AccessToke // Example: // // var v []struct { -// AccessToken string `json:"access_token,omitempty"` +// UserID uuid.UUID `json:"user_id,omitempty"` // } // // client.AccessToken.Query(). -// Select(accesstoken.FieldAccessToken). +// Select(accesstoken.FieldUserID). // Scan(ctx, &v) func (atq *AccessTokenQuery) Select(fields ...string) *AccessTokenSelect { atq.ctx.Fields = append(atq.ctx.Fields, fields...) @@ -410,7 +410,7 @@ func (atq *AccessTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([] func (atq *AccessTokenQuery) loadUsers(ctx context.Context, query *UserQuery, nodes []*AccessToken, init func(*AccessToken), assign func(*AccessToken, *User)) error { fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*AccessToken) + nodeids := make(map[string]*AccessToken) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] @@ -452,7 +452,7 @@ func (atq *AccessTokenQuery) sqlCount(ctx context.Context) (int, error) { } func (atq *AccessTokenQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(accesstoken.Table, accesstoken.Columns, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeInt)) + _spec := sqlgraph.NewQuerySpec(accesstoken.Table, accesstoken.Columns, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeString)) _spec.From = atq.sql if unique := atq.ctx.Unique; unique != nil { _spec.Unique = *unique diff --git a/packages/api/internal/db/ent/accesstoken_update.go b/packages/api/internal/db/ent/accesstoken_update.go index 9040b4016..242af6bd8 100644 --- a/packages/api/internal/db/ent/accesstoken_update.go +++ b/packages/api/internal/db/ent/accesstoken_update.go @@ -105,7 +105,7 @@ func (atu *AccessTokenUpdate) ExecX(ctx context.Context) { } func (atu *AccessTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := sqlgraph.NewUpdateSpec(accesstoken.Table, accesstoken.Columns, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeInt)) + _spec := sqlgraph.NewUpdateSpec(accesstoken.Table, accesstoken.Columns, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeString)) if ps := atu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -274,7 +274,7 @@ func (atuo *AccessTokenUpdateOne) ExecX(ctx context.Context) { } func (atuo *AccessTokenUpdateOne) sqlSave(ctx context.Context) (_node *AccessToken, err error) { - _spec := sqlgraph.NewUpdateSpec(accesstoken.Table, accesstoken.Columns, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeInt)) + _spec := sqlgraph.NewUpdateSpec(accesstoken.Table, accesstoken.Columns, sqlgraph.NewFieldSpec(accesstoken.FieldID, field.TypeString)) id, ok := atuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AccessToken.id" for update`)} diff --git a/packages/api/internal/db/ent/client.go b/packages/api/internal/db/ent/client.go index 9b02c3f8f..9a7b168d1 100644 --- a/packages/api/internal/db/ent/client.go +++ b/packages/api/internal/db/ent/client.go @@ -306,7 +306,7 @@ func (c *AccessTokenClient) UpdateOne(at *AccessToken) *AccessTokenUpdateOne { } // UpdateOneID returns an update builder for the given id. -func (c *AccessTokenClient) UpdateOneID(id int) *AccessTokenUpdateOne { +func (c *AccessTokenClient) UpdateOneID(id string) *AccessTokenUpdateOne { mutation := newAccessTokenMutation(c.config, OpUpdateOne, withAccessTokenID(id)) return &AccessTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } @@ -323,7 +323,7 @@ func (c *AccessTokenClient) DeleteOne(at *AccessToken) *AccessTokenDeleteOne { } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *AccessTokenClient) DeleteOneID(id int) *AccessTokenDeleteOne { +func (c *AccessTokenClient) DeleteOneID(id string) *AccessTokenDeleteOne { builder := c.Delete().Where(accesstoken.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -340,12 +340,12 @@ func (c *AccessTokenClient) Query() *AccessTokenQuery { } // Get returns a AccessToken entity by its id. -func (c *AccessTokenClient) Get(ctx context.Context, id int) (*AccessToken, error) { +func (c *AccessTokenClient) Get(ctx context.Context, id string) (*AccessToken, error) { return c.Query().Where(accesstoken.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. -func (c *AccessTokenClient) GetX(ctx context.Context, id int) *AccessToken { +func (c *AccessTokenClient) GetX(ctx context.Context, id string) *AccessToken { obj, err := c.Get(ctx, id) if err != nil { panic(err) diff --git a/packages/api/internal/db/ent/migrate/schema.go b/packages/api/internal/db/ent/migrate/schema.go index 5e7b6bd38..ef2d01b8a 100644 --- a/packages/api/internal/db/ent/migrate/schema.go +++ b/packages/api/internal/db/ent/migrate/schema.go @@ -10,7 +10,6 @@ import ( var ( // AccessTokensColumns holds the columns for the "access_tokens" table. AccessTokensColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "access_token", Type: field.TypeString, Unique: true}, {Name: "user_id", Type: field.TypeUUID}, {Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"}, @@ -83,7 +82,7 @@ var ( UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, {Name: "email", Type: field.TypeString}, - {Name: "access_token_users", Type: field.TypeInt, Nullable: true}, + {Name: "access_token_users", Type: field.TypeString, Nullable: true}, } // UsersTable holds the schema information for the "users" table. UsersTable = &schema.Table{ diff --git a/packages/api/internal/db/ent/mutation.go b/packages/api/internal/db/ent/mutation.go index 071c2f2b9..4730a2267 100644 --- a/packages/api/internal/db/ent/mutation.go +++ b/packages/api/internal/db/ent/mutation.go @@ -43,8 +43,7 @@ type AccessTokenMutation struct { config op Op typ string - id *int - access_token *string + id *string user_id *uuid.UUID created_at *time.Time clearedFields map[string]struct{} @@ -76,7 +75,7 @@ func newAccessTokenMutation(c config, op Op, opts ...accesstokenOption) *AccessT } // withAccessTokenID sets the ID field of the mutation. -func withAccessTokenID(id int) accesstokenOption { +func withAccessTokenID(id string) accesstokenOption { return func(m *AccessTokenMutation) { var ( err error @@ -126,9 +125,15 @@ func (m AccessTokenMutation) Tx() (*Tx, error) { return tx, nil } +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of AccessToken entities. +func (m *AccessTokenMutation) SetID(id string) { + m.id = &id +} + // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *AccessTokenMutation) ID() (id int, exists bool) { +func (m *AccessTokenMutation) ID() (id string, exists bool) { if m.id == nil { return } @@ -139,12 +144,12 @@ func (m *AccessTokenMutation) ID() (id int, exists bool) { // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. -func (m *AccessTokenMutation) IDs(ctx context.Context) ([]int, error) { +func (m *AccessTokenMutation) IDs(ctx context.Context) ([]string, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []int{id}, nil + return []string{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -154,42 +159,6 @@ func (m *AccessTokenMutation) IDs(ctx context.Context) ([]int, error) { } } -// SetAccessToken sets the "access_token" field. -func (m *AccessTokenMutation) SetAccessToken(s string) { - m.access_token = &s -} - -// AccessToken returns the value of the "access_token" field in the mutation. -func (m *AccessTokenMutation) AccessToken() (r string, exists bool) { - v := m.access_token - if v == nil { - return - } - return *v, true -} - -// OldAccessToken returns the old "access_token" field's value of the AccessToken entity. -// If the AccessToken object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *AccessTokenMutation) OldAccessToken(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAccessToken is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAccessToken requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldAccessToken: %w", err) - } - return oldValue.AccessToken, nil -} - -// ResetAccessToken resets all changes to the "access_token" field. -func (m *AccessTokenMutation) ResetAccessToken() { - m.access_token = nil -} - // SetUserID sets the "user_id" field. func (m *AccessTokenMutation) SetUserID(u uuid.UUID) { m.user_id = &u @@ -350,10 +319,7 @@ func (m *AccessTokenMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *AccessTokenMutation) Fields() []string { - fields := make([]string, 0, 3) - if m.access_token != nil { - fields = append(fields, accesstoken.FieldAccessToken) - } + fields := make([]string, 0, 2) if m.user_id != nil { fields = append(fields, accesstoken.FieldUserID) } @@ -368,8 +334,6 @@ func (m *AccessTokenMutation) Fields() []string { // schema. func (m *AccessTokenMutation) Field(name string) (ent.Value, bool) { switch name { - case accesstoken.FieldAccessToken: - return m.AccessToken() case accesstoken.FieldUserID: return m.UserID() case accesstoken.FieldCreatedAt: @@ -383,8 +347,6 @@ func (m *AccessTokenMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *AccessTokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case accesstoken.FieldAccessToken: - return m.OldAccessToken(ctx) case accesstoken.FieldUserID: return m.OldUserID(ctx) case accesstoken.FieldCreatedAt: @@ -398,13 +360,6 @@ func (m *AccessTokenMutation) OldField(ctx context.Context, name string) (ent.Va // type. func (m *AccessTokenMutation) SetField(name string, value ent.Value) error { switch name { - case accesstoken.FieldAccessToken: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAccessToken(v) - return nil case accesstoken.FieldUserID: v, ok := value.(uuid.UUID) if !ok { @@ -468,9 +423,6 @@ func (m *AccessTokenMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *AccessTokenMutation) ResetField(name string) error { switch name { - case accesstoken.FieldAccessToken: - m.ResetAccessToken() - return nil case accesstoken.FieldUserID: m.ResetUserID() return nil diff --git a/packages/api/internal/db/ent/schema/access_token.go b/packages/api/internal/db/ent/schema/access_token.go index 13616545c..1a32343e0 100644 --- a/packages/api/internal/db/ent/schema/access_token.go +++ b/packages/api/internal/db/ent/schema/access_token.go @@ -14,7 +14,7 @@ type AccessToken struct { func (AccessToken) Fields() []ent.Field { return []ent.Field{ - field.String("access_token").Unique().Immutable(), + field.String("id").Unique().StorageKey("access_token").Immutable(), field.UUID("user_id", uuid.UUID{}), field.Time("created_at").Immutable().Annotations( entsql.Default("CURRENT_TIMESTAMP"), diff --git a/packages/api/internal/db/ent/user.go b/packages/api/internal/db/ent/user.go index 0ab7e53ab..07eeaee40 100644 --- a/packages/api/internal/db/ent/user.go +++ b/packages/api/internal/db/ent/user.go @@ -22,7 +22,7 @@ type User struct { // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the UserQuery when eager-loading is set. Edges UserEdges `json:"edges"` - access_token_users *int + access_token_users *string selectValues sql.SelectValues } @@ -65,7 +65,7 @@ func (*User) scanValues(columns []string) ([]any, error) { case user.FieldID: values[i] = new(uuid.UUID) case user.ForeignKeys[0]: // access_token_users - values[i] = new(sql.NullInt64) + values[i] = new(sql.NullString) default: values[i] = new(sql.UnknownType) } @@ -94,11 +94,11 @@ func (u *User) assignValues(columns []string, values []any) error { u.Email = value.String } case user.ForeignKeys[0]: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for edge-field access_token_users", value) + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field access_token_users", values[i]) } else if value.Valid { - u.access_token_users = new(int) - *u.access_token_users = int(value.Int64) + u.access_token_users = new(string) + *u.access_token_users = value.String } default: u.selectValues.Set(columns[i], values[i])