From a10dbe08712c9d26880120cd143dcb01d6cf3c62 Mon Sep 17 00:00:00 2001 From: noah Date: Sat, 1 Jan 2022 21:06:15 +0900 Subject: [PATCH] Remove callback table --- go.mod | 4 + go.sum | 3 + internal/interactor/interface.go | 3 - internal/interactor/mock/pkg.go | 30 - internal/pkg/store/callback.go | 26 - model/ent/callback.go | 173 ----- model/ent/callback/callback.go | 92 --- model/ent/callback/where.go | 541 ---------------- model/ent/callback_create.go | 357 ----------- model/ent/callback_delete.go | 111 ---- model/ent/callback_query.go | 1020 ------------------------------ model/ent/callback_update.go | 495 --------------- model/ent/client.go | 131 +--- model/ent/config.go | 1 - model/ent/ent.go | 2 - model/ent/hook/hook.go | 13 - model/ent/migrate/schema.go | 25 - model/ent/mutation.go | 657 +------------------ model/ent/predicate/predicate.go | 3 - model/ent/repo.go | 24 +- model/ent/repo/repo.go | 9 - model/ent/repo/where.go | 28 - model/ent/repo_create.go | 35 - model/ent/repo_query.go | 64 +- model/ent/repo_update.go | 181 ------ model/ent/runtime.go | 17 - model/ent/schema/callback.go | 47 -- model/ent/schema/repo.go | 4 - model/ent/tx.go | 5 +- 29 files changed, 17 insertions(+), 4084 deletions(-) delete mode 100644 internal/pkg/store/callback.go delete mode 100644 model/ent/callback.go delete mode 100644 model/ent/callback/callback.go delete mode 100644 model/ent/callback/where.go delete mode 100644 model/ent/callback_create.go delete mode 100644 model/ent/callback_delete.go delete mode 100644 model/ent/callback_query.go delete mode 100644 model/ent/callback_update.go delete mode 100644 model/ent/schema/callback.go diff --git a/go.mod b/go.mod index 3f3344dd..c0117918 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/go-openapi/inflect v0.19.0 // indirect github.com/go-playground/locales v0.13.0 // indirect github.com/go-playground/universal-translator v0.17.0 // indirect github.com/go-playground/validator/v10 v10.6.1 // indirect @@ -62,9 +63,12 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect + golang.org/x/mod v0.4.2 // indirect golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect golang.org/x/text v0.3.6 // indirect + golang.org/x/tools v0.1.5 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/appengine v1.6.6 // indirect google.golang.org/protobuf v1.26.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 5b43d732..ac773a6f 100644 --- a/go.sum +++ b/go.sum @@ -116,6 +116,7 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= @@ -518,6 +519,7 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -685,6 +687,7 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/interactor/interface.go b/internal/interactor/interface.go index ac7e2b77..76944d13 100644 --- a/internal/interactor/interface.go +++ b/internal/interactor/interface.go @@ -66,9 +66,6 @@ type ( ListAllDeploymentStatistics(ctx context.Context) ([]*ent.DeploymentStatistics, error) ListDeploymentStatisticsGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) - CreateCallback(ctx context.Context, cb *ent.Callback) (*ent.Callback, error) - FindCallbackByHash(ctx context.Context, hash string) (*ent.Callback, error) - SearchReviews(ctx context.Context, u *ent.User) ([]*ent.Review, error) ListReviews(ctx context.Context, d *ent.Deployment) ([]*ent.Review, error) FindReviewOfUser(ctx context.Context, u *ent.User, d *ent.Deployment) (*ent.Review, error) diff --git a/internal/interactor/mock/pkg.go b/internal/interactor/mock/pkg.go index d99d93b2..3e5234b5 100644 --- a/internal/interactor/mock/pkg.go +++ b/internal/interactor/mock/pkg.go @@ -127,21 +127,6 @@ func (mr *MockStoreMockRecorder) CountUsers(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CountUsers", reflect.TypeOf((*MockStore)(nil).CountUsers), arg0) } -// CreateCallback mocks base method. -func (m *MockStore) CreateCallback(ctx context.Context, cb *ent.Callback) (*ent.Callback, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateCallback", ctx, cb) - ret0, _ := ret[0].(*ent.Callback) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CreateCallback indicates an expected call of CreateCallback. -func (mr *MockStoreMockRecorder) CreateCallback(ctx, cb interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateCallback", reflect.TypeOf((*MockStore)(nil).CreateCallback), ctx, cb) -} - // CreateChatUser mocks base method. func (m *MockStore) CreateChatUser(ctx context.Context, cu *ent.ChatUser) (*ent.ChatUser, error) { m.ctrl.T.Helper() @@ -349,21 +334,6 @@ func (mr *MockStoreMockRecorder) DeleteUser(ctx, u interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteUser", reflect.TypeOf((*MockStore)(nil).DeleteUser), ctx, u) } -// FindCallbackByHash mocks base method. -func (m *MockStore) FindCallbackByHash(ctx context.Context, hash string) (*ent.Callback, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FindCallbackByHash", ctx, hash) - ret0, _ := ret[0].(*ent.Callback) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FindCallbackByHash indicates an expected call of FindCallbackByHash. -func (mr *MockStoreMockRecorder) FindCallbackByHash(ctx, hash interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindCallbackByHash", reflect.TypeOf((*MockStore)(nil).FindCallbackByHash), ctx, hash) -} - // FindChatUserByID mocks base method. func (m *MockStore) FindChatUserByID(ctx context.Context, id string) (*ent.ChatUser, error) { m.ctrl.T.Helper() diff --git a/internal/pkg/store/callback.go b/internal/pkg/store/callback.go deleted file mode 100644 index 9edc0a77..00000000 --- a/internal/pkg/store/callback.go +++ /dev/null @@ -1,26 +0,0 @@ -package store - -import ( - "context" - - "github.com/gitploy-io/gitploy/model/ent" - "github.com/gitploy-io/gitploy/model/ent/callback" -) - -func (s *Store) CreateCallback(ctx context.Context, cb *ent.Callback) (*ent.Callback, error) { - return s.c.Callback. - Create(). - SetType(cb.Type). - SetRepoID(cb.RepoID). - Save(ctx) -} - -func (s *Store) FindCallbackByHash(ctx context.Context, hash string) (*ent.Callback, error) { - return s.c.Callback. - Query(). - Where( - callback.HashEQ(hash), - ). - WithRepo(). - First(ctx) -} diff --git a/model/ent/callback.go b/model/ent/callback.go deleted file mode 100644 index 3bd9171a..00000000 --- a/model/ent/callback.go +++ /dev/null @@ -1,173 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent/dialect/sql" - "github.com/gitploy-io/gitploy/model/ent/callback" - "github.com/gitploy-io/gitploy/model/ent/repo" -) - -// Callback is the model entity for the Callback schema. -type Callback struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // Hash holds the value of the "hash" field. - Hash string `json:"-"` - // Type holds the value of the "type" field. - Type callback.Type `json:"type"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at"` - // RepoID holds the value of the "repo_id" field. - RepoID int64 `json:"repo_id"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the CallbackQuery when eager-loading is set. - Edges CallbackEdges `json:"edges"` -} - -// CallbackEdges holds the relations/edges for other nodes in the graph. -type CallbackEdges struct { - // Repo holds the value of the repo edge. - Repo *Repo `json:"repo,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool -} - -// RepoOrErr returns the Repo value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e CallbackEdges) RepoOrErr() (*Repo, error) { - if e.loadedTypes[0] { - if e.Repo == nil { - // The edge repo was loaded in eager-loading, - // but was not found. - return nil, &NotFoundError{label: repo.Label} - } - return e.Repo, nil - } - return nil, &NotLoadedError{edge: "repo"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Callback) scanValues(columns []string) ([]interface{}, error) { - values := make([]interface{}, len(columns)) - for i := range columns { - switch columns[i] { - case callback.FieldID, callback.FieldRepoID: - values[i] = new(sql.NullInt64) - case callback.FieldHash, callback.FieldType: - values[i] = new(sql.NullString) - case callback.FieldCreatedAt, callback.FieldUpdatedAt: - values[i] = new(sql.NullTime) - default: - return nil, fmt.Errorf("unexpected column %q for type Callback", columns[i]) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Callback fields. -func (c *Callback) assignValues(columns []string, values []interface{}) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case callback.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - c.ID = int(value.Int64) - case callback.FieldHash: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field hash", values[i]) - } else if value.Valid { - c.Hash = value.String - } - case callback.FieldType: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field type", values[i]) - } else if value.Valid { - c.Type = callback.Type(value.String) - } - case callback.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - c.CreatedAt = value.Time - } - case callback.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - c.UpdatedAt = value.Time - } - case callback.FieldRepoID: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field repo_id", values[i]) - } else if value.Valid { - c.RepoID = value.Int64 - } - } - } - return nil -} - -// QueryRepo queries the "repo" edge of the Callback entity. -func (c *Callback) QueryRepo() *RepoQuery { - return (&CallbackClient{config: c.config}).QueryRepo(c) -} - -// Update returns a builder for updating this Callback. -// Note that you need to call Callback.Unwrap() before calling this method if this Callback -// was returned from a transaction, and the transaction was committed or rolled back. -func (c *Callback) Update() *CallbackUpdateOne { - return (&CallbackClient{config: c.config}).UpdateOne(c) -} - -// Unwrap unwraps the Callback entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (c *Callback) Unwrap() *Callback { - tx, ok := c.config.driver.(*txDriver) - if !ok { - panic("ent: Callback is not a transactional entity") - } - c.config.driver = tx.drv - return c -} - -// String implements the fmt.Stringer. -func (c *Callback) String() string { - var builder strings.Builder - builder.WriteString("Callback(") - builder.WriteString(fmt.Sprintf("id=%v", c.ID)) - builder.WriteString(", hash=") - builder.WriteString(", type=") - builder.WriteString(fmt.Sprintf("%v", c.Type)) - builder.WriteString(", created_at=") - builder.WriteString(c.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", updated_at=") - builder.WriteString(c.UpdatedAt.Format(time.ANSIC)) - builder.WriteString(", repo_id=") - builder.WriteString(fmt.Sprintf("%v", c.RepoID)) - builder.WriteByte(')') - return builder.String() -} - -// Callbacks is a parsable slice of Callback. -type Callbacks []*Callback - -func (c Callbacks) config(cfg config) { - for _i := range c { - c[_i].config = cfg - } -} diff --git a/model/ent/callback/callback.go b/model/ent/callback/callback.go deleted file mode 100644 index b1273d42..00000000 --- a/model/ent/callback/callback.go +++ /dev/null @@ -1,92 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package callback - -import ( - "fmt" - "time" -) - -const ( - // Label holds the string label denoting the callback type in the database. - Label = "callback" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldHash holds the string denoting the hash field in the database. - FieldHash = "hash" - // FieldType holds the string denoting the type field in the database. - FieldType = "type" - // 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. - FieldUpdatedAt = "updated_at" - // FieldRepoID holds the string denoting the repo_id field in the database. - FieldRepoID = "repo_id" - // EdgeRepo holds the string denoting the repo edge name in mutations. - EdgeRepo = "repo" - // Table holds the table name of the callback in the database. - Table = "callbacks" - // RepoTable is the table that holds the repo relation/edge. - RepoTable = "callbacks" - // RepoInverseTable is the table name for the Repo entity. - // It exists in this package in order to avoid circular dependency with the "repo" package. - RepoInverseTable = "repos" - // RepoColumn is the table column denoting the repo relation/edge. - RepoColumn = "repo_id" -) - -// Columns holds all SQL columns for callback fields. -var Columns = []string{ - FieldID, - FieldHash, - FieldType, - FieldCreatedAt, - FieldUpdatedAt, - FieldRepoID, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultHash holds the default value on creation for the "hash" field. - DefaultHash func() string - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() time.Time - // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. - UpdateDefaultUpdatedAt func() time.Time -) - -// Type defines the type for the "type" enum field. -type Type string - -// Type values. -const ( - TypeDeploy Type = "deploy" - TypeRollback Type = "rollback" - TypeLock Type = "lock" - TypeUnlock Type = "unlock" -) - -func (_type Type) String() string { - return string(_type) -} - -// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save. -func TypeValidator(_type Type) error { - switch _type { - case TypeDeploy, TypeRollback, TypeLock, TypeUnlock: - return nil - default: - return fmt.Errorf("callback: invalid enum value for type field: %q", _type) - } -} diff --git a/model/ent/callback/where.go b/model/ent/callback/where.go deleted file mode 100644 index 08bc5822..00000000 --- a/model/ent/callback/where.go +++ /dev/null @@ -1,541 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package callback - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "github.com/gitploy-io/gitploy/model/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldID), id)) - }) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldID), id)) - }) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.In(s.C(FieldID), v...)) - }) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(ids) == 0 { - s.Where(sql.False()) - return - } - v := make([]interface{}, len(ids)) - for i := range v { - v[i] = ids[i] - } - s.Where(sql.NotIn(s.C(FieldID), v...)) - }) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldID), id)) - }) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldID), id)) - }) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldID), id)) - }) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldID), id)) - }) -} - -// Hash applies equality check predicate on the "hash" field. It's identical to HashEQ. -func Hash(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHash), v)) - }) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// RepoID applies equality check predicate on the "repo_id" field. It's identical to RepoIDEQ. -func RepoID(v int64) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRepoID), v)) - }) -} - -// HashEQ applies the EQ predicate on the "hash" field. -func HashEQ(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldHash), v)) - }) -} - -// HashNEQ applies the NEQ predicate on the "hash" field. -func HashNEQ(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldHash), v)) - }) -} - -// HashIn applies the In predicate on the "hash" field. -func HashIn(vs ...string) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldHash), v...)) - }) -} - -// HashNotIn applies the NotIn predicate on the "hash" field. -func HashNotIn(vs ...string) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldHash), v...)) - }) -} - -// HashGT applies the GT predicate on the "hash" field. -func HashGT(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldHash), v)) - }) -} - -// HashGTE applies the GTE predicate on the "hash" field. -func HashGTE(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldHash), v)) - }) -} - -// HashLT applies the LT predicate on the "hash" field. -func HashLT(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldHash), v)) - }) -} - -// HashLTE applies the LTE predicate on the "hash" field. -func HashLTE(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldHash), v)) - }) -} - -// HashContains applies the Contains predicate on the "hash" field. -func HashContains(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.Contains(s.C(FieldHash), v)) - }) -} - -// HashHasPrefix applies the HasPrefix predicate on the "hash" field. -func HashHasPrefix(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.HasPrefix(s.C(FieldHash), v)) - }) -} - -// HashHasSuffix applies the HasSuffix predicate on the "hash" field. -func HashHasSuffix(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.HasSuffix(s.C(FieldHash), v)) - }) -} - -// HashEqualFold applies the EqualFold predicate on the "hash" field. -func HashEqualFold(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EqualFold(s.C(FieldHash), v)) - }) -} - -// HashContainsFold applies the ContainsFold predicate on the "hash" field. -func HashContainsFold(v string) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.ContainsFold(s.C(FieldHash), v)) - }) -} - -// TypeEQ applies the EQ predicate on the "type" field. -func TypeEQ(v Type) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldType), v)) - }) -} - -// TypeNEQ applies the NEQ predicate on the "type" field. -func TypeNEQ(v Type) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldType), v)) - }) -} - -// TypeIn applies the In predicate on the "type" field. -func TypeIn(vs ...Type) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldType), v...)) - }) -} - -// TypeNotIn applies the NotIn predicate on the "type" field. -func TypeNotIn(vs ...Type) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldType), v...)) - }) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldCreatedAt), v...)) - }) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldCreatedAt), v)) - }) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldCreatedAt), v)) - }) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...)) - }) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldUpdatedAt), v)) - }) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) - }) -} - -// RepoIDEQ applies the EQ predicate on the "repo_id" field. -func RepoIDEQ(v int64) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRepoID), v)) - }) -} - -// RepoIDNEQ applies the NEQ predicate on the "repo_id" field. -func RepoIDNEQ(v int64) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldRepoID), v)) - }) -} - -// RepoIDIn applies the In predicate on the "repo_id" field. -func RepoIDIn(vs ...int64) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.In(s.C(FieldRepoID), v...)) - }) -} - -// RepoIDNotIn applies the NotIn predicate on the "repo_id" field. -func RepoIDNotIn(vs ...int64) predicate.Callback { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Callback(func(s *sql.Selector) { - // if not arguments were provided, append the FALSE constants, - // since we can't apply "IN ()". This will make this predicate falsy. - if len(v) == 0 { - s.Where(sql.False()) - return - } - s.Where(sql.NotIn(s.C(FieldRepoID), v...)) - }) -} - -// HasRepo applies the HasEdge predicate on the "repo" edge. -func HasRepo() predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RepoTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RepoTable, RepoColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasRepoWith applies the HasEdge predicate on the "repo" edge with a given conditions (other predicates). -func HasRepoWith(preds ...predicate.Repo) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RepoInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RepoTable, RepoColumn), - ) - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Callback) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Callback) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Callback) predicate.Callback { - return predicate.Callback(func(s *sql.Selector) { - p(s.Not()) - }) -} diff --git a/model/ent/callback_create.go b/model/ent/callback_create.go deleted file mode 100644 index 10a5420e..00000000 --- a/model/ent/callback_create.go +++ /dev/null @@ -1,357 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/model/ent/callback" - "github.com/gitploy-io/gitploy/model/ent/repo" -) - -// CallbackCreate is the builder for creating a Callback entity. -type CallbackCreate struct { - config - mutation *CallbackMutation - hooks []Hook -} - -// SetHash sets the "hash" field. -func (cc *CallbackCreate) SetHash(s string) *CallbackCreate { - cc.mutation.SetHash(s) - return cc -} - -// SetNillableHash sets the "hash" field if the given value is not nil. -func (cc *CallbackCreate) SetNillableHash(s *string) *CallbackCreate { - if s != nil { - cc.SetHash(*s) - } - return cc -} - -// SetType sets the "type" field. -func (cc *CallbackCreate) SetType(c callback.Type) *CallbackCreate { - cc.mutation.SetType(c) - return cc -} - -// SetCreatedAt sets the "created_at" field. -func (cc *CallbackCreate) SetCreatedAt(t time.Time) *CallbackCreate { - cc.mutation.SetCreatedAt(t) - return cc -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (cc *CallbackCreate) SetNillableCreatedAt(t *time.Time) *CallbackCreate { - if t != nil { - cc.SetCreatedAt(*t) - } - return cc -} - -// SetUpdatedAt sets the "updated_at" field. -func (cc *CallbackCreate) SetUpdatedAt(t time.Time) *CallbackCreate { - cc.mutation.SetUpdatedAt(t) - return cc -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (cc *CallbackCreate) SetNillableUpdatedAt(t *time.Time) *CallbackCreate { - if t != nil { - cc.SetUpdatedAt(*t) - } - return cc -} - -// SetRepoID sets the "repo_id" field. -func (cc *CallbackCreate) SetRepoID(i int64) *CallbackCreate { - cc.mutation.SetRepoID(i) - return cc -} - -// SetRepo sets the "repo" edge to the Repo entity. -func (cc *CallbackCreate) SetRepo(r *Repo) *CallbackCreate { - return cc.SetRepoID(r.ID) -} - -// Mutation returns the CallbackMutation object of the builder. -func (cc *CallbackCreate) Mutation() *CallbackMutation { - return cc.mutation -} - -// Save creates the Callback in the database. -func (cc *CallbackCreate) Save(ctx context.Context) (*Callback, error) { - var ( - err error - node *Callback - ) - cc.defaults() - if len(cc.hooks) == 0 { - if err = cc.check(); err != nil { - return nil, err - } - node, err = cc.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CallbackMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = cc.check(); err != nil { - return nil, err - } - cc.mutation = mutation - if node, err = cc.sqlSave(ctx); err != nil { - return nil, err - } - mutation.id = &node.ID - mutation.done = true - return node, err - }) - for i := len(cc.hooks) - 1; i >= 0; i-- { - if cc.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = cc.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cc.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX calls Save and panics if Save returns an error. -func (cc *CallbackCreate) SaveX(ctx context.Context) *Callback { - v, err := cc.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (cc *CallbackCreate) Exec(ctx context.Context) error { - _, err := cc.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cc *CallbackCreate) ExecX(ctx context.Context) { - if err := cc.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (cc *CallbackCreate) defaults() { - if _, ok := cc.mutation.Hash(); !ok { - v := callback.DefaultHash() - cc.mutation.SetHash(v) - } - if _, ok := cc.mutation.CreatedAt(); !ok { - v := callback.DefaultCreatedAt() - cc.mutation.SetCreatedAt(v) - } - if _, ok := cc.mutation.UpdatedAt(); !ok { - v := callback.DefaultUpdatedAt() - cc.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (cc *CallbackCreate) check() error { - if _, ok := cc.mutation.Hash(); !ok { - return &ValidationError{Name: "hash", err: errors.New(`ent: missing required field "hash"`)} - } - if _, ok := cc.mutation.GetType(); !ok { - return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "type"`)} - } - if v, ok := cc.mutation.GetType(); ok { - if err := callback.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "type": %w`, err)} - } - } - if _, ok := cc.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "created_at"`)} - } - if _, ok := cc.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "updated_at"`)} - } - if _, ok := cc.mutation.RepoID(); !ok { - return &ValidationError{Name: "repo_id", err: errors.New(`ent: missing required field "repo_id"`)} - } - if _, ok := cc.mutation.RepoID(); !ok { - return &ValidationError{Name: "repo", err: errors.New("ent: missing required edge \"repo\"")} - } - return nil -} - -func (cc *CallbackCreate) sqlSave(ctx context.Context) (*Callback, error) { - _node, _spec := cc.createSpec() - if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - return _node, nil -} - -func (cc *CallbackCreate) createSpec() (*Callback, *sqlgraph.CreateSpec) { - var ( - _node = &Callback{config: cc.config} - _spec = &sqlgraph.CreateSpec{ - Table: callback.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - } - ) - if value, ok := cc.mutation.Hash(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeString, - Value: value, - Column: callback.FieldHash, - }) - _node.Hash = value - } - if value, ok := cc.mutation.GetType(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeEnum, - Value: value, - Column: callback.FieldType, - }) - _node.Type = value - } - if value, ok := cc.mutation.CreatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: callback.FieldCreatedAt, - }) - _node.CreatedAt = value - } - if value, ok := cc.mutation.UpdatedAt(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: callback.FieldUpdatedAt, - }) - _node.UpdatedAt = value - } - if nodes := cc.mutation.RepoIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: callback.RepoTable, - Columns: []string{callback.RepoColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: repo.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _node.RepoID = nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// CallbackCreateBulk is the builder for creating many Callback entities in bulk. -type CallbackCreateBulk struct { - config - builders []*CallbackCreate -} - -// Save creates the Callback entities in the database. -func (ccb *CallbackCreateBulk) Save(ctx context.Context) ([]*Callback, error) { - specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) - nodes := make([]*Callback, len(ccb.builders)) - mutators := make([]Mutator, len(ccb.builders)) - for i := range ccb.builders { - func(i int, root context.Context) { - builder := ccb.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CallbackMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() - var err error - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, ccb.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - mutation.done = true - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, ccb.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (ccb *CallbackCreateBulk) SaveX(ctx context.Context) []*Callback { - v, err := ccb.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (ccb *CallbackCreateBulk) Exec(ctx context.Context) error { - _, err := ccb.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (ccb *CallbackCreateBulk) ExecX(ctx context.Context) { - if err := ccb.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/model/ent/callback_delete.go b/model/ent/callback_delete.go deleted file mode 100644 index bda6cdc5..00000000 --- a/model/ent/callback_delete.go +++ /dev/null @@ -1,111 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/model/ent/callback" - "github.com/gitploy-io/gitploy/model/ent/predicate" -) - -// CallbackDelete is the builder for deleting a Callback entity. -type CallbackDelete struct { - config - hooks []Hook - mutation *CallbackMutation -} - -// Where appends a list predicates to the CallbackDelete builder. -func (cd *CallbackDelete) Where(ps ...predicate.Callback) *CallbackDelete { - cd.mutation.Where(ps...) - return cd -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (cd *CallbackDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(cd.hooks) == 0 { - affected, err = cd.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CallbackMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - cd.mutation = mutation - affected, err = cd.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(cd.hooks) - 1; i >= 0; i-- { - if cd.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = cd.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cd.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cd *CallbackDelete) ExecX(ctx context.Context) int { - n, err := cd.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (cd *CallbackDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: callback.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - if ps := cd.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return sqlgraph.DeleteNodes(ctx, cd.driver, _spec) -} - -// CallbackDeleteOne is the builder for deleting a single Callback entity. -type CallbackDeleteOne struct { - cd *CallbackDelete -} - -// Exec executes the deletion query. -func (cdo *CallbackDeleteOne) Exec(ctx context.Context) error { - n, err := cdo.cd.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{callback.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (cdo *CallbackDeleteOne) ExecX(ctx context.Context) { - cdo.cd.ExecX(ctx) -} diff --git a/model/ent/callback_query.go b/model/ent/callback_query.go deleted file mode 100644 index 5c70d8f1..00000000 --- a/model/ent/callback_query.go +++ /dev/null @@ -1,1020 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "math" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/model/ent/callback" - "github.com/gitploy-io/gitploy/model/ent/predicate" - "github.com/gitploy-io/gitploy/model/ent/repo" -) - -// CallbackQuery is the builder for querying Callback entities. -type CallbackQuery struct { - config - limit *int - offset *int - unique *bool - order []OrderFunc - fields []string - predicates []predicate.Callback - // eager-loading edges. - withRepo *RepoQuery - modifiers []func(s *sql.Selector) - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the CallbackQuery builder. -func (cq *CallbackQuery) Where(ps ...predicate.Callback) *CallbackQuery { - cq.predicates = append(cq.predicates, ps...) - return cq -} - -// Limit adds a limit step to the query. -func (cq *CallbackQuery) Limit(limit int) *CallbackQuery { - cq.limit = &limit - return cq -} - -// Offset adds an offset step to the query. -func (cq *CallbackQuery) Offset(offset int) *CallbackQuery { - cq.offset = &offset - return cq -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (cq *CallbackQuery) Unique(unique bool) *CallbackQuery { - cq.unique = &unique - return cq -} - -// Order adds an order step to the query. -func (cq *CallbackQuery) Order(o ...OrderFunc) *CallbackQuery { - cq.order = append(cq.order, o...) - return cq -} - -// QueryRepo chains the current query on the "repo" edge. -func (cq *CallbackQuery) QueryRepo() *RepoQuery { - query := &RepoQuery{config: cq.config} - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := cq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(callback.Table, callback.FieldID, selector), - sqlgraph.To(repo.Table, repo.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, callback.RepoTable, callback.RepoColumn), - ) - fromU = sqlgraph.SetNeighbors(cq.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first Callback entity from the query. -// Returns a *NotFoundError when no Callback was found. -func (cq *CallbackQuery) First(ctx context.Context) (*Callback, error) { - nodes, err := cq.Limit(1).All(ctx) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{callback.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (cq *CallbackQuery) FirstX(ctx context.Context) *Callback { - node, err := cq.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Callback ID from the query. -// Returns a *NotFoundError when no Callback ID was found. -func (cq *CallbackQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = cq.Limit(1).IDs(ctx); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{callback.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (cq *CallbackQuery) FirstIDX(ctx context.Context) int { - id, err := cq.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Callback entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Callback entity is not found. -// Returns a *NotFoundError when no Callback entities are found. -func (cq *CallbackQuery) Only(ctx context.Context) (*Callback, error) { - nodes, err := cq.Limit(2).All(ctx) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{callback.Label} - default: - return nil, &NotSingularError{callback.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (cq *CallbackQuery) OnlyX(ctx context.Context) *Callback { - node, err := cq.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Callback ID in the query. -// Returns a *NotSingularError when exactly one Callback ID is not found. -// Returns a *NotFoundError when no entities are found. -func (cq *CallbackQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = cq.Limit(2).IDs(ctx); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{callback.Label} - default: - err = &NotSingularError{callback.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (cq *CallbackQuery) OnlyIDX(ctx context.Context) int { - id, err := cq.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Callbacks. -func (cq *CallbackQuery) All(ctx context.Context) ([]*Callback, error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - return cq.sqlAll(ctx) -} - -// AllX is like All, but panics if an error occurs. -func (cq *CallbackQuery) AllX(ctx context.Context) []*Callback { - nodes, err := cq.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Callback IDs. -func (cq *CallbackQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int - if err := cq.Select(callback.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (cq *CallbackQuery) IDsX(ctx context.Context) []int { - ids, err := cq.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (cq *CallbackQuery) Count(ctx context.Context) (int, error) { - if err := cq.prepareQuery(ctx); err != nil { - return 0, err - } - return cq.sqlCount(ctx) -} - -// CountX is like Count, but panics if an error occurs. -func (cq *CallbackQuery) CountX(ctx context.Context) int { - count, err := cq.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (cq *CallbackQuery) Exist(ctx context.Context) (bool, error) { - if err := cq.prepareQuery(ctx); err != nil { - return false, err - } - return cq.sqlExist(ctx) -} - -// ExistX is like Exist, but panics if an error occurs. -func (cq *CallbackQuery) ExistX(ctx context.Context) bool { - exist, err := cq.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the CallbackQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (cq *CallbackQuery) Clone() *CallbackQuery { - if cq == nil { - return nil - } - return &CallbackQuery{ - config: cq.config, - limit: cq.limit, - offset: cq.offset, - order: append([]OrderFunc{}, cq.order...), - predicates: append([]predicate.Callback{}, cq.predicates...), - withRepo: cq.withRepo.Clone(), - // clone intermediate query. - sql: cq.sql.Clone(), - path: cq.path, - } -} - -// WithRepo tells the query-builder to eager-load the nodes that are connected to -// the "repo" edge. The optional arguments are used to configure the query builder of the edge. -func (cq *CallbackQuery) WithRepo(opts ...func(*RepoQuery)) *CallbackQuery { - query := &RepoQuery{config: cq.config} - for _, opt := range opts { - opt(query) - } - cq.withRepo = query - return cq -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// Hash string `json:"hash"` -// Count int `json:"count,omitempty"` -// } -// -// client.Callback.Query(). -// GroupBy(callback.FieldHash). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -// -func (cq *CallbackQuery) GroupBy(field string, fields ...string) *CallbackGroupBy { - group := &CallbackGroupBy{config: cq.config} - group.fields = append([]string{field}, fields...) - group.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := cq.prepareQuery(ctx); err != nil { - return nil, err - } - return cq.sqlQuery(ctx), nil - } - return group -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// Hash string `json:"hash"` -// } -// -// client.Callback.Query(). -// Select(callback.FieldHash). -// Scan(ctx, &v) -// -func (cq *CallbackQuery) Select(fields ...string) *CallbackSelect { - cq.fields = append(cq.fields, fields...) - return &CallbackSelect{CallbackQuery: cq} -} - -func (cq *CallbackQuery) prepareQuery(ctx context.Context) error { - for _, f := range cq.fields { - if !callback.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if cq.path != nil { - prev, err := cq.path(ctx) - if err != nil { - return err - } - cq.sql = prev - } - return nil -} - -func (cq *CallbackQuery) sqlAll(ctx context.Context) ([]*Callback, error) { - var ( - nodes = []*Callback{} - _spec = cq.querySpec() - loadedTypes = [1]bool{ - cq.withRepo != nil, - } - ) - _spec.ScanValues = func(columns []string) ([]interface{}, error) { - node := &Callback{config: cq.config} - nodes = append(nodes, node) - return node.scanValues(columns) - } - _spec.Assign = func(columns []string, values []interface{}) error { - if len(nodes) == 0 { - return fmt.Errorf("ent: Assign called without calling ScanValues") - } - node := nodes[len(nodes)-1] - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - if len(cq.modifiers) > 0 { - _spec.Modifiers = cq.modifiers - } - if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - - if query := cq.withRepo; query != nil { - ids := make([]int64, 0, len(nodes)) - nodeids := make(map[int64][]*Callback) - for i := range nodes { - fk := nodes[i].RepoID - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - query.Where(repo.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return nil, err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "repo_id" returned %v`, n.ID) - } - for i := range nodes { - nodes[i].Edges.Repo = n - } - } - } - - return nodes, nil -} - -func (cq *CallbackQuery) sqlCount(ctx context.Context) (int, error) { - _spec := cq.querySpec() - if len(cq.modifiers) > 0 { - _spec.Modifiers = cq.modifiers - } - return sqlgraph.CountNodes(ctx, cq.driver, _spec) -} - -func (cq *CallbackQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := cq.sqlCount(ctx) - if err != nil { - return false, fmt.Errorf("ent: check existence: %w", err) - } - return n > 0, nil -} - -func (cq *CallbackQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: callback.Table, - Columns: callback.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - From: cq.sql, - Unique: true, - } - if unique := cq.unique; unique != nil { - _spec.Unique = *unique - } - if fields := cq.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, callback.FieldID) - for i := range fields { - if fields[i] != callback.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := cq.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := cq.limit; limit != nil { - _spec.Limit = *limit - } - if offset := cq.offset; offset != nil { - _spec.Offset = *offset - } - if ps := cq.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (cq *CallbackQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(cq.driver.Dialect()) - t1 := builder.Table(callback.Table) - columns := cq.fields - if len(columns) == 0 { - columns = callback.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if cq.sql != nil { - selector = cq.sql - selector.Select(selector.Columns(columns...)...) - } - for _, m := range cq.modifiers { - m(selector) - } - for _, p := range cq.predicates { - p(selector) - } - for _, p := range cq.order { - p(selector) - } - if offset := cq.offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := cq.limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// ForUpdate locks the selected rows against concurrent updates, and prevent them from being -// updated, deleted or "selected ... for update" by other sessions, until the transaction is -// either committed or rolled-back. -func (cq *CallbackQuery) ForUpdate(opts ...sql.LockOption) *CallbackQuery { - if cq.driver.Dialect() == dialect.Postgres { - cq.Unique(false) - } - cq.modifiers = append(cq.modifiers, func(s *sql.Selector) { - s.ForUpdate(opts...) - }) - return cq -} - -// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock -// on any rows that are read. Other sessions can read the rows, but cannot modify them -// until your transaction commits. -func (cq *CallbackQuery) ForShare(opts ...sql.LockOption) *CallbackQuery { - if cq.driver.Dialect() == dialect.Postgres { - cq.Unique(false) - } - cq.modifiers = append(cq.modifiers, func(s *sql.Selector) { - s.ForShare(opts...) - }) - return cq -} - -// CallbackGroupBy is the group-by builder for Callback entities. -type CallbackGroupBy struct { - config - fields []string - fns []AggregateFunc - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (cgb *CallbackGroupBy) Aggregate(fns ...AggregateFunc) *CallbackGroupBy { - cgb.fns = append(cgb.fns, fns...) - return cgb -} - -// Scan applies the group-by query and scans the result into the given value. -func (cgb *CallbackGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := cgb.path(ctx) - if err != nil { - return err - } - cgb.sql = query - return cgb.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (cgb *CallbackGroupBy) ScanX(ctx context.Context, v interface{}) { - if err := cgb.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CallbackGroupBy) Strings(ctx context.Context) ([]string, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CallbackGroupBy.Strings is not achievable when grouping more than 1 field") - } - var v []string - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (cgb *CallbackGroupBy) StringsX(ctx context.Context) []string { - v, err := cgb.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CallbackGroupBy) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = cgb.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{callback.Label} - default: - err = fmt.Errorf("ent: CallbackGroupBy.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (cgb *CallbackGroupBy) StringX(ctx context.Context) string { - v, err := cgb.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CallbackGroupBy) Ints(ctx context.Context) ([]int, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CallbackGroupBy.Ints is not achievable when grouping more than 1 field") - } - var v []int - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (cgb *CallbackGroupBy) IntsX(ctx context.Context) []int { - v, err := cgb.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CallbackGroupBy) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = cgb.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{callback.Label} - default: - err = fmt.Errorf("ent: CallbackGroupBy.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (cgb *CallbackGroupBy) IntX(ctx context.Context) int { - v, err := cgb.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CallbackGroupBy) Float64s(ctx context.Context) ([]float64, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CallbackGroupBy.Float64s is not achievable when grouping more than 1 field") - } - var v []float64 - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (cgb *CallbackGroupBy) Float64sX(ctx context.Context) []float64 { - v, err := cgb.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CallbackGroupBy) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = cgb.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{callback.Label} - default: - err = fmt.Errorf("ent: CallbackGroupBy.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (cgb *CallbackGroupBy) Float64X(ctx context.Context) float64 { - v, err := cgb.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from group-by. -// It is only allowed when executing a group-by query with one field. -func (cgb *CallbackGroupBy) Bools(ctx context.Context) ([]bool, error) { - if len(cgb.fields) > 1 { - return nil, errors.New("ent: CallbackGroupBy.Bools is not achievable when grouping more than 1 field") - } - var v []bool - if err := cgb.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (cgb *CallbackGroupBy) BoolsX(ctx context.Context) []bool { - v, err := cgb.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a group-by query. -// It is only allowed when executing a group-by query with one field. -func (cgb *CallbackGroupBy) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = cgb.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{callback.Label} - default: - err = fmt.Errorf("ent: CallbackGroupBy.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (cgb *CallbackGroupBy) BoolX(ctx context.Context) bool { - v, err := cgb.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (cgb *CallbackGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range cgb.fields { - if !callback.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} - } - } - selector := cgb.sqlQuery() - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := cgb.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -func (cgb *CallbackGroupBy) sqlQuery() *sql.Selector { - selector := cgb.sql.Select() - aggregation := make([]string, 0, len(cgb.fns)) - for _, fn := range cgb.fns { - aggregation = append(aggregation, fn(selector)) - } - // If no columns were selected in a custom aggregation function, the default - // selection is the fields used for "group-by", and the aggregation functions. - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(cgb.fields)+len(cgb.fns)) - for _, f := range cgb.fields { - columns = append(columns, selector.C(f)) - } - for _, c := range aggregation { - columns = append(columns, c) - } - selector.Select(columns...) - } - return selector.GroupBy(selector.Columns(cgb.fields...)...) -} - -// CallbackSelect is the builder for selecting fields of Callback entities. -type CallbackSelect struct { - *CallbackQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector -} - -// Scan applies the selector query and scans the result into the given value. -func (cs *CallbackSelect) Scan(ctx context.Context, v interface{}) error { - if err := cs.prepareQuery(ctx); err != nil { - return err - } - cs.sql = cs.CallbackQuery.sqlQuery(ctx) - return cs.sqlScan(ctx, v) -} - -// ScanX is like Scan, but panics if an error occurs. -func (cs *CallbackSelect) ScanX(ctx context.Context, v interface{}) { - if err := cs.Scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (cs *CallbackSelect) Strings(ctx context.Context) ([]string, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CallbackSelect.Strings is not achievable when selecting more than 1 field") - } - var v []string - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (cs *CallbackSelect) StringsX(ctx context.Context) []string { - v, err := cs.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a selector. It is only allowed when selecting one field. -func (cs *CallbackSelect) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = cs.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{callback.Label} - default: - err = fmt.Errorf("ent: CallbackSelect.Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (cs *CallbackSelect) StringX(ctx context.Context) string { - v, err := cs.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (cs *CallbackSelect) Ints(ctx context.Context) ([]int, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CallbackSelect.Ints is not achievable when selecting more than 1 field") - } - var v []int - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (cs *CallbackSelect) IntsX(ctx context.Context) []int { - v, err := cs.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a selector. It is only allowed when selecting one field. -func (cs *CallbackSelect) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = cs.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{callback.Label} - default: - err = fmt.Errorf("ent: CallbackSelect.Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (cs *CallbackSelect) IntX(ctx context.Context) int { - v, err := cs.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (cs *CallbackSelect) Float64s(ctx context.Context) ([]float64, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CallbackSelect.Float64s is not achievable when selecting more than 1 field") - } - var v []float64 - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (cs *CallbackSelect) Float64sX(ctx context.Context) []float64 { - v, err := cs.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (cs *CallbackSelect) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = cs.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{callback.Label} - default: - err = fmt.Errorf("ent: CallbackSelect.Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (cs *CallbackSelect) Float64X(ctx context.Context) float64 { - v, err := cs.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (cs *CallbackSelect) Bools(ctx context.Context) ([]bool, error) { - if len(cs.fields) > 1 { - return nil, errors.New("ent: CallbackSelect.Bools is not achievable when selecting more than 1 field") - } - var v []bool - if err := cs.Scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (cs *CallbackSelect) BoolsX(ctx context.Context) []bool { - v, err := cs.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (cs *CallbackSelect) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = cs.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{callback.Label} - default: - err = fmt.Errorf("ent: CallbackSelect.Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (cs *CallbackSelect) BoolX(ctx context.Context) bool { - v, err := cs.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -func (cs *CallbackSelect) sqlScan(ctx context.Context, v interface{}) error { - rows := &sql.Rows{} - query, args := cs.sql.Query() - if err := cs.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/model/ent/callback_update.go b/model/ent/callback_update.go deleted file mode 100644 index 095b1dfb..00000000 --- a/model/ent/callback_update.go +++ /dev/null @@ -1,495 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/model/ent/callback" - "github.com/gitploy-io/gitploy/model/ent/predicate" - "github.com/gitploy-io/gitploy/model/ent/repo" -) - -// CallbackUpdate is the builder for updating Callback entities. -type CallbackUpdate struct { - config - hooks []Hook - mutation *CallbackMutation -} - -// Where appends a list predicates to the CallbackUpdate builder. -func (cu *CallbackUpdate) Where(ps ...predicate.Callback) *CallbackUpdate { - cu.mutation.Where(ps...) - return cu -} - -// SetType sets the "type" field. -func (cu *CallbackUpdate) SetType(c callback.Type) *CallbackUpdate { - cu.mutation.SetType(c) - return cu -} - -// SetCreatedAt sets the "created_at" field. -func (cu *CallbackUpdate) SetCreatedAt(t time.Time) *CallbackUpdate { - cu.mutation.SetCreatedAt(t) - return cu -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (cu *CallbackUpdate) SetNillableCreatedAt(t *time.Time) *CallbackUpdate { - if t != nil { - cu.SetCreatedAt(*t) - } - return cu -} - -// SetUpdatedAt sets the "updated_at" field. -func (cu *CallbackUpdate) SetUpdatedAt(t time.Time) *CallbackUpdate { - cu.mutation.SetUpdatedAt(t) - return cu -} - -// SetRepoID sets the "repo_id" field. -func (cu *CallbackUpdate) SetRepoID(i int64) *CallbackUpdate { - cu.mutation.SetRepoID(i) - return cu -} - -// SetRepo sets the "repo" edge to the Repo entity. -func (cu *CallbackUpdate) SetRepo(r *Repo) *CallbackUpdate { - return cu.SetRepoID(r.ID) -} - -// Mutation returns the CallbackMutation object of the builder. -func (cu *CallbackUpdate) Mutation() *CallbackMutation { - return cu.mutation -} - -// ClearRepo clears the "repo" edge to the Repo entity. -func (cu *CallbackUpdate) ClearRepo() *CallbackUpdate { - cu.mutation.ClearRepo() - return cu -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (cu *CallbackUpdate) Save(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - cu.defaults() - if len(cu.hooks) == 0 { - if err = cu.check(); err != nil { - return 0, err - } - affected, err = cu.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CallbackMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = cu.check(); err != nil { - return 0, err - } - cu.mutation = mutation - affected, err = cu.sqlSave(ctx) - mutation.done = true - return affected, err - }) - for i := len(cu.hooks) - 1; i >= 0; i-- { - if cu.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = cu.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cu.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// SaveX is like Save, but panics if an error occurs. -func (cu *CallbackUpdate) SaveX(ctx context.Context) int { - affected, err := cu.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (cu *CallbackUpdate) Exec(ctx context.Context) error { - _, err := cu.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cu *CallbackUpdate) ExecX(ctx context.Context) { - if err := cu.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (cu *CallbackUpdate) defaults() { - if _, ok := cu.mutation.UpdatedAt(); !ok { - v := callback.UpdateDefaultUpdatedAt() - cu.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (cu *CallbackUpdate) check() error { - if v, ok := cu.mutation.GetType(); ok { - if err := callback.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf("ent: validator failed for field \"type\": %w", err)} - } - } - if _, ok := cu.mutation.RepoID(); cu.mutation.RepoCleared() && !ok { - return errors.New("ent: clearing a required unique edge \"repo\"") - } - return nil -} - -func (cu *CallbackUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: callback.Table, - Columns: callback.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - if ps := cu.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := cu.mutation.GetType(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeEnum, - Value: value, - Column: callback.FieldType, - }) - } - if value, ok := cu.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: callback.FieldCreatedAt, - }) - } - if value, ok := cu.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: callback.FieldUpdatedAt, - }) - } - if cu.mutation.RepoCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: callback.RepoTable, - Columns: []string{callback.RepoColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: repo.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := cu.mutation.RepoIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: callback.RepoTable, - Columns: []string{callback.RepoColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: repo.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{callback.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return 0, err - } - return n, nil -} - -// CallbackUpdateOne is the builder for updating a single Callback entity. -type CallbackUpdateOne struct { - config - fields []string - hooks []Hook - mutation *CallbackMutation -} - -// SetType sets the "type" field. -func (cuo *CallbackUpdateOne) SetType(c callback.Type) *CallbackUpdateOne { - cuo.mutation.SetType(c) - return cuo -} - -// SetCreatedAt sets the "created_at" field. -func (cuo *CallbackUpdateOne) SetCreatedAt(t time.Time) *CallbackUpdateOne { - cuo.mutation.SetCreatedAt(t) - return cuo -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (cuo *CallbackUpdateOne) SetNillableCreatedAt(t *time.Time) *CallbackUpdateOne { - if t != nil { - cuo.SetCreatedAt(*t) - } - return cuo -} - -// SetUpdatedAt sets the "updated_at" field. -func (cuo *CallbackUpdateOne) SetUpdatedAt(t time.Time) *CallbackUpdateOne { - cuo.mutation.SetUpdatedAt(t) - return cuo -} - -// SetRepoID sets the "repo_id" field. -func (cuo *CallbackUpdateOne) SetRepoID(i int64) *CallbackUpdateOne { - cuo.mutation.SetRepoID(i) - return cuo -} - -// SetRepo sets the "repo" edge to the Repo entity. -func (cuo *CallbackUpdateOne) SetRepo(r *Repo) *CallbackUpdateOne { - return cuo.SetRepoID(r.ID) -} - -// Mutation returns the CallbackMutation object of the builder. -func (cuo *CallbackUpdateOne) Mutation() *CallbackMutation { - return cuo.mutation -} - -// ClearRepo clears the "repo" edge to the Repo entity. -func (cuo *CallbackUpdateOne) ClearRepo() *CallbackUpdateOne { - cuo.mutation.ClearRepo() - return cuo -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (cuo *CallbackUpdateOne) Select(field string, fields ...string) *CallbackUpdateOne { - cuo.fields = append([]string{field}, fields...) - return cuo -} - -// Save executes the query and returns the updated Callback entity. -func (cuo *CallbackUpdateOne) Save(ctx context.Context) (*Callback, error) { - var ( - err error - node *Callback - ) - cuo.defaults() - if len(cuo.hooks) == 0 { - if err = cuo.check(); err != nil { - return nil, err - } - node, err = cuo.sqlSave(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*CallbackMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err = cuo.check(); err != nil { - return nil, err - } - cuo.mutation = mutation - node, err = cuo.sqlSave(ctx) - mutation.done = true - return node, err - }) - for i := len(cuo.hooks) - 1; i >= 0; i-- { - if cuo.hooks[i] == nil { - return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = cuo.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, cuo.mutation); err != nil { - return nil, err - } - } - return node, err -} - -// SaveX is like Save, but panics if an error occurs. -func (cuo *CallbackUpdateOne) SaveX(ctx context.Context) *Callback { - node, err := cuo.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (cuo *CallbackUpdateOne) Exec(ctx context.Context) error { - _, err := cuo.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (cuo *CallbackUpdateOne) ExecX(ctx context.Context) { - if err := cuo.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (cuo *CallbackUpdateOne) defaults() { - if _, ok := cuo.mutation.UpdatedAt(); !ok { - v := callback.UpdateDefaultUpdatedAt() - cuo.mutation.SetUpdatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (cuo *CallbackUpdateOne) check() error { - if v, ok := cuo.mutation.GetType(); ok { - if err := callback.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf("ent: validator failed for field \"type\": %w", err)} - } - } - if _, ok := cuo.mutation.RepoID(); cuo.mutation.RepoCleared() && !ok { - return errors.New("ent: clearing a required unique edge \"repo\"") - } - return nil -} - -func (cuo *CallbackUpdateOne) sqlSave(ctx context.Context) (_node *Callback, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: callback.Table, - Columns: callback.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - id, ok := cuo.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Callback.ID for update")} - } - _spec.Node.ID.Value = id - if fields := cuo.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, callback.FieldID) - for _, f := range fields { - if !callback.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != callback.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := cuo.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := cuo.mutation.GetType(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeEnum, - Value: value, - Column: callback.FieldType, - }) - } - if value, ok := cuo.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: callback.FieldCreatedAt, - }) - } - if value, ok := cuo.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: callback.FieldUpdatedAt, - }) - } - if cuo.mutation.RepoCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: callback.RepoTable, - Columns: []string{callback.RepoColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: repo.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := cuo.mutation.RepoIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: true, - Table: callback.RepoTable, - Columns: []string{callback.RepoColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt64, - Column: repo.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &Callback{config: cuo.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{callback.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{err.Error(), err} - } - return nil, err - } - return _node, nil -} diff --git a/model/ent/client.go b/model/ent/client.go index ae2c0071..53b87601 100644 --- a/model/ent/client.go +++ b/model/ent/client.go @@ -9,7 +9,6 @@ import ( "github.com/gitploy-io/gitploy/model/ent/migrate" - "github.com/gitploy-io/gitploy/model/ent/callback" "github.com/gitploy-io/gitploy/model/ent/chatuser" "github.com/gitploy-io/gitploy/model/ent/deployment" "github.com/gitploy-io/gitploy/model/ent/deploymentstatistics" @@ -32,8 +31,6 @@ type Client struct { config // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema - // Callback is the client for interacting with the Callback builders. - Callback *CallbackClient // ChatUser is the client for interacting with the ChatUser builders. ChatUser *ChatUserClient // Deployment is the client for interacting with the Deployment builders. @@ -69,7 +66,6 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) - c.Callback = NewCallbackClient(c.config) c.ChatUser = NewChatUserClient(c.config) c.Deployment = NewDeploymentClient(c.config) c.DeploymentStatistics = NewDeploymentStatisticsClient(c.config) @@ -114,7 +110,6 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { return &Tx{ ctx: ctx, config: cfg, - Callback: NewCallbackClient(cfg), ChatUser: NewChatUserClient(cfg), Deployment: NewDeploymentClient(cfg), DeploymentStatistics: NewDeploymentStatisticsClient(cfg), @@ -144,7 +139,6 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ config: cfg, - Callback: NewCallbackClient(cfg), ChatUser: NewChatUserClient(cfg), Deployment: NewDeploymentClient(cfg), DeploymentStatistics: NewDeploymentStatisticsClient(cfg), @@ -162,7 +156,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). -// Callback. +// ChatUser. // Query(). // Count(ctx) // @@ -185,7 +179,6 @@ func (c *Client) Close() error { // Use adds the mutation hooks to all the entity clients. // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { - c.Callback.Use(hooks...) c.ChatUser.Use(hooks...) c.Deployment.Use(hooks...) c.DeploymentStatistics.Use(hooks...) @@ -199,112 +192,6 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } -// CallbackClient is a client for the Callback schema. -type CallbackClient struct { - config -} - -// NewCallbackClient returns a client for the Callback from the given config. -func NewCallbackClient(c config) *CallbackClient { - return &CallbackClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `callback.Hooks(f(g(h())))`. -func (c *CallbackClient) Use(hooks ...Hook) { - c.hooks.Callback = append(c.hooks.Callback, hooks...) -} - -// Create returns a create builder for Callback. -func (c *CallbackClient) Create() *CallbackCreate { - mutation := newCallbackMutation(c.config, OpCreate) - return &CallbackCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Callback entities. -func (c *CallbackClient) CreateBulk(builders ...*CallbackCreate) *CallbackCreateBulk { - return &CallbackCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Callback. -func (c *CallbackClient) Update() *CallbackUpdate { - mutation := newCallbackMutation(c.config, OpUpdate) - return &CallbackUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *CallbackClient) UpdateOne(ca *Callback) *CallbackUpdateOne { - mutation := newCallbackMutation(c.config, OpUpdateOne, withCallback(ca)) - return &CallbackUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *CallbackClient) UpdateOneID(id int) *CallbackUpdateOne { - mutation := newCallbackMutation(c.config, OpUpdateOne, withCallbackID(id)) - return &CallbackUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Callback. -func (c *CallbackClient) Delete() *CallbackDelete { - mutation := newCallbackMutation(c.config, OpDelete) - return &CallbackDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a delete builder for the given entity. -func (c *CallbackClient) DeleteOne(ca *Callback) *CallbackDeleteOne { - return c.DeleteOneID(ca.ID) -} - -// DeleteOneID returns a delete builder for the given id. -func (c *CallbackClient) DeleteOneID(id int) *CallbackDeleteOne { - builder := c.Delete().Where(callback.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &CallbackDeleteOne{builder} -} - -// Query returns a query builder for Callback. -func (c *CallbackClient) Query() *CallbackQuery { - return &CallbackQuery{ - config: c.config, - } -} - -// Get returns a Callback entity by its id. -func (c *CallbackClient) Get(ctx context.Context, id int) (*Callback, error) { - return c.Query().Where(callback.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *CallbackClient) GetX(ctx context.Context, id int) *Callback { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryRepo queries the repo edge of a Callback. -func (c *CallbackClient) QueryRepo(ca *Callback) *RepoQuery { - query := &RepoQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := ca.ID - step := sqlgraph.NewStep( - sqlgraph.From(callback.Table, callback.FieldID, id), - sqlgraph.To(repo.Table, repo.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, callback.RepoTable, callback.RepoColumn), - ) - fromV = sqlgraph.Neighbors(ca.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *CallbackClient) Hooks() []Hook { - return c.hooks.Callback -} - // ChatUserClient is a client for the ChatUser schema. type ChatUserClient struct { config @@ -1398,22 +1285,6 @@ func (c *RepoClient) QueryDeployments(r *Repo) *DeploymentQuery { return query } -// QueryCallback queries the callback edge of a Repo. -func (c *RepoClient) QueryCallback(r *Repo) *CallbackQuery { - query := &CallbackQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := r.ID - step := sqlgraph.NewStep( - sqlgraph.From(repo.Table, repo.FieldID, id), - sqlgraph.To(callback.Table, callback.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, repo.CallbackTable, repo.CallbackColumn), - ) - fromV = sqlgraph.Neighbors(r.driver.Dialect(), step) - return fromV, nil - } - return query -} - // QueryLocks queries the locks edge of a Repo. func (c *RepoClient) QueryLocks(r *Repo) *LockQuery { query := &LockQuery{config: c.config} diff --git a/model/ent/config.go b/model/ent/config.go index 29f56d1a..5963351c 100644 --- a/model/ent/config.go +++ b/model/ent/config.go @@ -24,7 +24,6 @@ type config struct { // hooks per client, for fast access. type hooks struct { - Callback []ent.Hook ChatUser []ent.Hook Deployment []ent.Hook DeploymentStatistics []ent.Hook diff --git a/model/ent/ent.go b/model/ent/ent.go index 83a6c197..ec95b82b 100644 --- a/model/ent/ent.go +++ b/model/ent/ent.go @@ -8,7 +8,6 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" - "github.com/gitploy-io/gitploy/model/ent/callback" "github.com/gitploy-io/gitploy/model/ent/chatuser" "github.com/gitploy-io/gitploy/model/ent/deployment" "github.com/gitploy-io/gitploy/model/ent/deploymentstatistics" @@ -40,7 +39,6 @@ type OrderFunc func(*sql.Selector) // columnChecker returns a function indicates if the column exists in the given column. func columnChecker(table string) func(string) error { checks := map[string]func(string) bool{ - callback.Table: callback.ValidColumn, chatuser.Table: chatuser.ValidColumn, deployment.Table: deployment.ValidColumn, deploymentstatistics.Table: deploymentstatistics.ValidColumn, diff --git a/model/ent/hook/hook.go b/model/ent/hook/hook.go index 4015ef9c..9ff4377b 100644 --- a/model/ent/hook/hook.go +++ b/model/ent/hook/hook.go @@ -9,19 +9,6 @@ import ( "github.com/gitploy-io/gitploy/model/ent" ) -// The CallbackFunc type is an adapter to allow the use of ordinary -// function as Callback mutator. -type CallbackFunc func(context.Context, *ent.CallbackMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f CallbackFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.CallbackMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CallbackMutation", m) - } - return f(ctx, mv) -} - // The ChatUserFunc type is an adapter to allow the use of ordinary // function as ChatUser mutator. type ChatUserFunc func(context.Context, *ent.ChatUserMutation) (ent.Value, error) diff --git a/model/ent/migrate/schema.go b/model/ent/migrate/schema.go index 29066870..b3284b22 100644 --- a/model/ent/migrate/schema.go +++ b/model/ent/migrate/schema.go @@ -8,29 +8,6 @@ import ( ) var ( - // CallbacksColumns holds the columns for the "callbacks" table. - CallbacksColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "hash", Type: field.TypeString, Unique: true}, - {Name: "type", Type: field.TypeEnum, Enums: []string{"deploy", "rollback", "lock", "unlock"}}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "updated_at", Type: field.TypeTime}, - {Name: "repo_id", Type: field.TypeInt64, Nullable: true}, - } - // CallbacksTable holds the schema information for the "callbacks" table. - CallbacksTable = &schema.Table{ - Name: "callbacks", - Columns: CallbacksColumns, - PrimaryKey: []*schema.Column{CallbacksColumns[0]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "callbacks_repos_callback", - Columns: []*schema.Column{CallbacksColumns[5]}, - RefColumns: []*schema.Column{ReposColumns[0]}, - OnDelete: schema.Cascade, - }, - }, - } // ChatUsersColumns holds the columns for the "chat_users" table. ChatUsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeString}, @@ -423,7 +400,6 @@ var ( } // Tables holds all the tables in the schema. Tables = []*schema.Table{ - CallbacksTable, ChatUsersTable, DeploymentsTable, DeploymentStatisticsTable, @@ -439,7 +415,6 @@ var ( ) func init() { - CallbacksTable.ForeignKeys[0].RefTable = ReposTable ChatUsersTable.ForeignKeys[0].RefTable = UsersTable DeploymentsTable.ForeignKeys[0].RefTable = ReposTable DeploymentsTable.ForeignKeys[1].RefTable = UsersTable diff --git a/model/ent/mutation.go b/model/ent/mutation.go index 069ac145..26ce11f6 100644 --- a/model/ent/mutation.go +++ b/model/ent/mutation.go @@ -8,7 +8,6 @@ import ( "sync" "time" - "github.com/gitploy-io/gitploy/model/ent/callback" "github.com/gitploy-io/gitploy/model/ent/chatuser" "github.com/gitploy-io/gitploy/model/ent/deployment" "github.com/gitploy-io/gitploy/model/ent/deploymentstatistics" @@ -34,7 +33,6 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeCallback = "Callback" TypeChatUser = "ChatUser" TypeDeployment = "Deployment" TypeDeploymentStatistics = "DeploymentStatistics" @@ -48,572 +46,6 @@ const ( TypeUser = "User" ) -// CallbackMutation represents an operation that mutates the Callback nodes in the graph. -type CallbackMutation struct { - config - op Op - typ string - id *int - hash *string - _type *callback.Type - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - repo *int64 - clearedrepo bool - done bool - oldValue func(context.Context) (*Callback, error) - predicates []predicate.Callback -} - -var _ ent.Mutation = (*CallbackMutation)(nil) - -// callbackOption allows management of the mutation configuration using functional options. -type callbackOption func(*CallbackMutation) - -// newCallbackMutation creates new mutation for the Callback entity. -func newCallbackMutation(c config, op Op, opts ...callbackOption) *CallbackMutation { - m := &CallbackMutation{ - config: c, - op: op, - typ: TypeCallback, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withCallbackID sets the ID field of the mutation. -func withCallbackID(id int) callbackOption { - return func(m *CallbackMutation) { - var ( - err error - once sync.Once - value *Callback - ) - m.oldValue = func(ctx context.Context) (*Callback, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Callback.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withCallback sets the old Callback of the mutation. -func withCallback(node *Callback) callbackOption { - return func(m *CallbackMutation) { - m.oldValue = func(context.Context) (*Callback, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m CallbackMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m CallbackMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// 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 *CallbackMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// SetHash sets the "hash" field. -func (m *CallbackMutation) SetHash(s string) { - m.hash = &s -} - -// Hash returns the value of the "hash" field in the mutation. -func (m *CallbackMutation) Hash() (r string, exists bool) { - v := m.hash - if v == nil { - return - } - return *v, true -} - -// OldHash returns the old "hash" field's value of the Callback entity. -// If the Callback 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 *CallbackMutation) OldHash(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldHash is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldHash requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldHash: %w", err) - } - return oldValue.Hash, nil -} - -// ResetHash resets all changes to the "hash" field. -func (m *CallbackMutation) ResetHash() { - m.hash = nil -} - -// SetType sets the "type" field. -func (m *CallbackMutation) SetType(c callback.Type) { - m._type = &c -} - -// GetType returns the value of the "type" field in the mutation. -func (m *CallbackMutation) GetType() (r callback.Type, exists bool) { - v := m._type - if v == nil { - return - } - return *v, true -} - -// OldType returns the old "type" field's value of the Callback entity. -// If the Callback 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 *CallbackMutation) OldType(ctx context.Context) (v callback.Type, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldType requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldType: %w", err) - } - return oldValue.Type, nil -} - -// ResetType resets all changes to the "type" field. -func (m *CallbackMutation) ResetType() { - m._type = nil -} - -// SetCreatedAt sets the "created_at" field. -func (m *CallbackMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *CallbackMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the Callback entity. -// If the Callback 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 *CallbackMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *CallbackMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *CallbackMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *CallbackMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the Callback entity. -// If the Callback 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 *CallbackMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *CallbackMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetRepoID sets the "repo_id" field. -func (m *CallbackMutation) SetRepoID(i int64) { - m.repo = &i -} - -// RepoID returns the value of the "repo_id" field in the mutation. -func (m *CallbackMutation) RepoID() (r int64, exists bool) { - v := m.repo - if v == nil { - return - } - return *v, true -} - -// OldRepoID returns the old "repo_id" field's value of the Callback entity. -// If the Callback 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 *CallbackMutation) OldRepoID(ctx context.Context) (v int64, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRepoID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRepoID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldRepoID: %w", err) - } - return oldValue.RepoID, nil -} - -// ResetRepoID resets all changes to the "repo_id" field. -func (m *CallbackMutation) ResetRepoID() { - m.repo = nil -} - -// ClearRepo clears the "repo" edge to the Repo entity. -func (m *CallbackMutation) ClearRepo() { - m.clearedrepo = true -} - -// RepoCleared reports if the "repo" edge to the Repo entity was cleared. -func (m *CallbackMutation) RepoCleared() bool { - return m.clearedrepo -} - -// RepoIDs returns the "repo" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// RepoID instead. It exists only for internal usage by the builders. -func (m *CallbackMutation) RepoIDs() (ids []int64) { - if id := m.repo; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetRepo resets all changes to the "repo" edge. -func (m *CallbackMutation) ResetRepo() { - m.repo = nil - m.clearedrepo = false -} - -// Where appends a list predicates to the CallbackMutation builder. -func (m *CallbackMutation) Where(ps ...predicate.Callback) { - m.predicates = append(m.predicates, ps...) -} - -// Op returns the operation name. -func (m *CallbackMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (Callback). -func (m *CallbackMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *CallbackMutation) Fields() []string { - fields := make([]string, 0, 5) - if m.hash != nil { - fields = append(fields, callback.FieldHash) - } - if m._type != nil { - fields = append(fields, callback.FieldType) - } - if m.created_at != nil { - fields = append(fields, callback.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, callback.FieldUpdatedAt) - } - if m.repo != nil { - fields = append(fields, callback.FieldRepoID) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *CallbackMutation) Field(name string) (ent.Value, bool) { - switch name { - case callback.FieldHash: - return m.Hash() - case callback.FieldType: - return m.GetType() - case callback.FieldCreatedAt: - return m.CreatedAt() - case callback.FieldUpdatedAt: - return m.UpdatedAt() - case callback.FieldRepoID: - return m.RepoID() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *CallbackMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case callback.FieldHash: - return m.OldHash(ctx) - case callback.FieldType: - return m.OldType(ctx) - case callback.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case callback.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case callback.FieldRepoID: - return m.OldRepoID(ctx) - } - return nil, fmt.Errorf("unknown Callback field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *CallbackMutation) SetField(name string, value ent.Value) error { - switch name { - case callback.FieldHash: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetHash(v) - return nil - case callback.FieldType: - v, ok := value.(callback.Type) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetType(v) - return nil - case callback.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case callback.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - case callback.FieldRepoID: - v, ok := value.(int64) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetRepoID(v) - return nil - } - return fmt.Errorf("unknown Callback field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *CallbackMutation) AddedFields() []string { - var fields []string - return fields -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *CallbackMutation) AddedField(name string) (ent.Value, bool) { - switch name { - } - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *CallbackMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Callback numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *CallbackMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *CallbackMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *CallbackMutation) ClearField(name string) error { - return fmt.Errorf("unknown Callback nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *CallbackMutation) ResetField(name string) error { - switch name { - case callback.FieldHash: - m.ResetHash() - return nil - case callback.FieldType: - m.ResetType() - return nil - case callback.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case callback.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case callback.FieldRepoID: - m.ResetRepoID() - return nil - } - return fmt.Errorf("unknown Callback field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *CallbackMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.repo != nil { - edges = append(edges, callback.EdgeRepo) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *CallbackMutation) AddedIDs(name string) []ent.Value { - switch name { - case callback.EdgeRepo: - if id := m.repo; id != nil { - return []ent.Value{*id} - } - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *CallbackMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *CallbackMutation) RemovedIDs(name string) []ent.Value { - switch name { - } - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *CallbackMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedrepo { - edges = append(edges, callback.EdgeRepo) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *CallbackMutation) EdgeCleared(name string) bool { - switch name { - case callback.EdgeRepo: - return m.clearedrepo - } - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *CallbackMutation) ClearEdge(name string) error { - switch name { - case callback.EdgeRepo: - m.ClearRepo() - return nil - } - return fmt.Errorf("unknown Callback unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *CallbackMutation) ResetEdge(name string) error { - switch name { - case callback.EdgeRepo: - m.ResetRepo() - return nil - } - return fmt.Errorf("unknown Callback edge %s", name) -} - // ChatUserMutation represents an operation that mutates the ChatUser nodes in the graph. type ChatUserMutation struct { config @@ -7240,9 +6672,6 @@ type RepoMutation struct { deployments map[int]struct{} removeddeployments map[int]struct{} cleareddeployments bool - callback map[int]struct{} - removedcallback map[int]struct{} - clearedcallback bool locks map[int]struct{} removedlocks map[int]struct{} clearedlocks bool @@ -7869,60 +7298,6 @@ func (m *RepoMutation) ResetDeployments() { m.removeddeployments = nil } -// AddCallbackIDs adds the "callback" edge to the Callback entity by ids. -func (m *RepoMutation) AddCallbackIDs(ids ...int) { - if m.callback == nil { - m.callback = make(map[int]struct{}) - } - for i := range ids { - m.callback[ids[i]] = struct{}{} - } -} - -// ClearCallback clears the "callback" edge to the Callback entity. -func (m *RepoMutation) ClearCallback() { - m.clearedcallback = true -} - -// CallbackCleared reports if the "callback" edge to the Callback entity was cleared. -func (m *RepoMutation) CallbackCleared() bool { - return m.clearedcallback -} - -// RemoveCallbackIDs removes the "callback" edge to the Callback entity by IDs. -func (m *RepoMutation) RemoveCallbackIDs(ids ...int) { - if m.removedcallback == nil { - m.removedcallback = make(map[int]struct{}) - } - for i := range ids { - delete(m.callback, ids[i]) - m.removedcallback[ids[i]] = struct{}{} - } -} - -// RemovedCallback returns the removed IDs of the "callback" edge to the Callback entity. -func (m *RepoMutation) RemovedCallbackIDs() (ids []int) { - for id := range m.removedcallback { - ids = append(ids, id) - } - return -} - -// CallbackIDs returns the "callback" edge IDs in the mutation. -func (m *RepoMutation) CallbackIDs() (ids []int) { - for id := range m.callback { - ids = append(ids, id) - } - return -} - -// ResetCallback resets all changes to the "callback" edge. -func (m *RepoMutation) ResetCallback() { - m.callback = nil - m.clearedcallback = false - m.removedcallback = nil -} - // AddLockIDs adds the "locks" edge to the Lock entity by ids. func (m *RepoMutation) AddLockIDs(ids ...int) { if m.locks == nil { @@ -8364,16 +7739,13 @@ func (m *RepoMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *RepoMutation) AddedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 5) if m.perms != nil { edges = append(edges, repo.EdgePerms) } if m.deployments != nil { edges = append(edges, repo.EdgeDeployments) } - if m.callback != nil { - edges = append(edges, repo.EdgeCallback) - } if m.locks != nil { edges = append(edges, repo.EdgeLocks) } @@ -8402,12 +7774,6 @@ func (m *RepoMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids - case repo.EdgeCallback: - ids := make([]ent.Value, 0, len(m.callback)) - for id := range m.callback { - ids = append(ids, id) - } - return ids case repo.EdgeLocks: ids := make([]ent.Value, 0, len(m.locks)) for id := range m.locks { @@ -8430,16 +7796,13 @@ func (m *RepoMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *RepoMutation) RemovedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 5) if m.removedperms != nil { edges = append(edges, repo.EdgePerms) } if m.removeddeployments != nil { edges = append(edges, repo.EdgeDeployments) } - if m.removedcallback != nil { - edges = append(edges, repo.EdgeCallback) - } if m.removedlocks != nil { edges = append(edges, repo.EdgeLocks) } @@ -8465,12 +7828,6 @@ func (m *RepoMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids - case repo.EdgeCallback: - ids := make([]ent.Value, 0, len(m.removedcallback)) - for id := range m.removedcallback { - ids = append(ids, id) - } - return ids case repo.EdgeLocks: ids := make([]ent.Value, 0, len(m.removedlocks)) for id := range m.removedlocks { @@ -8489,16 +7846,13 @@ func (m *RepoMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *RepoMutation) ClearedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 5) if m.clearedperms { edges = append(edges, repo.EdgePerms) } if m.cleareddeployments { edges = append(edges, repo.EdgeDeployments) } - if m.clearedcallback { - edges = append(edges, repo.EdgeCallback) - } if m.clearedlocks { edges = append(edges, repo.EdgeLocks) } @@ -8519,8 +7873,6 @@ func (m *RepoMutation) EdgeCleared(name string) bool { return m.clearedperms case repo.EdgeDeployments: return m.cleareddeployments - case repo.EdgeCallback: - return m.clearedcallback case repo.EdgeLocks: return m.clearedlocks case repo.EdgeDeploymentStatistics: @@ -8552,9 +7904,6 @@ func (m *RepoMutation) ResetEdge(name string) error { case repo.EdgeDeployments: m.ResetDeployments() return nil - case repo.EdgeCallback: - m.ResetCallback() - return nil case repo.EdgeLocks: m.ResetLocks() return nil diff --git a/model/ent/predicate/predicate.go b/model/ent/predicate/predicate.go index f8a59094..c79c8f6c 100644 --- a/model/ent/predicate/predicate.go +++ b/model/ent/predicate/predicate.go @@ -6,9 +6,6 @@ import ( "entgo.io/ent/dialect/sql" ) -// Callback is the predicate function for callback builders. -type Callback func(*sql.Selector) - // ChatUser is the predicate function for chatuser builders. type ChatUser func(*sql.Selector) diff --git a/model/ent/repo.go b/model/ent/repo.go index 4c0b324a..b19bbf0c 100644 --- a/model/ent/repo.go +++ b/model/ent/repo.go @@ -48,8 +48,6 @@ type RepoEdges struct { Perms []*Perm `json:"perms,omitempty"` // Deployments holds the value of the deployments edge. Deployments []*Deployment `json:"deployments,omitempty"` - // Callback holds the value of the callback edge. - Callback []*Callback `json:"callback,omitempty"` // Locks holds the value of the locks edge. Locks []*Lock `json:"locks,omitempty"` // DeploymentStatistics holds the value of the deployment_statistics edge. @@ -58,7 +56,7 @@ type RepoEdges struct { Owner *User `json:"owner,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [6]bool + loadedTypes [5]bool } // PermsOrErr returns the Perms value or an error if the edge @@ -79,19 +77,10 @@ func (e RepoEdges) DeploymentsOrErr() ([]*Deployment, error) { return nil, &NotLoadedError{edge: "deployments"} } -// CallbackOrErr returns the Callback value or an error if the edge -// was not loaded in eager-loading. -func (e RepoEdges) CallbackOrErr() ([]*Callback, error) { - if e.loadedTypes[2] { - return e.Callback, nil - } - return nil, &NotLoadedError{edge: "callback"} -} - // LocksOrErr returns the Locks value or an error if the edge // was not loaded in eager-loading. func (e RepoEdges) LocksOrErr() ([]*Lock, error) { - if e.loadedTypes[3] { + if e.loadedTypes[2] { return e.Locks, nil } return nil, &NotLoadedError{edge: "locks"} @@ -100,7 +89,7 @@ func (e RepoEdges) LocksOrErr() ([]*Lock, error) { // DeploymentStatisticsOrErr returns the DeploymentStatistics value or an error if the edge // was not loaded in eager-loading. func (e RepoEdges) DeploymentStatisticsOrErr() ([]*DeploymentStatistics, error) { - if e.loadedTypes[4] { + if e.loadedTypes[3] { return e.DeploymentStatistics, nil } return nil, &NotLoadedError{edge: "deployment_statistics"} @@ -109,7 +98,7 @@ func (e RepoEdges) DeploymentStatisticsOrErr() ([]*DeploymentStatistics, error) // OwnerOrErr returns the Owner value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RepoEdges) OwnerOrErr() (*User, error) { - if e.loadedTypes[5] { + if e.loadedTypes[4] { if e.Owner == nil { // The edge owner was loaded in eager-loading, // but was not found. @@ -229,11 +218,6 @@ func (r *Repo) QueryDeployments() *DeploymentQuery { return (&RepoClient{config: r.config}).QueryDeployments(r) } -// QueryCallback queries the "callback" edge of the Repo entity. -func (r *Repo) QueryCallback() *CallbackQuery { - return (&RepoClient{config: r.config}).QueryCallback(r) -} - // QueryLocks queries the "locks" edge of the Repo entity. func (r *Repo) QueryLocks() *LockQuery { return (&RepoClient{config: r.config}).QueryLocks(r) diff --git a/model/ent/repo/repo.go b/model/ent/repo/repo.go index fd79c018..ac78e78e 100644 --- a/model/ent/repo/repo.go +++ b/model/ent/repo/repo.go @@ -35,8 +35,6 @@ const ( EdgePerms = "perms" // EdgeDeployments holds the string denoting the deployments edge name in mutations. EdgeDeployments = "deployments" - // EdgeCallback holds the string denoting the callback edge name in mutations. - EdgeCallback = "callback" // EdgeLocks holds the string denoting the locks edge name in mutations. EdgeLocks = "locks" // EdgeDeploymentStatistics holds the string denoting the deployment_statistics edge name in mutations. @@ -59,13 +57,6 @@ const ( DeploymentsInverseTable = "deployments" // DeploymentsColumn is the table column denoting the deployments relation/edge. DeploymentsColumn = "repo_id" - // CallbackTable is the table that holds the callback relation/edge. - CallbackTable = "callbacks" - // CallbackInverseTable is the table name for the Callback entity. - // It exists in this package in order to avoid circular dependency with the "callback" package. - CallbackInverseTable = "callbacks" - // CallbackColumn is the table column denoting the callback relation/edge. - CallbackColumn = "repo_id" // LocksTable is the table that holds the locks relation/edge. LocksTable = "locks" // LocksInverseTable is the table name for the Lock entity. diff --git a/model/ent/repo/where.go b/model/ent/repo/where.go index c86eac42..b432cfa4 100644 --- a/model/ent/repo/where.go +++ b/model/ent/repo/where.go @@ -1071,34 +1071,6 @@ func HasDeploymentsWith(preds ...predicate.Deployment) predicate.Repo { }) } -// HasCallback applies the HasEdge predicate on the "callback" edge. -func HasCallback() predicate.Repo { - return predicate.Repo(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(CallbackTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, CallbackTable, CallbackColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasCallbackWith applies the HasEdge predicate on the "callback" edge with a given conditions (other predicates). -func HasCallbackWith(preds ...predicate.Callback) predicate.Repo { - return predicate.Repo(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(CallbackInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, CallbackTable, CallbackColumn), - ) - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - // HasLocks applies the HasEdge predicate on the "locks" edge. func HasLocks() predicate.Repo { return predicate.Repo(func(s *sql.Selector) { diff --git a/model/ent/repo_create.go b/model/ent/repo_create.go index 684f38f4..89d384e0 100644 --- a/model/ent/repo_create.go +++ b/model/ent/repo_create.go @@ -10,7 +10,6 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/model/ent/callback" "github.com/gitploy-io/gitploy/model/ent/deployment" "github.com/gitploy-io/gitploy/model/ent/deploymentstatistics" "github.com/gitploy-io/gitploy/model/ent/lock" @@ -178,21 +177,6 @@ func (rc *RepoCreate) AddDeployments(d ...*Deployment) *RepoCreate { return rc.AddDeploymentIDs(ids...) } -// AddCallbackIDs adds the "callback" edge to the Callback entity by IDs. -func (rc *RepoCreate) AddCallbackIDs(ids ...int) *RepoCreate { - rc.mutation.AddCallbackIDs(ids...) - return rc -} - -// AddCallback adds the "callback" edges to the Callback entity. -func (rc *RepoCreate) AddCallback(c ...*Callback) *RepoCreate { - ids := make([]int, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return rc.AddCallbackIDs(ids...) -} - // AddLockIDs adds the "locks" edge to the Lock entity by IDs. func (rc *RepoCreate) AddLockIDs(ids ...int) *RepoCreate { rc.mutation.AddLockIDs(ids...) @@ -483,25 +467,6 @@ func (rc *RepoCreate) createSpec() (*Repo, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } - if nodes := rc.mutation.CallbackIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: repo.CallbackTable, - Columns: []string{repo.CallbackColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } if nodes := rc.mutation.LocksIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/model/ent/repo_query.go b/model/ent/repo_query.go index d248f19a..07266095 100644 --- a/model/ent/repo_query.go +++ b/model/ent/repo_query.go @@ -13,7 +13,6 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/model/ent/callback" "github.com/gitploy-io/gitploy/model/ent/deployment" "github.com/gitploy-io/gitploy/model/ent/deploymentstatistics" "github.com/gitploy-io/gitploy/model/ent/lock" @@ -35,7 +34,6 @@ type RepoQuery struct { // eager-loading edges. withPerms *PermQuery withDeployments *DeploymentQuery - withCallback *CallbackQuery withLocks *LockQuery withDeploymentStatistics *DeploymentStatisticsQuery withOwner *UserQuery @@ -120,28 +118,6 @@ func (rq *RepoQuery) QueryDeployments() *DeploymentQuery { return query } -// QueryCallback chains the current query on the "callback" edge. -func (rq *RepoQuery) QueryCallback() *CallbackQuery { - query := &CallbackQuery{config: rq.config} - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := rq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := rq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(repo.Table, repo.FieldID, selector), - sqlgraph.To(callback.Table, callback.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, repo.CallbackTable, repo.CallbackColumn), - ) - fromU = sqlgraph.SetNeighbors(rq.driver.Dialect(), step) - return fromU, nil - } - return query -} - // QueryLocks chains the current query on the "locks" edge. func (rq *RepoQuery) QueryLocks() *LockQuery { query := &LockQuery{config: rq.config} @@ -391,7 +367,6 @@ func (rq *RepoQuery) Clone() *RepoQuery { predicates: append([]predicate.Repo{}, rq.predicates...), withPerms: rq.withPerms.Clone(), withDeployments: rq.withDeployments.Clone(), - withCallback: rq.withCallback.Clone(), withLocks: rq.withLocks.Clone(), withDeploymentStatistics: rq.withDeploymentStatistics.Clone(), withOwner: rq.withOwner.Clone(), @@ -423,17 +398,6 @@ func (rq *RepoQuery) WithDeployments(opts ...func(*DeploymentQuery)) *RepoQuery return rq } -// WithCallback tells the query-builder to eager-load the nodes that are connected to -// the "callback" edge. The optional arguments are used to configure the query builder of the edge. -func (rq *RepoQuery) WithCallback(opts ...func(*CallbackQuery)) *RepoQuery { - query := &CallbackQuery{config: rq.config} - for _, opt := range opts { - opt(query) - } - rq.withCallback = query - return rq -} - // WithLocks tells the query-builder to eager-load the nodes that are connected to // the "locks" edge. The optional arguments are used to configure the query builder of the edge. func (rq *RepoQuery) WithLocks(opts ...func(*LockQuery)) *RepoQuery { @@ -532,10 +496,9 @@ func (rq *RepoQuery) sqlAll(ctx context.Context) ([]*Repo, error) { var ( nodes = []*Repo{} _spec = rq.querySpec() - loadedTypes = [6]bool{ + loadedTypes = [5]bool{ rq.withPerms != nil, rq.withDeployments != nil, - rq.withCallback != nil, rq.withLocks != nil, rq.withDeploymentStatistics != nil, rq.withOwner != nil, @@ -614,31 +577,6 @@ func (rq *RepoQuery) sqlAll(ctx context.Context) ([]*Repo, error) { } } - if query := rq.withCallback; query != nil { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int64]*Repo) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.Callback = []*Callback{} - } - query.Where(predicate.Callback(func(s *sql.Selector) { - s.Where(sql.InValues(repo.CallbackColumn, fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return nil, err - } - for _, n := range neighbors { - fk := n.RepoID - node, ok := nodeids[fk] - if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "repo_id" returned %v for node %v`, fk, n.ID) - } - node.Edges.Callback = append(node.Edges.Callback, n) - } - } - if query := rq.withLocks; query != nil { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[int64]*Repo) diff --git a/model/ent/repo_update.go b/model/ent/repo_update.go index 1d74e52d..fcb4fe10 100644 --- a/model/ent/repo_update.go +++ b/model/ent/repo_update.go @@ -10,7 +10,6 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/model/ent/callback" "github.com/gitploy-io/gitploy/model/ent/deployment" "github.com/gitploy-io/gitploy/model/ent/deploymentstatistics" "github.com/gitploy-io/gitploy/model/ent/lock" @@ -196,21 +195,6 @@ func (ru *RepoUpdate) AddDeployments(d ...*Deployment) *RepoUpdate { return ru.AddDeploymentIDs(ids...) } -// AddCallbackIDs adds the "callback" edge to the Callback entity by IDs. -func (ru *RepoUpdate) AddCallbackIDs(ids ...int) *RepoUpdate { - ru.mutation.AddCallbackIDs(ids...) - return ru -} - -// AddCallback adds the "callback" edges to the Callback entity. -func (ru *RepoUpdate) AddCallback(c ...*Callback) *RepoUpdate { - ids := make([]int, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return ru.AddCallbackIDs(ids...) -} - // AddLockIDs adds the "locks" edge to the Lock entity by IDs. func (ru *RepoUpdate) AddLockIDs(ids ...int) *RepoUpdate { ru.mutation.AddLockIDs(ids...) @@ -293,27 +277,6 @@ func (ru *RepoUpdate) RemoveDeployments(d ...*Deployment) *RepoUpdate { return ru.RemoveDeploymentIDs(ids...) } -// ClearCallback clears all "callback" edges to the Callback entity. -func (ru *RepoUpdate) ClearCallback() *RepoUpdate { - ru.mutation.ClearCallback() - return ru -} - -// RemoveCallbackIDs removes the "callback" edge to Callback entities by IDs. -func (ru *RepoUpdate) RemoveCallbackIDs(ids ...int) *RepoUpdate { - ru.mutation.RemoveCallbackIDs(ids...) - return ru -} - -// RemoveCallback removes "callback" edges to Callback entities. -func (ru *RepoUpdate) RemoveCallback(c ...*Callback) *RepoUpdate { - ids := make([]int, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return ru.RemoveCallbackIDs(ids...) -} - // ClearLocks clears all "locks" edges to the Lock entity. func (ru *RepoUpdate) ClearLocks() *RepoUpdate { ru.mutation.ClearLocks() @@ -633,60 +596,6 @@ func (ru *RepoUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if ru.mutation.CallbackCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: repo.CallbackTable, - Columns: []string{repo.CallbackColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := ru.mutation.RemovedCallbackIDs(); len(nodes) > 0 && !ru.mutation.CallbackCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: repo.CallbackTable, - Columns: []string{repo.CallbackColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := ru.mutation.CallbackIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: repo.CallbackTable, - Columns: []string{repo.CallbackColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } if ru.mutation.LocksCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, @@ -1012,21 +921,6 @@ func (ruo *RepoUpdateOne) AddDeployments(d ...*Deployment) *RepoUpdateOne { return ruo.AddDeploymentIDs(ids...) } -// AddCallbackIDs adds the "callback" edge to the Callback entity by IDs. -func (ruo *RepoUpdateOne) AddCallbackIDs(ids ...int) *RepoUpdateOne { - ruo.mutation.AddCallbackIDs(ids...) - return ruo -} - -// AddCallback adds the "callback" edges to the Callback entity. -func (ruo *RepoUpdateOne) AddCallback(c ...*Callback) *RepoUpdateOne { - ids := make([]int, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return ruo.AddCallbackIDs(ids...) -} - // AddLockIDs adds the "locks" edge to the Lock entity by IDs. func (ruo *RepoUpdateOne) AddLockIDs(ids ...int) *RepoUpdateOne { ruo.mutation.AddLockIDs(ids...) @@ -1109,27 +1003,6 @@ func (ruo *RepoUpdateOne) RemoveDeployments(d ...*Deployment) *RepoUpdateOne { return ruo.RemoveDeploymentIDs(ids...) } -// ClearCallback clears all "callback" edges to the Callback entity. -func (ruo *RepoUpdateOne) ClearCallback() *RepoUpdateOne { - ruo.mutation.ClearCallback() - return ruo -} - -// RemoveCallbackIDs removes the "callback" edge to Callback entities by IDs. -func (ruo *RepoUpdateOne) RemoveCallbackIDs(ids ...int) *RepoUpdateOne { - ruo.mutation.RemoveCallbackIDs(ids...) - return ruo -} - -// RemoveCallback removes "callback" edges to Callback entities. -func (ruo *RepoUpdateOne) RemoveCallback(c ...*Callback) *RepoUpdateOne { - ids := make([]int, len(c)) - for i := range c { - ids[i] = c[i].ID - } - return ruo.RemoveCallbackIDs(ids...) -} - // ClearLocks clears all "locks" edges to the Lock entity. func (ruo *RepoUpdateOne) ClearLocks() *RepoUpdateOne { ruo.mutation.ClearLocks() @@ -1473,60 +1346,6 @@ func (ruo *RepoUpdateOne) sqlSave(ctx context.Context) (_node *Repo, err error) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if ruo.mutation.CallbackCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: repo.CallbackTable, - Columns: []string{repo.CallbackColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := ruo.mutation.RemovedCallbackIDs(); len(nodes) > 0 && !ruo.mutation.CallbackCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: repo.CallbackTable, - Columns: []string{repo.CallbackColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := ruo.mutation.CallbackIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: false, - Table: repo.CallbackTable, - Columns: []string{repo.CallbackColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: callback.FieldID, - }, - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } if ruo.mutation.LocksCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, diff --git a/model/ent/runtime.go b/model/ent/runtime.go index 40b77e8c..43d4ffe0 100644 --- a/model/ent/runtime.go +++ b/model/ent/runtime.go @@ -5,7 +5,6 @@ package ent import ( "time" - "github.com/gitploy-io/gitploy/model/ent/callback" "github.com/gitploy-io/gitploy/model/ent/chatuser" "github.com/gitploy-io/gitploy/model/ent/deployment" "github.com/gitploy-io/gitploy/model/ent/deploymentstatistics" @@ -23,22 +22,6 @@ import ( // (default values, validators, hooks and policies) and stitches it // to their package variables. func init() { - callbackFields := schema.Callback{}.Fields() - _ = callbackFields - // callbackDescHash is the schema descriptor for hash field. - callbackDescHash := callbackFields[0].Descriptor() - // callback.DefaultHash holds the default value on creation for the hash field. - callback.DefaultHash = callbackDescHash.Default.(func() string) - // callbackDescCreatedAt is the schema descriptor for created_at field. - callbackDescCreatedAt := callbackFields[2].Descriptor() - // callback.DefaultCreatedAt holds the default value on creation for the created_at field. - callback.DefaultCreatedAt = callbackDescCreatedAt.Default.(func() time.Time) - // callbackDescUpdatedAt is the schema descriptor for updated_at field. - callbackDescUpdatedAt := callbackFields[3].Descriptor() - // callback.DefaultUpdatedAt holds the default value on creation for the updated_at field. - callback.DefaultUpdatedAt = callbackDescUpdatedAt.Default.(func() time.Time) - // callback.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. - callback.UpdateDefaultUpdatedAt = callbackDescUpdatedAt.UpdateDefault.(func() time.Time) chatuserFields := schema.ChatUser{}.Fields() _ = chatuserFields // chatuserDescCreatedAt is the schema descriptor for created_at field. diff --git a/model/ent/schema/callback.go b/model/ent/schema/callback.go deleted file mode 100644 index 2c364b5e..00000000 --- a/model/ent/schema/callback.go +++ /dev/null @@ -1,47 +0,0 @@ -package schema - -import ( - "entgo.io/ent" - "entgo.io/ent/schema/edge" - "entgo.io/ent/schema/field" -) - -// Callback holds the schema definition for the Callback entity. -type Callback struct { - ent.Schema -} - -// Fields of the Callback. -func (Callback) Fields() []ent.Field { - return []ent.Field{ - field.String("hash"). - Immutable(). - Unique(). - DefaultFunc(generateHash). - Sensitive(), - field.Enum("type"). - Values( - "deploy", - "rollback", - "lock", - "unlock", - ), - field.Time("created_at"). - Default(nowUTC), - field.Time("updated_at"). - Default(nowUTC). - UpdateDefault(nowUTC), - field.Int64("repo_id"), - } -} - -// Edges of the Callback. -func (Callback) Edges() []ent.Edge { - return []ent.Edge{ - edge.From("repo", Repo.Type). - Ref("callback"). - Field("repo_id"). - Unique(). - Required(), - } -} diff --git a/model/ent/schema/repo.go b/model/ent/schema/repo.go index 9ddbcbf3..0888b86c 100644 --- a/model/ent/schema/repo.go +++ b/model/ent/schema/repo.go @@ -52,10 +52,6 @@ func (Repo) Edges() []ent.Edge { Annotations(entsql.Annotation{ OnDelete: entsql.Cascade, }), - edge.To("callback", Callback.Type). - Annotations(entsql.Annotation{ - OnDelete: entsql.Cascade, - }), edge.To("locks", Lock.Type). Annotations(entsql.Annotation{ OnDelete: entsql.Cascade, diff --git a/model/ent/tx.go b/model/ent/tx.go index dce19ed1..0eb8607e 100644 --- a/model/ent/tx.go +++ b/model/ent/tx.go @@ -12,8 +12,6 @@ import ( // Tx is a transactional client that is created by calling Client.Tx(). type Tx struct { config - // Callback is the client for interacting with the Callback builders. - Callback *CallbackClient // ChatUser is the client for interacting with the ChatUser builders. ChatUser *ChatUserClient // Deployment is the client for interacting with the Deployment builders. @@ -171,7 +169,6 @@ func (tx *Tx) Client() *Client { } func (tx *Tx) init() { - tx.Callback = NewCallbackClient(tx.config) tx.ChatUser = NewChatUserClient(tx.config) tx.Deployment = NewDeploymentClient(tx.config) tx.DeploymentStatistics = NewDeploymentStatisticsClient(tx.config) @@ -192,7 +189,7 @@ func (tx *Tx) init() { // of them in order to commit or rollback the transaction. // // If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: Callback.QueryXXX(), the query will be executed +// applies a query, for example: ChatUser.QueryXXX(), the query will be executed // through the driver which created this transaction. // // Note that txDriver is not goroutine safe.