From c733ba537797d49191b2497003eeacbe38118d0f Mon Sep 17 00:00:00 2001 From: Jakub Novak Date: Fri, 22 Nov 2024 09:20:41 -0800 Subject: [PATCH] Update team api key model --- packages/shared/pkg/db/apiKeys.go | 2 +- packages/shared/pkg/models/client.go | 8 +- packages/shared/pkg/models/migrate/schema.go | 5 +- packages/shared/pkg/models/mutation.go | 100 ++++++++++++++---- packages/shared/pkg/models/runtime.go | 4 +- packages/shared/pkg/models/team/team.go | 4 +- packages/shared/pkg/models/team_create.go | 6 +- packages/shared/pkg/models/team_update.go | 28 ++--- packages/shared/pkg/models/teamapikey.go | 20 +++- .../pkg/models/teamapikey/teamapikey.go | 18 ++-- .../shared/pkg/models/teamapikey/where.go | 94 +++++++++++++--- .../shared/pkg/models/teamapikey_create.go | 79 +++++++++++--- .../shared/pkg/models/teamapikey_delete.go | 2 +- .../shared/pkg/models/teamapikey_query.go | 26 ++--- .../shared/pkg/models/teamapikey_update.go | 38 ++++++- packages/shared/pkg/models/user/user.go | 4 +- packages/shared/pkg/models/user_create.go | 6 +- packages/shared/pkg/models/user_update.go | 28 ++--- 18 files changed, 342 insertions(+), 130 deletions(-) diff --git a/packages/shared/pkg/db/apiKeys.go b/packages/shared/pkg/db/apiKeys.go index b5639f9e1..8dc87d42b 100644 --- a/packages/shared/pkg/db/apiKeys.go +++ b/packages/shared/pkg/db/apiKeys.go @@ -17,7 +17,7 @@ func (db *DB) GetTeamAuth(ctx context.Context, apiKey string) (*models.Team, *mo TeamAPIKey. Query(). WithTeam(). - Where(teamapikey.ID(apiKey)). + Where(teamapikey.APIKey(apiKey)). QueryTeam(). WithTeamTier(). Only(ctx) diff --git a/packages/shared/pkg/models/client.go b/packages/shared/pkg/models/client.go index 0edd33b3d..270b0189f 100644 --- a/packages/shared/pkg/models/client.go +++ b/packages/shared/pkg/models/client.go @@ -1212,7 +1212,7 @@ func (c *TeamAPIKeyClient) UpdateOne(tak *TeamAPIKey) *TeamAPIKeyUpdateOne { } // UpdateOneID returns an update builder for the given id. -func (c *TeamAPIKeyClient) UpdateOneID(id string) *TeamAPIKeyUpdateOne { +func (c *TeamAPIKeyClient) UpdateOneID(id uuid.UUID) *TeamAPIKeyUpdateOne { mutation := newTeamAPIKeyMutation(c.config, OpUpdateOne, withTeamAPIKeyID(id)) return &TeamAPIKeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } @@ -1229,7 +1229,7 @@ func (c *TeamAPIKeyClient) DeleteOne(tak *TeamAPIKey) *TeamAPIKeyDeleteOne { } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *TeamAPIKeyClient) DeleteOneID(id string) *TeamAPIKeyDeleteOne { +func (c *TeamAPIKeyClient) DeleteOneID(id uuid.UUID) *TeamAPIKeyDeleteOne { builder := c.Delete().Where(teamapikey.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -1246,12 +1246,12 @@ func (c *TeamAPIKeyClient) Query() *TeamAPIKeyQuery { } // Get returns a TeamAPIKey entity by its id. -func (c *TeamAPIKeyClient) Get(ctx context.Context, id string) (*TeamAPIKey, error) { +func (c *TeamAPIKeyClient) Get(ctx context.Context, id uuid.UUID) (*TeamAPIKey, error) { return c.Query().Where(teamapikey.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. -func (c *TeamAPIKeyClient) GetX(ctx context.Context, id string) *TeamAPIKey { +func (c *TeamAPIKeyClient) GetX(ctx context.Context, id uuid.UUID) *TeamAPIKey { obj, err := c.Get(ctx, id) if err != nil { panic(err) diff --git a/packages/shared/pkg/models/migrate/schema.go b/packages/shared/pkg/models/migrate/schema.go index 21d76bb30..f86253993 100644 --- a/packages/shared/pkg/models/migrate/schema.go +++ b/packages/shared/pkg/models/migrate/schema.go @@ -133,6 +133,7 @@ var ( } // TeamAPIKeysColumns holds the columns for the "team_api_keys" table. TeamAPIKeysColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true, Default: "gen_random_uuid()"}, {Name: "api_key", Type: field.TypeString, Unique: true, SchemaType: map[string]string{"postgres": "character varying(44)"}}, {Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"}, {Name: "updated_at", Type: field.TypeTime, Nullable: true}, @@ -149,13 +150,13 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "team_api_keys_teams_team_api_keys", - Columns: []*schema.Column{TeamAPIKeysColumns[5]}, + Columns: []*schema.Column{TeamAPIKeysColumns[6]}, RefColumns: []*schema.Column{TeamsColumns[0]}, OnDelete: schema.Cascade, }, { Symbol: "team_api_keys_users_created_api_keys", - Columns: []*schema.Column{TeamAPIKeysColumns[6]}, + Columns: []*schema.Column{TeamAPIKeysColumns[7]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/packages/shared/pkg/models/mutation.go b/packages/shared/pkg/models/mutation.go index e2b6f0db3..82796ead2 100644 --- a/packages/shared/pkg/models/mutation.go +++ b/packages/shared/pkg/models/mutation.go @@ -3250,8 +3250,8 @@ type TeamMutation struct { users map[uuid.UUID]struct{} removedusers map[uuid.UUID]struct{} clearedusers bool - team_api_keys map[string]struct{} - removedteam_api_keys map[string]struct{} + team_api_keys map[uuid.UUID]struct{} + removedteam_api_keys map[uuid.UUID]struct{} clearedteam_api_keys bool team_tier *string clearedteam_tier bool @@ -3690,9 +3690,9 @@ func (m *TeamMutation) ResetUsers() { } // AddTeamAPIKeyIDs adds the "team_api_keys" edge to the TeamAPIKey entity by ids. -func (m *TeamMutation) AddTeamAPIKeyIDs(ids ...string) { +func (m *TeamMutation) AddTeamAPIKeyIDs(ids ...uuid.UUID) { if m.team_api_keys == nil { - m.team_api_keys = make(map[string]struct{}) + m.team_api_keys = make(map[uuid.UUID]struct{}) } for i := range ids { m.team_api_keys[ids[i]] = struct{}{} @@ -3710,9 +3710,9 @@ func (m *TeamMutation) TeamAPIKeysCleared() bool { } // RemoveTeamAPIKeyIDs removes the "team_api_keys" edge to the TeamAPIKey entity by IDs. -func (m *TeamMutation) RemoveTeamAPIKeyIDs(ids ...string) { +func (m *TeamMutation) RemoveTeamAPIKeyIDs(ids ...uuid.UUID) { if m.removedteam_api_keys == nil { - m.removedteam_api_keys = make(map[string]struct{}) + m.removedteam_api_keys = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.team_api_keys, ids[i]) @@ -3721,7 +3721,7 @@ func (m *TeamMutation) RemoveTeamAPIKeyIDs(ids ...string) { } // RemovedTeamAPIKeys returns the removed IDs of the "team_api_keys" edge to the TeamAPIKey entity. -func (m *TeamMutation) RemovedTeamAPIKeysIDs() (ids []string) { +func (m *TeamMutation) RemovedTeamAPIKeysIDs() (ids []uuid.UUID) { for id := range m.removedteam_api_keys { ids = append(ids, id) } @@ -3729,7 +3729,7 @@ func (m *TeamMutation) RemovedTeamAPIKeysIDs() (ids []string) { } // TeamAPIKeysIDs returns the "team_api_keys" edge IDs in the mutation. -func (m *TeamMutation) TeamAPIKeysIDs() (ids []string) { +func (m *TeamMutation) TeamAPIKeysIDs() (ids []uuid.UUID) { for id := range m.team_api_keys { ids = append(ids, id) } @@ -4318,7 +4318,8 @@ type TeamAPIKeyMutation struct { config op Op typ string - id *string + id *uuid.UUID + api_key *string created_at *time.Time updated_at *time.Time name *string @@ -4353,7 +4354,7 @@ func newTeamAPIKeyMutation(c config, op Op, opts ...teamapikeyOption) *TeamAPIKe } // withTeamAPIKeyID sets the ID field of the mutation. -func withTeamAPIKeyID(id string) teamapikeyOption { +func withTeamAPIKeyID(id uuid.UUID) teamapikeyOption { return func(m *TeamAPIKeyMutation) { var ( err error @@ -4405,13 +4406,13 @@ func (m TeamAPIKeyMutation) Tx() (*Tx, error) { // SetID sets the value of the id field. Note that this // operation is only accepted on creation of TeamAPIKey entities. -func (m *TeamAPIKeyMutation) SetID(id string) { +func (m *TeamAPIKeyMutation) SetID(id uuid.UUID) { 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 *TeamAPIKeyMutation) ID() (id string, exists bool) { +func (m *TeamAPIKeyMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } @@ -4422,12 +4423,12 @@ func (m *TeamAPIKeyMutation) ID() (id string, 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 *TeamAPIKeyMutation) IDs(ctx context.Context) ([]string, error) { +func (m *TeamAPIKeyMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []string{id}, nil + return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -4437,6 +4438,42 @@ func (m *TeamAPIKeyMutation) IDs(ctx context.Context) ([]string, error) { } } +// SetAPIKey sets the "api_key" field. +func (m *TeamAPIKeyMutation) SetAPIKey(s string) { + m.api_key = &s +} + +// APIKey returns the value of the "api_key" field in the mutation. +func (m *TeamAPIKeyMutation) APIKey() (r string, exists bool) { + v := m.api_key + if v == nil { + return + } + return *v, true +} + +// OldAPIKey returns the old "api_key" field's value of the TeamAPIKey entity. +// If the TeamAPIKey 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 *TeamAPIKeyMutation) OldAPIKey(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAPIKey is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAPIKey requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAPIKey: %w", err) + } + return oldValue.APIKey, nil +} + +// ResetAPIKey resets all changes to the "api_key" field. +func (m *TeamAPIKeyMutation) ResetAPIKey() { + m.api_key = nil +} + // SetCreatedAt sets the "created_at" field. func (m *TeamAPIKeyMutation) SetCreatedAt(t time.Time) { m.created_at = &t @@ -4793,7 +4830,10 @@ func (m *TeamAPIKeyMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *TeamAPIKeyMutation) Fields() []string { - fields := make([]string, 0, 6) + fields := make([]string, 0, 7) + if m.api_key != nil { + fields = append(fields, teamapikey.FieldAPIKey) + } if m.created_at != nil { fields = append(fields, teamapikey.FieldCreatedAt) } @@ -4820,6 +4860,8 @@ func (m *TeamAPIKeyMutation) Fields() []string { // schema. func (m *TeamAPIKeyMutation) Field(name string) (ent.Value, bool) { switch name { + case teamapikey.FieldAPIKey: + return m.APIKey() case teamapikey.FieldCreatedAt: return m.CreatedAt() case teamapikey.FieldUpdatedAt: @@ -4841,6 +4883,8 @@ func (m *TeamAPIKeyMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *TeamAPIKeyMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { + case teamapikey.FieldAPIKey: + return m.OldAPIKey(ctx) case teamapikey.FieldCreatedAt: return m.OldCreatedAt(ctx) case teamapikey.FieldUpdatedAt: @@ -4862,6 +4906,13 @@ func (m *TeamAPIKeyMutation) OldField(ctx context.Context, name string) (ent.Val // type. func (m *TeamAPIKeyMutation) SetField(name string, value ent.Value) error { switch name { + case teamapikey.FieldAPIKey: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAPIKey(v) + return nil case teamapikey.FieldCreatedAt: v, ok := value.(time.Time) if !ok { @@ -4974,6 +5025,9 @@ func (m *TeamAPIKeyMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *TeamAPIKeyMutation) ResetField(name string) error { switch name { + case teamapikey.FieldAPIKey: + m.ResetAPIKey() + return nil case teamapikey.FieldCreatedAt: m.ResetCreatedAt() return nil @@ -5791,8 +5845,8 @@ type UserMutation struct { access_tokens map[string]struct{} removedaccess_tokens map[string]struct{} clearedaccess_tokens bool - created_api_keys map[string]struct{} - removedcreated_api_keys map[string]struct{} + created_api_keys map[uuid.UUID]struct{} + removedcreated_api_keys map[uuid.UUID]struct{} clearedcreated_api_keys bool users_teams map[int]struct{} removedusers_teams map[int]struct{} @@ -6051,9 +6105,9 @@ func (m *UserMutation) ResetAccessTokens() { } // AddCreatedAPIKeyIDs adds the "created_api_keys" edge to the TeamAPIKey entity by ids. -func (m *UserMutation) AddCreatedAPIKeyIDs(ids ...string) { +func (m *UserMutation) AddCreatedAPIKeyIDs(ids ...uuid.UUID) { if m.created_api_keys == nil { - m.created_api_keys = make(map[string]struct{}) + m.created_api_keys = make(map[uuid.UUID]struct{}) } for i := range ids { m.created_api_keys[ids[i]] = struct{}{} @@ -6071,9 +6125,9 @@ func (m *UserMutation) CreatedAPIKeysCleared() bool { } // RemoveCreatedAPIKeyIDs removes the "created_api_keys" edge to the TeamAPIKey entity by IDs. -func (m *UserMutation) RemoveCreatedAPIKeyIDs(ids ...string) { +func (m *UserMutation) RemoveCreatedAPIKeyIDs(ids ...uuid.UUID) { if m.removedcreated_api_keys == nil { - m.removedcreated_api_keys = make(map[string]struct{}) + m.removedcreated_api_keys = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.created_api_keys, ids[i]) @@ -6082,7 +6136,7 @@ func (m *UserMutation) RemoveCreatedAPIKeyIDs(ids ...string) { } // RemovedCreatedAPIKeys returns the removed IDs of the "created_api_keys" edge to the TeamAPIKey entity. -func (m *UserMutation) RemovedCreatedAPIKeysIDs() (ids []string) { +func (m *UserMutation) RemovedCreatedAPIKeysIDs() (ids []uuid.UUID) { for id := range m.removedcreated_api_keys { ids = append(ids, id) } @@ -6090,7 +6144,7 @@ func (m *UserMutation) RemovedCreatedAPIKeysIDs() (ids []string) { } // CreatedAPIKeysIDs returns the "created_api_keys" edge IDs in the mutation. -func (m *UserMutation) CreatedAPIKeysIDs() (ids []string) { +func (m *UserMutation) CreatedAPIKeysIDs() (ids []uuid.UUID) { for id := range m.created_api_keys { ids = append(ids, id) } diff --git a/packages/shared/pkg/models/runtime.go b/packages/shared/pkg/models/runtime.go index a085a9c51..fbf7c402a 100644 --- a/packages/shared/pkg/models/runtime.go +++ b/packages/shared/pkg/models/runtime.go @@ -74,11 +74,11 @@ func init() { teamapikeyFields := schema.TeamAPIKey{}.Fields() _ = teamapikeyFields // teamapikeyDescCreatedAt is the schema descriptor for created_at field. - teamapikeyDescCreatedAt := teamapikeyFields[1].Descriptor() + teamapikeyDescCreatedAt := teamapikeyFields[2].Descriptor() // teamapikey.DefaultCreatedAt holds the default value on creation for the created_at field. teamapikey.DefaultCreatedAt = teamapikeyDescCreatedAt.Default.(func() time.Time) // teamapikeyDescName is the schema descriptor for name field. - teamapikeyDescName := teamapikeyFields[4].Descriptor() + teamapikeyDescName := teamapikeyFields[5].Descriptor() // teamapikey.DefaultName holds the default value on creation for the name field. teamapikey.DefaultName = teamapikeyDescName.Default.(string) userFields := schema.User{}.Fields() diff --git a/packages/shared/pkg/models/team/team.go b/packages/shared/pkg/models/team/team.go index 58cd01f74..3721ca784 100644 --- a/packages/shared/pkg/models/team/team.go +++ b/packages/shared/pkg/models/team/team.go @@ -38,8 +38,6 @@ const ( EdgeEnvs = "envs" // EdgeUsersTeams holds the string denoting the users_teams edge name in mutations. EdgeUsersTeams = "users_teams" - // TeamAPIKeyFieldID holds the string denoting the ID field of the TeamAPIKey. - TeamAPIKeyFieldID = "api_key" // Table holds the table name of the team in the database. Table = "teams" // UsersTable is the table that holds the users relation/edge. The primary key declared below. @@ -227,7 +225,7 @@ func newUsersStep() *sqlgraph.Step { func newTeamAPIKeysStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(TeamAPIKeysInverseTable, TeamAPIKeyFieldID), + sqlgraph.To(TeamAPIKeysInverseTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, TeamAPIKeysTable, TeamAPIKeysColumn), ) } diff --git a/packages/shared/pkg/models/team_create.go b/packages/shared/pkg/models/team_create.go index fd60b2f71..48de2b0b1 100644 --- a/packages/shared/pkg/models/team_create.go +++ b/packages/shared/pkg/models/team_create.go @@ -109,14 +109,14 @@ func (tc *TeamCreate) AddUsers(u ...*User) *TeamCreate { } // AddTeamAPIKeyIDs adds the "team_api_keys" edge to the TeamAPIKey entity by IDs. -func (tc *TeamCreate) AddTeamAPIKeyIDs(ids ...string) *TeamCreate { +func (tc *TeamCreate) AddTeamAPIKeyIDs(ids ...uuid.UUID) *TeamCreate { tc.mutation.AddTeamAPIKeyIDs(ids...) return tc } // AddTeamAPIKeys adds the "team_api_keys" edges to the TeamAPIKey entity. func (tc *TeamCreate) AddTeamAPIKeys(t ...*TeamAPIKey) *TeamCreate { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -323,7 +323,7 @@ func (tc *TeamCreate) createSpec() (*Team, *sqlgraph.CreateSpec) { Columns: []string{team.TeamAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = tc.schemaConfig.TeamAPIKey diff --git a/packages/shared/pkg/models/team_update.go b/packages/shared/pkg/models/team_update.go index cf11ff877..0803fee6e 100644 --- a/packages/shared/pkg/models/team_update.go +++ b/packages/shared/pkg/models/team_update.go @@ -141,14 +141,14 @@ func (tu *TeamUpdate) AddUsers(u ...*User) *TeamUpdate { } // AddTeamAPIKeyIDs adds the "team_api_keys" edge to the TeamAPIKey entity by IDs. -func (tu *TeamUpdate) AddTeamAPIKeyIDs(ids ...string) *TeamUpdate { +func (tu *TeamUpdate) AddTeamAPIKeyIDs(ids ...uuid.UUID) *TeamUpdate { tu.mutation.AddTeamAPIKeyIDs(ids...) return tu } // AddTeamAPIKeys adds the "team_api_keys" edges to the TeamAPIKey entity. func (tu *TeamUpdate) AddTeamAPIKeys(t ...*TeamAPIKey) *TeamUpdate { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -229,14 +229,14 @@ func (tu *TeamUpdate) ClearTeamAPIKeys() *TeamUpdate { } // RemoveTeamAPIKeyIDs removes the "team_api_keys" edge to TeamAPIKey entities by IDs. -func (tu *TeamUpdate) RemoveTeamAPIKeyIDs(ids ...string) *TeamUpdate { +func (tu *TeamUpdate) RemoveTeamAPIKeyIDs(ids ...uuid.UUID) *TeamUpdate { tu.mutation.RemoveTeamAPIKeyIDs(ids...) return tu } // RemoveTeamAPIKeys removes "team_api_keys" edges to TeamAPIKey entities. func (tu *TeamUpdate) RemoveTeamAPIKeys(t ...*TeamAPIKey) *TeamUpdate { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -435,7 +435,7 @@ func (tu *TeamUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{team.TeamAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = tu.schemaConfig.TeamAPIKey @@ -449,7 +449,7 @@ func (tu *TeamUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{team.TeamAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = tu.schemaConfig.TeamAPIKey @@ -466,7 +466,7 @@ func (tu *TeamUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{team.TeamAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = tu.schemaConfig.TeamAPIKey @@ -732,14 +732,14 @@ func (tuo *TeamUpdateOne) AddUsers(u ...*User) *TeamUpdateOne { } // AddTeamAPIKeyIDs adds the "team_api_keys" edge to the TeamAPIKey entity by IDs. -func (tuo *TeamUpdateOne) AddTeamAPIKeyIDs(ids ...string) *TeamUpdateOne { +func (tuo *TeamUpdateOne) AddTeamAPIKeyIDs(ids ...uuid.UUID) *TeamUpdateOne { tuo.mutation.AddTeamAPIKeyIDs(ids...) return tuo } // AddTeamAPIKeys adds the "team_api_keys" edges to the TeamAPIKey entity. func (tuo *TeamUpdateOne) AddTeamAPIKeys(t ...*TeamAPIKey) *TeamUpdateOne { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -820,14 +820,14 @@ func (tuo *TeamUpdateOne) ClearTeamAPIKeys() *TeamUpdateOne { } // RemoveTeamAPIKeyIDs removes the "team_api_keys" edge to TeamAPIKey entities by IDs. -func (tuo *TeamUpdateOne) RemoveTeamAPIKeyIDs(ids ...string) *TeamUpdateOne { +func (tuo *TeamUpdateOne) RemoveTeamAPIKeyIDs(ids ...uuid.UUID) *TeamUpdateOne { tuo.mutation.RemoveTeamAPIKeyIDs(ids...) return tuo } // RemoveTeamAPIKeys removes "team_api_keys" edges to TeamAPIKey entities. func (tuo *TeamUpdateOne) RemoveTeamAPIKeys(t ...*TeamAPIKey) *TeamUpdateOne { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -1056,7 +1056,7 @@ func (tuo *TeamUpdateOne) sqlSave(ctx context.Context) (_node *Team, err error) Columns: []string{team.TeamAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = tuo.schemaConfig.TeamAPIKey @@ -1070,7 +1070,7 @@ func (tuo *TeamUpdateOne) sqlSave(ctx context.Context) (_node *Team, err error) Columns: []string{team.TeamAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = tuo.schemaConfig.TeamAPIKey @@ -1087,7 +1087,7 @@ func (tuo *TeamUpdateOne) sqlSave(ctx context.Context) (_node *Team, err error) Columns: []string{team.TeamAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = tuo.schemaConfig.TeamAPIKey diff --git a/packages/shared/pkg/models/teamapikey.go b/packages/shared/pkg/models/teamapikey.go index daf425c77..6539436f9 100644 --- a/packages/shared/pkg/models/teamapikey.go +++ b/packages/shared/pkg/models/teamapikey.go @@ -19,7 +19,9 @@ import ( type TeamAPIKey struct { config `json:"-"` // ID of the ent. - ID string `json:"id,omitempty"` + ID uuid.UUID `json:"id,omitempty"` + // APIKey holds the value of the "api_key" field. + APIKey string `json:"-"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // UpdatedAt holds the value of the "updated_at" field. @@ -82,11 +84,11 @@ func (*TeamAPIKey) scanValues(columns []string) ([]any, error) { switch columns[i] { case teamapikey.FieldCreatedBy: values[i] = &sql.NullScanner{S: new(uuid.UUID)} - case teamapikey.FieldID, teamapikey.FieldName: + case teamapikey.FieldAPIKey, teamapikey.FieldName: values[i] = new(sql.NullString) case teamapikey.FieldCreatedAt, teamapikey.FieldUpdatedAt, teamapikey.FieldLastUsed: values[i] = new(sql.NullTime) - case teamapikey.FieldTeamID: + case teamapikey.FieldID, teamapikey.FieldTeamID: values[i] = new(uuid.UUID) default: values[i] = new(sql.UnknownType) @@ -104,10 +106,16 @@ func (tak *TeamAPIKey) assignValues(columns []string, values []any) error { for i := range columns { switch columns[i] { case teamapikey.FieldID: - if value, ok := values[i].(*sql.NullString); !ok { + if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + tak.ID = *value + } + case teamapikey.FieldAPIKey: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field api_key", values[i]) } else if value.Valid { - tak.ID = value.String + tak.APIKey = value.String } case teamapikey.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { @@ -194,6 +202,8 @@ func (tak *TeamAPIKey) String() string { var builder strings.Builder builder.WriteString("TeamAPIKey(") builder.WriteString(fmt.Sprintf("id=%v, ", tak.ID)) + builder.WriteString("api_key=") + builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(tak.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") diff --git a/packages/shared/pkg/models/teamapikey/teamapikey.go b/packages/shared/pkg/models/teamapikey/teamapikey.go index ca9db9556..ec803ed7b 100644 --- a/packages/shared/pkg/models/teamapikey/teamapikey.go +++ b/packages/shared/pkg/models/teamapikey/teamapikey.go @@ -13,7 +13,9 @@ const ( // Label holds the string label denoting the teamapikey type in the database. Label = "team_api_key" // FieldID holds the string denoting the id field in the database. - FieldID = "api_key" + FieldID = "id" + // FieldAPIKey holds the string denoting the api_key field in the database. + FieldAPIKey = "api_key" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" // FieldUpdatedAt holds the string denoting the updated_at field in the database. @@ -30,10 +32,6 @@ const ( EdgeTeam = "team" // EdgeCreator holds the string denoting the creator edge name in mutations. EdgeCreator = "creator" - // TeamFieldID holds the string denoting the ID field of the Team. - TeamFieldID = "id" - // UserFieldID holds the string denoting the ID field of the User. - UserFieldID = "id" // Table holds the table name of the teamapikey in the database. Table = "team_api_keys" // TeamTable is the table that holds the team relation/edge. @@ -55,6 +53,7 @@ const ( // Columns holds all SQL columns for teamapikey fields. var Columns = []string{ FieldID, + FieldAPIKey, FieldCreatedAt, FieldUpdatedAt, FieldTeamID, @@ -88,6 +87,11 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } +// ByAPIKey orders the results by the api_key field. +func ByAPIKey(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAPIKey, opts...).ToFunc() +} + // ByCreatedAt orders the results by the created_at field. func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() @@ -134,14 +138,14 @@ func ByCreatorField(field string, opts ...sql.OrderTermOption) OrderOption { func newTeamStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(TeamInverseTable, TeamFieldID), + sqlgraph.To(TeamInverseTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, TeamTable, TeamColumn), ) } func newCreatorStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(CreatorInverseTable, UserFieldID), + sqlgraph.To(CreatorInverseTable, FieldID), sqlgraph.Edge(sqlgraph.M2O, true, CreatorTable, CreatorColumn), ) } diff --git a/packages/shared/pkg/models/teamapikey/where.go b/packages/shared/pkg/models/teamapikey/where.go index c26da5ba2..0ebd7acfd 100644 --- a/packages/shared/pkg/models/teamapikey/where.go +++ b/packages/shared/pkg/models/teamapikey/where.go @@ -13,58 +13,53 @@ import ( ) // ID filters vertices based on their ID field. -func ID(id string) predicate.TeamAPIKey { +func ID(id uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id string) predicate.TeamAPIKey { +func IDEQ(id uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id string) predicate.TeamAPIKey { +func IDNEQ(id uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...string) predicate.TeamAPIKey { +func IDIn(ids ...uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...string) predicate.TeamAPIKey { +func IDNotIn(ids ...uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. -func IDGT(id string) predicate.TeamAPIKey { +func IDGT(id uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id string) predicate.TeamAPIKey { +func IDGTE(id uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. -func IDLT(id string) predicate.TeamAPIKey { +func IDLT(id uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id string) predicate.TeamAPIKey { +func IDLTE(id uuid.UUID) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldLTE(FieldID, id)) } -// IDEqualFold applies the EqualFold predicate on the ID field. -func IDEqualFold(id string) predicate.TeamAPIKey { - return predicate.TeamAPIKey(sql.FieldEqualFold(FieldID, id)) -} - -// IDContainsFold applies the ContainsFold predicate on the ID field. -func IDContainsFold(id string) predicate.TeamAPIKey { - return predicate.TeamAPIKey(sql.FieldContainsFold(FieldID, id)) +// APIKey applies equality check predicate on the "api_key" field. It's identical to APIKeyEQ. +func APIKey(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldEQ(FieldAPIKey, v)) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. @@ -97,6 +92,71 @@ func LastUsed(v time.Time) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldEQ(FieldLastUsed, v)) } +// APIKeyEQ applies the EQ predicate on the "api_key" field. +func APIKeyEQ(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldEQ(FieldAPIKey, v)) +} + +// APIKeyNEQ applies the NEQ predicate on the "api_key" field. +func APIKeyNEQ(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldNEQ(FieldAPIKey, v)) +} + +// APIKeyIn applies the In predicate on the "api_key" field. +func APIKeyIn(vs ...string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldIn(FieldAPIKey, vs...)) +} + +// APIKeyNotIn applies the NotIn predicate on the "api_key" field. +func APIKeyNotIn(vs ...string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldNotIn(FieldAPIKey, vs...)) +} + +// APIKeyGT applies the GT predicate on the "api_key" field. +func APIKeyGT(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldGT(FieldAPIKey, v)) +} + +// APIKeyGTE applies the GTE predicate on the "api_key" field. +func APIKeyGTE(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldGTE(FieldAPIKey, v)) +} + +// APIKeyLT applies the LT predicate on the "api_key" field. +func APIKeyLT(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldLT(FieldAPIKey, v)) +} + +// APIKeyLTE applies the LTE predicate on the "api_key" field. +func APIKeyLTE(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldLTE(FieldAPIKey, v)) +} + +// APIKeyContains applies the Contains predicate on the "api_key" field. +func APIKeyContains(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldContains(FieldAPIKey, v)) +} + +// APIKeyHasPrefix applies the HasPrefix predicate on the "api_key" field. +func APIKeyHasPrefix(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldHasPrefix(FieldAPIKey, v)) +} + +// APIKeyHasSuffix applies the HasSuffix predicate on the "api_key" field. +func APIKeyHasSuffix(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldHasSuffix(FieldAPIKey, v)) +} + +// APIKeyEqualFold applies the EqualFold predicate on the "api_key" field. +func APIKeyEqualFold(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldEqualFold(FieldAPIKey, v)) +} + +// APIKeyContainsFold applies the ContainsFold predicate on the "api_key" field. +func APIKeyContainsFold(v string) predicate.TeamAPIKey { + return predicate.TeamAPIKey(sql.FieldContainsFold(FieldAPIKey, v)) +} + // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.TeamAPIKey { return predicate.TeamAPIKey(sql.FieldEQ(FieldCreatedAt, v)) diff --git a/packages/shared/pkg/models/teamapikey_create.go b/packages/shared/pkg/models/teamapikey_create.go index a9f256115..8815edba7 100644 --- a/packages/shared/pkg/models/teamapikey_create.go +++ b/packages/shared/pkg/models/teamapikey_create.go @@ -26,6 +26,12 @@ type TeamAPIKeyCreate struct { conflict []sql.ConflictOption } +// SetAPIKey sets the "api_key" field. +func (takc *TeamAPIKeyCreate) SetAPIKey(s string) *TeamAPIKeyCreate { + takc.mutation.SetAPIKey(s) + return takc +} + // SetCreatedAt sets the "created_at" field. func (takc *TeamAPIKeyCreate) SetCreatedAt(t time.Time) *TeamAPIKeyCreate { takc.mutation.SetCreatedAt(t) @@ -103,8 +109,8 @@ func (takc *TeamAPIKeyCreate) SetNillableLastUsed(t *time.Time) *TeamAPIKeyCreat } // SetID sets the "id" field. -func (takc *TeamAPIKeyCreate) SetID(s string) *TeamAPIKeyCreate { - takc.mutation.SetID(s) +func (takc *TeamAPIKeyCreate) SetID(u uuid.UUID) *TeamAPIKeyCreate { + takc.mutation.SetID(u) return takc } @@ -179,6 +185,9 @@ func (takc *TeamAPIKeyCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (takc *TeamAPIKeyCreate) check() error { + if _, ok := takc.mutation.APIKey(); !ok { + return &ValidationError{Name: "api_key", err: errors.New(`models: missing required field "TeamAPIKey.api_key"`)} + } if _, ok := takc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "TeamAPIKey.created_at"`)} } @@ -206,10 +215,10 @@ func (takc *TeamAPIKeyCreate) sqlSave(ctx context.Context) (*TeamAPIKey, error) return nil, err } if _spec.ID.Value != nil { - if id, ok := _spec.ID.Value.(string); ok { - _node.ID = id - } else { - return nil, fmt.Errorf("unexpected TeamAPIKey.ID type: %T", _spec.ID.Value) + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err } } takc.mutation.id = &_node.ID @@ -220,13 +229,17 @@ func (takc *TeamAPIKeyCreate) sqlSave(ctx context.Context) (*TeamAPIKey, error) func (takc *TeamAPIKeyCreate) createSpec() (*TeamAPIKey, *sqlgraph.CreateSpec) { var ( _node = &TeamAPIKey{config: takc.config} - _spec = sqlgraph.NewCreateSpec(teamapikey.Table, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString)) + _spec = sqlgraph.NewCreateSpec(teamapikey.Table, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID)) ) _spec.Schema = takc.schemaConfig.TeamAPIKey _spec.OnConflict = takc.conflict if id, ok := takc.mutation.ID(); ok { _node.ID = id - _spec.ID.Value = id + _spec.ID.Value = &id + } + if value, ok := takc.mutation.APIKey(); ok { + _spec.SetField(teamapikey.FieldAPIKey, field.TypeString, value) + _node.APIKey = value } if value, ok := takc.mutation.CreatedAt(); ok { _spec.SetField(teamapikey.FieldCreatedAt, field.TypeTime, value) @@ -287,7 +300,7 @@ func (takc *TeamAPIKeyCreate) createSpec() (*TeamAPIKey, *sqlgraph.CreateSpec) { // of the `INSERT` statement. For example: // // client.TeamAPIKey.Create(). -// SetCreatedAt(v). +// SetAPIKey(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. @@ -296,7 +309,7 @@ func (takc *TeamAPIKeyCreate) createSpec() (*TeamAPIKey, *sqlgraph.CreateSpec) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.TeamAPIKeyUpsert) { -// SetCreatedAt(v+v). +// SetAPIKey(v+v). // }). // Exec(ctx) func (takc *TeamAPIKeyCreate) OnConflict(opts ...sql.ConflictOption) *TeamAPIKeyUpsertOne { @@ -332,6 +345,18 @@ type ( } ) +// SetAPIKey sets the "api_key" field. +func (u *TeamAPIKeyUpsert) SetAPIKey(v string) *TeamAPIKeyUpsert { + u.Set(teamapikey.FieldAPIKey, v) + return u +} + +// UpdateAPIKey sets the "api_key" field to the value that was provided on create. +func (u *TeamAPIKeyUpsert) UpdateAPIKey() *TeamAPIKeyUpsert { + u.SetExcluded(teamapikey.FieldAPIKey) + return u +} + // SetUpdatedAt sets the "updated_at" field. func (u *TeamAPIKeyUpsert) SetUpdatedAt(v time.Time) *TeamAPIKeyUpsert { u.Set(teamapikey.FieldUpdatedAt, v) @@ -461,6 +486,20 @@ func (u *TeamAPIKeyUpsertOne) Update(set func(*TeamAPIKeyUpsert)) *TeamAPIKeyUps return u } +// SetAPIKey sets the "api_key" field. +func (u *TeamAPIKeyUpsertOne) SetAPIKey(v string) *TeamAPIKeyUpsertOne { + return u.Update(func(s *TeamAPIKeyUpsert) { + s.SetAPIKey(v) + }) +} + +// UpdateAPIKey sets the "api_key" field to the value that was provided on create. +func (u *TeamAPIKeyUpsertOne) UpdateAPIKey() *TeamAPIKeyUpsertOne { + return u.Update(func(s *TeamAPIKeyUpsert) { + s.UpdateAPIKey() + }) +} + // SetUpdatedAt sets the "updated_at" field. func (u *TeamAPIKeyUpsertOne) SetUpdatedAt(v time.Time) *TeamAPIKeyUpsertOne { return u.Update(func(s *TeamAPIKeyUpsert) { @@ -568,7 +607,7 @@ func (u *TeamAPIKeyUpsertOne) ExecX(ctx context.Context) { } // Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *TeamAPIKeyUpsertOne) ID(ctx context.Context) (id string, err error) { +func (u *TeamAPIKeyUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) { if u.create.driver.Dialect() == dialect.MySQL { // In case of "ON CONFLICT", there is no way to get back non-numeric ID // fields from the database since MySQL does not support the RETURNING clause. @@ -582,7 +621,7 @@ func (u *TeamAPIKeyUpsertOne) ID(ctx context.Context) (id string, err error) { } // IDX is like ID, but panics if an error occurs. -func (u *TeamAPIKeyUpsertOne) IDX(ctx context.Context) string { +func (u *TeamAPIKeyUpsertOne) IDX(ctx context.Context) uuid.UUID { id, err := u.ID(ctx) if err != nil { panic(err) @@ -688,7 +727,7 @@ func (takcb *TeamAPIKeyCreateBulk) ExecX(ctx context.Context) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.TeamAPIKeyUpsert) { -// SetCreatedAt(v+v). +// SetAPIKey(v+v). // }). // Exec(ctx) func (takcb *TeamAPIKeyCreateBulk) OnConflict(opts ...sql.ConflictOption) *TeamAPIKeyUpsertBulk { @@ -770,6 +809,20 @@ func (u *TeamAPIKeyUpsertBulk) Update(set func(*TeamAPIKeyUpsert)) *TeamAPIKeyUp return u } +// SetAPIKey sets the "api_key" field. +func (u *TeamAPIKeyUpsertBulk) SetAPIKey(v string) *TeamAPIKeyUpsertBulk { + return u.Update(func(s *TeamAPIKeyUpsert) { + s.SetAPIKey(v) + }) +} + +// UpdateAPIKey sets the "api_key" field to the value that was provided on create. +func (u *TeamAPIKeyUpsertBulk) UpdateAPIKey() *TeamAPIKeyUpsertBulk { + return u.Update(func(s *TeamAPIKeyUpsert) { + s.UpdateAPIKey() + }) +} + // SetUpdatedAt sets the "updated_at" field. func (u *TeamAPIKeyUpsertBulk) SetUpdatedAt(v time.Time) *TeamAPIKeyUpsertBulk { return u.Update(func(s *TeamAPIKeyUpsert) { diff --git a/packages/shared/pkg/models/teamapikey_delete.go b/packages/shared/pkg/models/teamapikey_delete.go index 2b5d931ef..ec1595093 100644 --- a/packages/shared/pkg/models/teamapikey_delete.go +++ b/packages/shared/pkg/models/teamapikey_delete.go @@ -41,7 +41,7 @@ func (takd *TeamAPIKeyDelete) ExecX(ctx context.Context) int { } func (takd *TeamAPIKeyDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(teamapikey.Table, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString)) + _spec := sqlgraph.NewDeleteSpec(teamapikey.Table, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID)) _spec.Node.Schema = takd.schemaConfig.TeamAPIKey ctx = internal.NewSchemaConfigContext(ctx, takd.schemaConfig) if ps := takd.mutation.predicates; len(ps) > 0 { diff --git a/packages/shared/pkg/models/teamapikey_query.go b/packages/shared/pkg/models/teamapikey_query.go index 3ecfcae11..e1c3901f9 100644 --- a/packages/shared/pkg/models/teamapikey_query.go +++ b/packages/shared/pkg/models/teamapikey_query.go @@ -138,8 +138,8 @@ func (takq *TeamAPIKeyQuery) FirstX(ctx context.Context) *TeamAPIKey { // FirstID returns the first TeamAPIKey ID from the query. // Returns a *NotFoundError when no TeamAPIKey ID was found. -func (takq *TeamAPIKeyQuery) FirstID(ctx context.Context) (id string, err error) { - var ids []string +func (takq *TeamAPIKeyQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID if ids, err = takq.Limit(1).IDs(setContextOp(ctx, takq.ctx, "FirstID")); err != nil { return } @@ -151,7 +151,7 @@ func (takq *TeamAPIKeyQuery) FirstID(ctx context.Context) (id string, err error) } // FirstIDX is like FirstID, but panics if an error occurs. -func (takq *TeamAPIKeyQuery) FirstIDX(ctx context.Context) string { +func (takq *TeamAPIKeyQuery) FirstIDX(ctx context.Context) uuid.UUID { id, err := takq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -189,8 +189,8 @@ func (takq *TeamAPIKeyQuery) OnlyX(ctx context.Context) *TeamAPIKey { // OnlyID is like Only, but returns the only TeamAPIKey ID in the query. // Returns a *NotSingularError when more than one TeamAPIKey ID is found. // Returns a *NotFoundError when no entities are found. -func (takq *TeamAPIKeyQuery) OnlyID(ctx context.Context) (id string, err error) { - var ids []string +func (takq *TeamAPIKeyQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID if ids, err = takq.Limit(2).IDs(setContextOp(ctx, takq.ctx, "OnlyID")); err != nil { return } @@ -206,7 +206,7 @@ func (takq *TeamAPIKeyQuery) OnlyID(ctx context.Context) (id string, err error) } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (takq *TeamAPIKeyQuery) OnlyIDX(ctx context.Context) string { +func (takq *TeamAPIKeyQuery) OnlyIDX(ctx context.Context) uuid.UUID { id, err := takq.OnlyID(ctx) if err != nil { panic(err) @@ -234,7 +234,7 @@ func (takq *TeamAPIKeyQuery) AllX(ctx context.Context) []*TeamAPIKey { } // IDs executes the query and returns a list of TeamAPIKey IDs. -func (takq *TeamAPIKeyQuery) IDs(ctx context.Context) (ids []string, err error) { +func (takq *TeamAPIKeyQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if takq.ctx.Unique == nil && takq.path != nil { takq.Unique(true) } @@ -246,7 +246,7 @@ func (takq *TeamAPIKeyQuery) IDs(ctx context.Context) (ids []string, err error) } // IDsX is like IDs, but panics if an error occurs. -func (takq *TeamAPIKeyQuery) IDsX(ctx context.Context) []string { +func (takq *TeamAPIKeyQuery) IDsX(ctx context.Context) []uuid.UUID { ids, err := takq.IDs(ctx) if err != nil { panic(err) @@ -342,12 +342,12 @@ func (takq *TeamAPIKeyQuery) WithCreator(opts ...func(*UserQuery)) *TeamAPIKeyQu // Example: // // var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` +// APIKey string `json:"api_key,omitempty"` // Count int `json:"count,omitempty"` // } // // client.TeamAPIKey.Query(). -// GroupBy(teamapikey.FieldCreatedAt). +// GroupBy(teamapikey.FieldAPIKey). // Aggregate(models.Count()). // Scan(ctx, &v) func (takq *TeamAPIKeyQuery) GroupBy(field string, fields ...string) *TeamAPIKeyGroupBy { @@ -365,11 +365,11 @@ func (takq *TeamAPIKeyQuery) GroupBy(field string, fields ...string) *TeamAPIKey // Example: // // var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` +// APIKey string `json:"api_key,omitempty"` // } // // client.TeamAPIKey.Query(). -// Select(teamapikey.FieldCreatedAt). +// Select(teamapikey.FieldAPIKey). // Scan(ctx, &v) func (takq *TeamAPIKeyQuery) Select(fields ...string) *TeamAPIKeySelect { takq.ctx.Fields = append(takq.ctx.Fields, fields...) @@ -534,7 +534,7 @@ func (takq *TeamAPIKeyQuery) sqlCount(ctx context.Context) (int, error) { } func (takq *TeamAPIKeyQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(teamapikey.Table, teamapikey.Columns, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString)) + _spec := sqlgraph.NewQuerySpec(teamapikey.Table, teamapikey.Columns, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID)) _spec.From = takq.sql if unique := takq.ctx.Unique; unique != nil { _spec.Unique = *unique diff --git a/packages/shared/pkg/models/teamapikey_update.go b/packages/shared/pkg/models/teamapikey_update.go index 6135fa2c4..14477837d 100644 --- a/packages/shared/pkg/models/teamapikey_update.go +++ b/packages/shared/pkg/models/teamapikey_update.go @@ -33,6 +33,20 @@ func (taku *TeamAPIKeyUpdate) Where(ps ...predicate.TeamAPIKey) *TeamAPIKeyUpdat return taku } +// SetAPIKey sets the "api_key" field. +func (taku *TeamAPIKeyUpdate) SetAPIKey(s string) *TeamAPIKeyUpdate { + taku.mutation.SetAPIKey(s) + return taku +} + +// SetNillableAPIKey sets the "api_key" field if the given value is not nil. +func (taku *TeamAPIKeyUpdate) SetNillableAPIKey(s *string) *TeamAPIKeyUpdate { + if s != nil { + taku.SetAPIKey(*s) + } + return taku +} + // SetUpdatedAt sets the "updated_at" field. func (taku *TeamAPIKeyUpdate) SetUpdatedAt(t time.Time) *TeamAPIKeyUpdate { taku.mutation.SetUpdatedAt(t) @@ -207,7 +221,7 @@ func (taku *TeamAPIKeyUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := taku.check(); err != nil { return n, err } - _spec := sqlgraph.NewUpdateSpec(teamapikey.Table, teamapikey.Columns, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString)) + _spec := sqlgraph.NewUpdateSpec(teamapikey.Table, teamapikey.Columns, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID)) if ps := taku.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -215,6 +229,9 @@ func (taku *TeamAPIKeyUpdate) sqlSave(ctx context.Context) (n int, err error) { } } } + if value, ok := taku.mutation.APIKey(); ok { + _spec.SetField(teamapikey.FieldAPIKey, field.TypeString, value) + } if value, ok := taku.mutation.UpdatedAt(); ok { _spec.SetField(teamapikey.FieldUpdatedAt, field.TypeTime, value) } @@ -316,6 +333,20 @@ type TeamAPIKeyUpdateOne struct { modifiers []func(*sql.UpdateBuilder) } +// SetAPIKey sets the "api_key" field. +func (takuo *TeamAPIKeyUpdateOne) SetAPIKey(s string) *TeamAPIKeyUpdateOne { + takuo.mutation.SetAPIKey(s) + return takuo +} + +// SetNillableAPIKey sets the "api_key" field if the given value is not nil. +func (takuo *TeamAPIKeyUpdateOne) SetNillableAPIKey(s *string) *TeamAPIKeyUpdateOne { + if s != nil { + takuo.SetAPIKey(*s) + } + return takuo +} + // SetUpdatedAt sets the "updated_at" field. func (takuo *TeamAPIKeyUpdateOne) SetUpdatedAt(t time.Time) *TeamAPIKeyUpdateOne { takuo.mutation.SetUpdatedAt(t) @@ -503,7 +534,7 @@ func (takuo *TeamAPIKeyUpdateOne) sqlSave(ctx context.Context) (_node *TeamAPIKe if err := takuo.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(teamapikey.Table, teamapikey.Columns, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString)) + _spec := sqlgraph.NewUpdateSpec(teamapikey.Table, teamapikey.Columns, sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID)) id, ok := takuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "TeamAPIKey.id" for update`)} @@ -528,6 +559,9 @@ func (takuo *TeamAPIKeyUpdateOne) sqlSave(ctx context.Context) (_node *TeamAPIKe } } } + if value, ok := takuo.mutation.APIKey(); ok { + _spec.SetField(teamapikey.FieldAPIKey, field.TypeString, value) + } if value, ok := takuo.mutation.UpdatedAt(); ok { _spec.SetField(teamapikey.FieldUpdatedAt, field.TypeTime, value) } diff --git a/packages/shared/pkg/models/user/user.go b/packages/shared/pkg/models/user/user.go index 40d035f08..c1069dc8f 100644 --- a/packages/shared/pkg/models/user/user.go +++ b/packages/shared/pkg/models/user/user.go @@ -24,8 +24,6 @@ const ( EdgeUsersTeams = "users_teams" // AccessTokenFieldID holds the string denoting the ID field of the AccessToken. AccessTokenFieldID = "access_token" - // TeamAPIKeyFieldID holds the string denoting the ID field of the TeamAPIKey. - TeamAPIKeyFieldID = "api_key" // Table holds the table name of the user in the database. Table = "users" // TeamsTable is the table that holds the teams relation/edge. The primary key declared below. @@ -168,7 +166,7 @@ func newAccessTokensStep() *sqlgraph.Step { func newCreatedAPIKeysStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(CreatedAPIKeysInverseTable, TeamAPIKeyFieldID), + sqlgraph.To(CreatedAPIKeysInverseTable, FieldID), sqlgraph.Edge(sqlgraph.O2M, false, CreatedAPIKeysTable, CreatedAPIKeysColumn), ) } diff --git a/packages/shared/pkg/models/user_create.go b/packages/shared/pkg/models/user_create.go index 3043b63ab..998e6d5c4 100644 --- a/packages/shared/pkg/models/user_create.go +++ b/packages/shared/pkg/models/user_create.go @@ -70,14 +70,14 @@ func (uc *UserCreate) AddAccessTokens(a ...*AccessToken) *UserCreate { } // AddCreatedAPIKeyIDs adds the "created_api_keys" edge to the TeamAPIKey entity by IDs. -func (uc *UserCreate) AddCreatedAPIKeyIDs(ids ...string) *UserCreate { +func (uc *UserCreate) AddCreatedAPIKeyIDs(ids ...uuid.UUID) *UserCreate { uc.mutation.AddCreatedAPIKeyIDs(ids...) return uc } // AddCreatedAPIKeys adds the "created_api_keys" edges to the TeamAPIKey entity. func (uc *UserCreate) AddCreatedAPIKeys(t ...*TeamAPIKey) *UserCreate { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -228,7 +228,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.CreatedAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = uc.schemaConfig.TeamAPIKey diff --git a/packages/shared/pkg/models/user_update.go b/packages/shared/pkg/models/user_update.go index 89f8a9630..04f9d6452 100644 --- a/packages/shared/pkg/models/user_update.go +++ b/packages/shared/pkg/models/user_update.go @@ -79,14 +79,14 @@ func (uu *UserUpdate) AddAccessTokens(a ...*AccessToken) *UserUpdate { } // AddCreatedAPIKeyIDs adds the "created_api_keys" edge to the TeamAPIKey entity by IDs. -func (uu *UserUpdate) AddCreatedAPIKeyIDs(ids ...string) *UserUpdate { +func (uu *UserUpdate) AddCreatedAPIKeyIDs(ids ...uuid.UUID) *UserUpdate { uu.mutation.AddCreatedAPIKeyIDs(ids...) return uu } // AddCreatedAPIKeys adds the "created_api_keys" edges to the TeamAPIKey entity. func (uu *UserUpdate) AddCreatedAPIKeys(t ...*TeamAPIKey) *UserUpdate { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -162,14 +162,14 @@ func (uu *UserUpdate) ClearCreatedAPIKeys() *UserUpdate { } // RemoveCreatedAPIKeyIDs removes the "created_api_keys" edge to TeamAPIKey entities by IDs. -func (uu *UserUpdate) RemoveCreatedAPIKeyIDs(ids ...string) *UserUpdate { +func (uu *UserUpdate) RemoveCreatedAPIKeyIDs(ids ...uuid.UUID) *UserUpdate { uu.mutation.RemoveCreatedAPIKeyIDs(ids...) return uu } // RemoveCreatedAPIKeys removes "created_api_keys" edges to TeamAPIKey entities. func (uu *UserUpdate) RemoveCreatedAPIKeys(t ...*TeamAPIKey) *UserUpdate { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -371,7 +371,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CreatedAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = uu.schemaConfig.TeamAPIKey @@ -385,7 +385,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CreatedAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = uu.schemaConfig.TeamAPIKey @@ -402,7 +402,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CreatedAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = uu.schemaConfig.TeamAPIKey @@ -528,14 +528,14 @@ func (uuo *UserUpdateOne) AddAccessTokens(a ...*AccessToken) *UserUpdateOne { } // AddCreatedAPIKeyIDs adds the "created_api_keys" edge to the TeamAPIKey entity by IDs. -func (uuo *UserUpdateOne) AddCreatedAPIKeyIDs(ids ...string) *UserUpdateOne { +func (uuo *UserUpdateOne) AddCreatedAPIKeyIDs(ids ...uuid.UUID) *UserUpdateOne { uuo.mutation.AddCreatedAPIKeyIDs(ids...) return uuo } // AddCreatedAPIKeys adds the "created_api_keys" edges to the TeamAPIKey entity. func (uuo *UserUpdateOne) AddCreatedAPIKeys(t ...*TeamAPIKey) *UserUpdateOne { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -611,14 +611,14 @@ func (uuo *UserUpdateOne) ClearCreatedAPIKeys() *UserUpdateOne { } // RemoveCreatedAPIKeyIDs removes the "created_api_keys" edge to TeamAPIKey entities by IDs. -func (uuo *UserUpdateOne) RemoveCreatedAPIKeyIDs(ids ...string) *UserUpdateOne { +func (uuo *UserUpdateOne) RemoveCreatedAPIKeyIDs(ids ...uuid.UUID) *UserUpdateOne { uuo.mutation.RemoveCreatedAPIKeyIDs(ids...) return uuo } // RemoveCreatedAPIKeys removes "created_api_keys" edges to TeamAPIKey entities. func (uuo *UserUpdateOne) RemoveCreatedAPIKeys(t ...*TeamAPIKey) *UserUpdateOne { - ids := make([]string, len(t)) + ids := make([]uuid.UUID, len(t)) for i := range t { ids[i] = t[i].ID } @@ -850,7 +850,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CreatedAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = uuo.schemaConfig.TeamAPIKey @@ -864,7 +864,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CreatedAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = uuo.schemaConfig.TeamAPIKey @@ -881,7 +881,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CreatedAPIKeysColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeString), + IDSpec: sqlgraph.NewFieldSpec(teamapikey.FieldID, field.TypeUUID), }, } edge.Schema = uuo.schemaConfig.TeamAPIKey