github.com/iasthc/atlas/cmd/atlas@v0.0.0-20230523071841-73246df3f88d/internal/migrate/ent/mutation.go (about) 1 // Copyright 2021-present The Atlas Authors. All rights reserved. 2 // This source code is licensed under the Apache 2.0 license found 3 // in the LICENSE file in the root directory of this source tree. 4 5 // Code generated by entc, DO NOT EDIT. 6 7 package ent 8 9 import ( 10 "context" 11 "errors" 12 "fmt" 13 "sync" 14 "time" 15 16 "github.com/iasthc/atlas/cmd/atlas/internal/migrate/ent/predicate" 17 "github.com/iasthc/atlas/cmd/atlas/internal/migrate/ent/revision" 18 "github.com/iasthc/atlas/sql/migrate" 19 "entgo.io/ent" 20 "entgo.io/ent/dialect/sql" 21 ) 22 23 const ( 24 // Operation types. 25 OpCreate = ent.OpCreate 26 OpDelete = ent.OpDelete 27 OpDeleteOne = ent.OpDeleteOne 28 OpUpdate = ent.OpUpdate 29 OpUpdateOne = ent.OpUpdateOne 30 31 // Node types. 32 TypeRevision = "Revision" 33 ) 34 35 // RevisionMutation represents an operation that mutates the Revision nodes in the graph. 36 type RevisionMutation struct { 37 config 38 op Op 39 typ string 40 id *string 41 description *string 42 _type *migrate.RevisionType 43 add_type *migrate.RevisionType 44 applied *int 45 addapplied *int 46 total *int 47 addtotal *int 48 executed_at *time.Time 49 execution_time *time.Duration 50 addexecution_time *time.Duration 51 error *string 52 error_stmt *string 53 hash *string 54 partial_hashes *[]string 55 appendpartial_hashes []string 56 operator_version *string 57 clearedFields map[string]struct{} 58 done bool 59 oldValue func(context.Context) (*Revision, error) 60 predicates []predicate.Revision 61 } 62 63 var _ ent.Mutation = (*RevisionMutation)(nil) 64 65 // revisionOption allows management of the mutation configuration using functional options. 66 type revisionOption func(*RevisionMutation) 67 68 // newRevisionMutation creates new mutation for the Revision entity. 69 func newRevisionMutation(c config, op Op, opts ...revisionOption) *RevisionMutation { 70 m := &RevisionMutation{ 71 config: c, 72 op: op, 73 typ: TypeRevision, 74 clearedFields: make(map[string]struct{}), 75 } 76 for _, opt := range opts { 77 opt(m) 78 } 79 return m 80 } 81 82 // withRevisionID sets the ID field of the mutation. 83 func withRevisionID(id string) revisionOption { 84 return func(m *RevisionMutation) { 85 var ( 86 err error 87 once sync.Once 88 value *Revision 89 ) 90 m.oldValue = func(ctx context.Context) (*Revision, error) { 91 once.Do(func() { 92 if m.done { 93 err = errors.New("querying old values post mutation is not allowed") 94 } else { 95 value, err = m.Client().Revision.Get(ctx, id) 96 } 97 }) 98 return value, err 99 } 100 m.id = &id 101 } 102 } 103 104 // withRevision sets the old Revision of the mutation. 105 func withRevision(node *Revision) revisionOption { 106 return func(m *RevisionMutation) { 107 m.oldValue = func(context.Context) (*Revision, error) { 108 return node, nil 109 } 110 m.id = &node.ID 111 } 112 } 113 114 // Client returns a new `ent.Client` from the mutation. If the mutation was 115 // executed in a transaction (ent.Tx), a transactional client is returned. 116 func (m RevisionMutation) Client() *Client { 117 client := &Client{config: m.config} 118 client.init() 119 return client 120 } 121 122 // Tx returns an `ent.Tx` for mutations that were executed in transactions; 123 // it returns an error otherwise. 124 func (m RevisionMutation) Tx() (*Tx, error) { 125 if _, ok := m.driver.(*txDriver); !ok { 126 return nil, errors.New("ent: mutation is not running in a transaction") 127 } 128 tx := &Tx{config: m.config} 129 tx.init() 130 return tx, nil 131 } 132 133 // SetID sets the value of the id field. Note that this 134 // operation is only accepted on creation of Revision entities. 135 func (m *RevisionMutation) SetID(id string) { 136 m.id = &id 137 } 138 139 // ID returns the ID value in the mutation. Note that the ID is only available 140 // if it was provided to the builder or after it was returned from the database. 141 func (m *RevisionMutation) ID() (id string, exists bool) { 142 if m.id == nil { 143 return 144 } 145 return *m.id, true 146 } 147 148 // IDs queries the database and returns the entity ids that match the mutation's predicate. 149 // That means, if the mutation is applied within a transaction with an isolation level such 150 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated 151 // or updated by the mutation. 152 func (m *RevisionMutation) IDs(ctx context.Context) ([]string, error) { 153 switch { 154 case m.op.Is(OpUpdateOne | OpDeleteOne): 155 id, exists := m.ID() 156 if exists { 157 return []string{id}, nil 158 } 159 fallthrough 160 case m.op.Is(OpUpdate | OpDelete): 161 return m.Client().Revision.Query().Where(m.predicates...).IDs(ctx) 162 default: 163 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) 164 } 165 } 166 167 // SetDescription sets the "description" field. 168 func (m *RevisionMutation) SetDescription(s string) { 169 m.description = &s 170 } 171 172 // Description returns the value of the "description" field in the mutation. 173 func (m *RevisionMutation) Description() (r string, exists bool) { 174 v := m.description 175 if v == nil { 176 return 177 } 178 return *v, true 179 } 180 181 // OldDescription returns the old "description" field's value of the Revision entity. 182 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 183 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 184 func (m *RevisionMutation) OldDescription(ctx context.Context) (v string, err error) { 185 if !m.op.Is(OpUpdateOne) { 186 return v, errors.New("OldDescription is only allowed on UpdateOne operations") 187 } 188 if m.id == nil || m.oldValue == nil { 189 return v, errors.New("OldDescription requires an ID field in the mutation") 190 } 191 oldValue, err := m.oldValue(ctx) 192 if err != nil { 193 return v, fmt.Errorf("querying old value for OldDescription: %w", err) 194 } 195 return oldValue.Description, nil 196 } 197 198 // ResetDescription resets all changes to the "description" field. 199 func (m *RevisionMutation) ResetDescription() { 200 m.description = nil 201 } 202 203 // SetType sets the "type" field. 204 func (m *RevisionMutation) SetType(mt migrate.RevisionType) { 205 m._type = &mt 206 m.add_type = nil 207 } 208 209 // GetType returns the value of the "type" field in the mutation. 210 func (m *RevisionMutation) GetType() (r migrate.RevisionType, exists bool) { 211 v := m._type 212 if v == nil { 213 return 214 } 215 return *v, true 216 } 217 218 // OldType returns the old "type" field's value of the Revision entity. 219 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 220 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 221 func (m *RevisionMutation) OldType(ctx context.Context) (v migrate.RevisionType, err error) { 222 if !m.op.Is(OpUpdateOne) { 223 return v, errors.New("OldType is only allowed on UpdateOne operations") 224 } 225 if m.id == nil || m.oldValue == nil { 226 return v, errors.New("OldType requires an ID field in the mutation") 227 } 228 oldValue, err := m.oldValue(ctx) 229 if err != nil { 230 return v, fmt.Errorf("querying old value for OldType: %w", err) 231 } 232 return oldValue.Type, nil 233 } 234 235 // AddType adds mt to the "type" field. 236 func (m *RevisionMutation) AddType(mt migrate.RevisionType) { 237 if m.add_type != nil { 238 *m.add_type += mt 239 } else { 240 m.add_type = &mt 241 } 242 } 243 244 // AddedType returns the value that was added to the "type" field in this mutation. 245 func (m *RevisionMutation) AddedType() (r migrate.RevisionType, exists bool) { 246 v := m.add_type 247 if v == nil { 248 return 249 } 250 return *v, true 251 } 252 253 // ResetType resets all changes to the "type" field. 254 func (m *RevisionMutation) ResetType() { 255 m._type = nil 256 m.add_type = nil 257 } 258 259 // SetApplied sets the "applied" field. 260 func (m *RevisionMutation) SetApplied(i int) { 261 m.applied = &i 262 m.addapplied = nil 263 } 264 265 // Applied returns the value of the "applied" field in the mutation. 266 func (m *RevisionMutation) Applied() (r int, exists bool) { 267 v := m.applied 268 if v == nil { 269 return 270 } 271 return *v, true 272 } 273 274 // OldApplied returns the old "applied" field's value of the Revision entity. 275 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 276 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 277 func (m *RevisionMutation) OldApplied(ctx context.Context) (v int, err error) { 278 if !m.op.Is(OpUpdateOne) { 279 return v, errors.New("OldApplied is only allowed on UpdateOne operations") 280 } 281 if m.id == nil || m.oldValue == nil { 282 return v, errors.New("OldApplied requires an ID field in the mutation") 283 } 284 oldValue, err := m.oldValue(ctx) 285 if err != nil { 286 return v, fmt.Errorf("querying old value for OldApplied: %w", err) 287 } 288 return oldValue.Applied, nil 289 } 290 291 // AddApplied adds i to the "applied" field. 292 func (m *RevisionMutation) AddApplied(i int) { 293 if m.addapplied != nil { 294 *m.addapplied += i 295 } else { 296 m.addapplied = &i 297 } 298 } 299 300 // AddedApplied returns the value that was added to the "applied" field in this mutation. 301 func (m *RevisionMutation) AddedApplied() (r int, exists bool) { 302 v := m.addapplied 303 if v == nil { 304 return 305 } 306 return *v, true 307 } 308 309 // ResetApplied resets all changes to the "applied" field. 310 func (m *RevisionMutation) ResetApplied() { 311 m.applied = nil 312 m.addapplied = nil 313 } 314 315 // SetTotal sets the "total" field. 316 func (m *RevisionMutation) SetTotal(i int) { 317 m.total = &i 318 m.addtotal = nil 319 } 320 321 // Total returns the value of the "total" field in the mutation. 322 func (m *RevisionMutation) Total() (r int, exists bool) { 323 v := m.total 324 if v == nil { 325 return 326 } 327 return *v, true 328 } 329 330 // OldTotal returns the old "total" field's value of the Revision entity. 331 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 332 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 333 func (m *RevisionMutation) OldTotal(ctx context.Context) (v int, err error) { 334 if !m.op.Is(OpUpdateOne) { 335 return v, errors.New("OldTotal is only allowed on UpdateOne operations") 336 } 337 if m.id == nil || m.oldValue == nil { 338 return v, errors.New("OldTotal requires an ID field in the mutation") 339 } 340 oldValue, err := m.oldValue(ctx) 341 if err != nil { 342 return v, fmt.Errorf("querying old value for OldTotal: %w", err) 343 } 344 return oldValue.Total, nil 345 } 346 347 // AddTotal adds i to the "total" field. 348 func (m *RevisionMutation) AddTotal(i int) { 349 if m.addtotal != nil { 350 *m.addtotal += i 351 } else { 352 m.addtotal = &i 353 } 354 } 355 356 // AddedTotal returns the value that was added to the "total" field in this mutation. 357 func (m *RevisionMutation) AddedTotal() (r int, exists bool) { 358 v := m.addtotal 359 if v == nil { 360 return 361 } 362 return *v, true 363 } 364 365 // ResetTotal resets all changes to the "total" field. 366 func (m *RevisionMutation) ResetTotal() { 367 m.total = nil 368 m.addtotal = nil 369 } 370 371 // SetExecutedAt sets the "executed_at" field. 372 func (m *RevisionMutation) SetExecutedAt(t time.Time) { 373 m.executed_at = &t 374 } 375 376 // ExecutedAt returns the value of the "executed_at" field in the mutation. 377 func (m *RevisionMutation) ExecutedAt() (r time.Time, exists bool) { 378 v := m.executed_at 379 if v == nil { 380 return 381 } 382 return *v, true 383 } 384 385 // OldExecutedAt returns the old "executed_at" field's value of the Revision entity. 386 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 387 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 388 func (m *RevisionMutation) OldExecutedAt(ctx context.Context) (v time.Time, err error) { 389 if !m.op.Is(OpUpdateOne) { 390 return v, errors.New("OldExecutedAt is only allowed on UpdateOne operations") 391 } 392 if m.id == nil || m.oldValue == nil { 393 return v, errors.New("OldExecutedAt requires an ID field in the mutation") 394 } 395 oldValue, err := m.oldValue(ctx) 396 if err != nil { 397 return v, fmt.Errorf("querying old value for OldExecutedAt: %w", err) 398 } 399 return oldValue.ExecutedAt, nil 400 } 401 402 // ResetExecutedAt resets all changes to the "executed_at" field. 403 func (m *RevisionMutation) ResetExecutedAt() { 404 m.executed_at = nil 405 } 406 407 // SetExecutionTime sets the "execution_time" field. 408 func (m *RevisionMutation) SetExecutionTime(t time.Duration) { 409 m.execution_time = &t 410 m.addexecution_time = nil 411 } 412 413 // ExecutionTime returns the value of the "execution_time" field in the mutation. 414 func (m *RevisionMutation) ExecutionTime() (r time.Duration, exists bool) { 415 v := m.execution_time 416 if v == nil { 417 return 418 } 419 return *v, true 420 } 421 422 // OldExecutionTime returns the old "execution_time" field's value of the Revision entity. 423 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 424 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 425 func (m *RevisionMutation) OldExecutionTime(ctx context.Context) (v time.Duration, err error) { 426 if !m.op.Is(OpUpdateOne) { 427 return v, errors.New("OldExecutionTime is only allowed on UpdateOne operations") 428 } 429 if m.id == nil || m.oldValue == nil { 430 return v, errors.New("OldExecutionTime requires an ID field in the mutation") 431 } 432 oldValue, err := m.oldValue(ctx) 433 if err != nil { 434 return v, fmt.Errorf("querying old value for OldExecutionTime: %w", err) 435 } 436 return oldValue.ExecutionTime, nil 437 } 438 439 // AddExecutionTime adds t to the "execution_time" field. 440 func (m *RevisionMutation) AddExecutionTime(t time.Duration) { 441 if m.addexecution_time != nil { 442 *m.addexecution_time += t 443 } else { 444 m.addexecution_time = &t 445 } 446 } 447 448 // AddedExecutionTime returns the value that was added to the "execution_time" field in this mutation. 449 func (m *RevisionMutation) AddedExecutionTime() (r time.Duration, exists bool) { 450 v := m.addexecution_time 451 if v == nil { 452 return 453 } 454 return *v, true 455 } 456 457 // ResetExecutionTime resets all changes to the "execution_time" field. 458 func (m *RevisionMutation) ResetExecutionTime() { 459 m.execution_time = nil 460 m.addexecution_time = nil 461 } 462 463 // SetError sets the "error" field. 464 func (m *RevisionMutation) SetError(s string) { 465 m.error = &s 466 } 467 468 // Error returns the value of the "error" field in the mutation. 469 func (m *RevisionMutation) Error() (r string, exists bool) { 470 v := m.error 471 if v == nil { 472 return 473 } 474 return *v, true 475 } 476 477 // OldError returns the old "error" field's value of the Revision entity. 478 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 479 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 480 func (m *RevisionMutation) OldError(ctx context.Context) (v string, err error) { 481 if !m.op.Is(OpUpdateOne) { 482 return v, errors.New("OldError is only allowed on UpdateOne operations") 483 } 484 if m.id == nil || m.oldValue == nil { 485 return v, errors.New("OldError requires an ID field in the mutation") 486 } 487 oldValue, err := m.oldValue(ctx) 488 if err != nil { 489 return v, fmt.Errorf("querying old value for OldError: %w", err) 490 } 491 return oldValue.Error, nil 492 } 493 494 // ClearError clears the value of the "error" field. 495 func (m *RevisionMutation) ClearError() { 496 m.error = nil 497 m.clearedFields[revision.FieldError] = struct{}{} 498 } 499 500 // ErrorCleared returns if the "error" field was cleared in this mutation. 501 func (m *RevisionMutation) ErrorCleared() bool { 502 _, ok := m.clearedFields[revision.FieldError] 503 return ok 504 } 505 506 // ResetError resets all changes to the "error" field. 507 func (m *RevisionMutation) ResetError() { 508 m.error = nil 509 delete(m.clearedFields, revision.FieldError) 510 } 511 512 // SetErrorStmt sets the "error_stmt" field. 513 func (m *RevisionMutation) SetErrorStmt(s string) { 514 m.error_stmt = &s 515 } 516 517 // ErrorStmt returns the value of the "error_stmt" field in the mutation. 518 func (m *RevisionMutation) ErrorStmt() (r string, exists bool) { 519 v := m.error_stmt 520 if v == nil { 521 return 522 } 523 return *v, true 524 } 525 526 // OldErrorStmt returns the old "error_stmt" field's value of the Revision entity. 527 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 528 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 529 func (m *RevisionMutation) OldErrorStmt(ctx context.Context) (v string, err error) { 530 if !m.op.Is(OpUpdateOne) { 531 return v, errors.New("OldErrorStmt is only allowed on UpdateOne operations") 532 } 533 if m.id == nil || m.oldValue == nil { 534 return v, errors.New("OldErrorStmt requires an ID field in the mutation") 535 } 536 oldValue, err := m.oldValue(ctx) 537 if err != nil { 538 return v, fmt.Errorf("querying old value for OldErrorStmt: %w", err) 539 } 540 return oldValue.ErrorStmt, nil 541 } 542 543 // ClearErrorStmt clears the value of the "error_stmt" field. 544 func (m *RevisionMutation) ClearErrorStmt() { 545 m.error_stmt = nil 546 m.clearedFields[revision.FieldErrorStmt] = struct{}{} 547 } 548 549 // ErrorStmtCleared returns if the "error_stmt" field was cleared in this mutation. 550 func (m *RevisionMutation) ErrorStmtCleared() bool { 551 _, ok := m.clearedFields[revision.FieldErrorStmt] 552 return ok 553 } 554 555 // ResetErrorStmt resets all changes to the "error_stmt" field. 556 func (m *RevisionMutation) ResetErrorStmt() { 557 m.error_stmt = nil 558 delete(m.clearedFields, revision.FieldErrorStmt) 559 } 560 561 // SetHash sets the "hash" field. 562 func (m *RevisionMutation) SetHash(s string) { 563 m.hash = &s 564 } 565 566 // Hash returns the value of the "hash" field in the mutation. 567 func (m *RevisionMutation) Hash() (r string, exists bool) { 568 v := m.hash 569 if v == nil { 570 return 571 } 572 return *v, true 573 } 574 575 // OldHash returns the old "hash" field's value of the Revision entity. 576 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 577 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 578 func (m *RevisionMutation) OldHash(ctx context.Context) (v string, err error) { 579 if !m.op.Is(OpUpdateOne) { 580 return v, errors.New("OldHash is only allowed on UpdateOne operations") 581 } 582 if m.id == nil || m.oldValue == nil { 583 return v, errors.New("OldHash requires an ID field in the mutation") 584 } 585 oldValue, err := m.oldValue(ctx) 586 if err != nil { 587 return v, fmt.Errorf("querying old value for OldHash: %w", err) 588 } 589 return oldValue.Hash, nil 590 } 591 592 // ResetHash resets all changes to the "hash" field. 593 func (m *RevisionMutation) ResetHash() { 594 m.hash = nil 595 } 596 597 // SetPartialHashes sets the "partial_hashes" field. 598 func (m *RevisionMutation) SetPartialHashes(s []string) { 599 m.partial_hashes = &s 600 m.appendpartial_hashes = nil 601 } 602 603 // PartialHashes returns the value of the "partial_hashes" field in the mutation. 604 func (m *RevisionMutation) PartialHashes() (r []string, exists bool) { 605 v := m.partial_hashes 606 if v == nil { 607 return 608 } 609 return *v, true 610 } 611 612 // OldPartialHashes returns the old "partial_hashes" field's value of the Revision entity. 613 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 614 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 615 func (m *RevisionMutation) OldPartialHashes(ctx context.Context) (v []string, err error) { 616 if !m.op.Is(OpUpdateOne) { 617 return v, errors.New("OldPartialHashes is only allowed on UpdateOne operations") 618 } 619 if m.id == nil || m.oldValue == nil { 620 return v, errors.New("OldPartialHashes requires an ID field in the mutation") 621 } 622 oldValue, err := m.oldValue(ctx) 623 if err != nil { 624 return v, fmt.Errorf("querying old value for OldPartialHashes: %w", err) 625 } 626 return oldValue.PartialHashes, nil 627 } 628 629 // AppendPartialHashes adds s to the "partial_hashes" field. 630 func (m *RevisionMutation) AppendPartialHashes(s []string) { 631 m.appendpartial_hashes = append(m.appendpartial_hashes, s...) 632 } 633 634 // AppendedPartialHashes returns the list of values that were appended to the "partial_hashes" field in this mutation. 635 func (m *RevisionMutation) AppendedPartialHashes() ([]string, bool) { 636 if len(m.appendpartial_hashes) == 0 { 637 return nil, false 638 } 639 return m.appendpartial_hashes, true 640 } 641 642 // ClearPartialHashes clears the value of the "partial_hashes" field. 643 func (m *RevisionMutation) ClearPartialHashes() { 644 m.partial_hashes = nil 645 m.appendpartial_hashes = nil 646 m.clearedFields[revision.FieldPartialHashes] = struct{}{} 647 } 648 649 // PartialHashesCleared returns if the "partial_hashes" field was cleared in this mutation. 650 func (m *RevisionMutation) PartialHashesCleared() bool { 651 _, ok := m.clearedFields[revision.FieldPartialHashes] 652 return ok 653 } 654 655 // ResetPartialHashes resets all changes to the "partial_hashes" field. 656 func (m *RevisionMutation) ResetPartialHashes() { 657 m.partial_hashes = nil 658 m.appendpartial_hashes = nil 659 delete(m.clearedFields, revision.FieldPartialHashes) 660 } 661 662 // SetOperatorVersion sets the "operator_version" field. 663 func (m *RevisionMutation) SetOperatorVersion(s string) { 664 m.operator_version = &s 665 } 666 667 // OperatorVersion returns the value of the "operator_version" field in the mutation. 668 func (m *RevisionMutation) OperatorVersion() (r string, exists bool) { 669 v := m.operator_version 670 if v == nil { 671 return 672 } 673 return *v, true 674 } 675 676 // OldOperatorVersion returns the old "operator_version" field's value of the Revision entity. 677 // If the Revision object wasn't provided to the builder, the object is fetched from the database. 678 // An error is returned if the mutation operation is not UpdateOne, or the database query fails. 679 func (m *RevisionMutation) OldOperatorVersion(ctx context.Context) (v string, err error) { 680 if !m.op.Is(OpUpdateOne) { 681 return v, errors.New("OldOperatorVersion is only allowed on UpdateOne operations") 682 } 683 if m.id == nil || m.oldValue == nil { 684 return v, errors.New("OldOperatorVersion requires an ID field in the mutation") 685 } 686 oldValue, err := m.oldValue(ctx) 687 if err != nil { 688 return v, fmt.Errorf("querying old value for OldOperatorVersion: %w", err) 689 } 690 return oldValue.OperatorVersion, nil 691 } 692 693 // ResetOperatorVersion resets all changes to the "operator_version" field. 694 func (m *RevisionMutation) ResetOperatorVersion() { 695 m.operator_version = nil 696 } 697 698 // Where appends a list predicates to the RevisionMutation builder. 699 func (m *RevisionMutation) Where(ps ...predicate.Revision) { 700 m.predicates = append(m.predicates, ps...) 701 } 702 703 // WhereP appends storage-level predicates to the RevisionMutation builder. Using this method, 704 // users can use type-assertion to append predicates that do not depend on any generated package. 705 func (m *RevisionMutation) WhereP(ps ...func(*sql.Selector)) { 706 p := make([]predicate.Revision, len(ps)) 707 for i := range ps { 708 p[i] = ps[i] 709 } 710 m.Where(p...) 711 } 712 713 // Op returns the operation name. 714 func (m *RevisionMutation) Op() Op { 715 return m.op 716 } 717 718 // SetOp allows setting the mutation operation. 719 func (m *RevisionMutation) SetOp(op Op) { 720 m.op = op 721 } 722 723 // Type returns the node type of this mutation (Revision). 724 func (m *RevisionMutation) Type() string { 725 return m.typ 726 } 727 728 // Fields returns all fields that were changed during this mutation. Note that in 729 // order to get all numeric fields that were incremented/decremented, call 730 // AddedFields(). 731 func (m *RevisionMutation) Fields() []string { 732 fields := make([]string, 0, 11) 733 if m.description != nil { 734 fields = append(fields, revision.FieldDescription) 735 } 736 if m._type != nil { 737 fields = append(fields, revision.FieldType) 738 } 739 if m.applied != nil { 740 fields = append(fields, revision.FieldApplied) 741 } 742 if m.total != nil { 743 fields = append(fields, revision.FieldTotal) 744 } 745 if m.executed_at != nil { 746 fields = append(fields, revision.FieldExecutedAt) 747 } 748 if m.execution_time != nil { 749 fields = append(fields, revision.FieldExecutionTime) 750 } 751 if m.error != nil { 752 fields = append(fields, revision.FieldError) 753 } 754 if m.error_stmt != nil { 755 fields = append(fields, revision.FieldErrorStmt) 756 } 757 if m.hash != nil { 758 fields = append(fields, revision.FieldHash) 759 } 760 if m.partial_hashes != nil { 761 fields = append(fields, revision.FieldPartialHashes) 762 } 763 if m.operator_version != nil { 764 fields = append(fields, revision.FieldOperatorVersion) 765 } 766 return fields 767 } 768 769 // Field returns the value of a field with the given name. The second boolean 770 // return value indicates that this field was not set, or was not defined in the 771 // schema. 772 func (m *RevisionMutation) Field(name string) (ent.Value, bool) { 773 switch name { 774 case revision.FieldDescription: 775 return m.Description() 776 case revision.FieldType: 777 return m.GetType() 778 case revision.FieldApplied: 779 return m.Applied() 780 case revision.FieldTotal: 781 return m.Total() 782 case revision.FieldExecutedAt: 783 return m.ExecutedAt() 784 case revision.FieldExecutionTime: 785 return m.ExecutionTime() 786 case revision.FieldError: 787 return m.Error() 788 case revision.FieldErrorStmt: 789 return m.ErrorStmt() 790 case revision.FieldHash: 791 return m.Hash() 792 case revision.FieldPartialHashes: 793 return m.PartialHashes() 794 case revision.FieldOperatorVersion: 795 return m.OperatorVersion() 796 } 797 return nil, false 798 } 799 800 // OldField returns the old value of the field from the database. An error is 801 // returned if the mutation operation is not UpdateOne, or the query to the 802 // database failed. 803 func (m *RevisionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { 804 switch name { 805 case revision.FieldDescription: 806 return m.OldDescription(ctx) 807 case revision.FieldType: 808 return m.OldType(ctx) 809 case revision.FieldApplied: 810 return m.OldApplied(ctx) 811 case revision.FieldTotal: 812 return m.OldTotal(ctx) 813 case revision.FieldExecutedAt: 814 return m.OldExecutedAt(ctx) 815 case revision.FieldExecutionTime: 816 return m.OldExecutionTime(ctx) 817 case revision.FieldError: 818 return m.OldError(ctx) 819 case revision.FieldErrorStmt: 820 return m.OldErrorStmt(ctx) 821 case revision.FieldHash: 822 return m.OldHash(ctx) 823 case revision.FieldPartialHashes: 824 return m.OldPartialHashes(ctx) 825 case revision.FieldOperatorVersion: 826 return m.OldOperatorVersion(ctx) 827 } 828 return nil, fmt.Errorf("unknown Revision field %s", name) 829 } 830 831 // SetField sets the value of a field with the given name. It returns an error if 832 // the field is not defined in the schema, or if the type mismatched the field 833 // type. 834 func (m *RevisionMutation) SetField(name string, value ent.Value) error { 835 switch name { 836 case revision.FieldDescription: 837 v, ok := value.(string) 838 if !ok { 839 return fmt.Errorf("unexpected type %T for field %s", value, name) 840 } 841 m.SetDescription(v) 842 return nil 843 case revision.FieldType: 844 v, ok := value.(migrate.RevisionType) 845 if !ok { 846 return fmt.Errorf("unexpected type %T for field %s", value, name) 847 } 848 m.SetType(v) 849 return nil 850 case revision.FieldApplied: 851 v, ok := value.(int) 852 if !ok { 853 return fmt.Errorf("unexpected type %T for field %s", value, name) 854 } 855 m.SetApplied(v) 856 return nil 857 case revision.FieldTotal: 858 v, ok := value.(int) 859 if !ok { 860 return fmt.Errorf("unexpected type %T for field %s", value, name) 861 } 862 m.SetTotal(v) 863 return nil 864 case revision.FieldExecutedAt: 865 v, ok := value.(time.Time) 866 if !ok { 867 return fmt.Errorf("unexpected type %T for field %s", value, name) 868 } 869 m.SetExecutedAt(v) 870 return nil 871 case revision.FieldExecutionTime: 872 v, ok := value.(time.Duration) 873 if !ok { 874 return fmt.Errorf("unexpected type %T for field %s", value, name) 875 } 876 m.SetExecutionTime(v) 877 return nil 878 case revision.FieldError: 879 v, ok := value.(string) 880 if !ok { 881 return fmt.Errorf("unexpected type %T for field %s", value, name) 882 } 883 m.SetError(v) 884 return nil 885 case revision.FieldErrorStmt: 886 v, ok := value.(string) 887 if !ok { 888 return fmt.Errorf("unexpected type %T for field %s", value, name) 889 } 890 m.SetErrorStmt(v) 891 return nil 892 case revision.FieldHash: 893 v, ok := value.(string) 894 if !ok { 895 return fmt.Errorf("unexpected type %T for field %s", value, name) 896 } 897 m.SetHash(v) 898 return nil 899 case revision.FieldPartialHashes: 900 v, ok := value.([]string) 901 if !ok { 902 return fmt.Errorf("unexpected type %T for field %s", value, name) 903 } 904 m.SetPartialHashes(v) 905 return nil 906 case revision.FieldOperatorVersion: 907 v, ok := value.(string) 908 if !ok { 909 return fmt.Errorf("unexpected type %T for field %s", value, name) 910 } 911 m.SetOperatorVersion(v) 912 return nil 913 } 914 return fmt.Errorf("unknown Revision field %s", name) 915 } 916 917 // AddedFields returns all numeric fields that were incremented/decremented during 918 // this mutation. 919 func (m *RevisionMutation) AddedFields() []string { 920 var fields []string 921 if m.add_type != nil { 922 fields = append(fields, revision.FieldType) 923 } 924 if m.addapplied != nil { 925 fields = append(fields, revision.FieldApplied) 926 } 927 if m.addtotal != nil { 928 fields = append(fields, revision.FieldTotal) 929 } 930 if m.addexecution_time != nil { 931 fields = append(fields, revision.FieldExecutionTime) 932 } 933 return fields 934 } 935 936 // AddedField returns the numeric value that was incremented/decremented on a field 937 // with the given name. The second boolean return value indicates that this field 938 // was not set, or was not defined in the schema. 939 func (m *RevisionMutation) AddedField(name string) (ent.Value, bool) { 940 switch name { 941 case revision.FieldType: 942 return m.AddedType() 943 case revision.FieldApplied: 944 return m.AddedApplied() 945 case revision.FieldTotal: 946 return m.AddedTotal() 947 case revision.FieldExecutionTime: 948 return m.AddedExecutionTime() 949 } 950 return nil, false 951 } 952 953 // AddField adds the value to the field with the given name. It returns an error if 954 // the field is not defined in the schema, or if the type mismatched the field 955 // type. 956 func (m *RevisionMutation) AddField(name string, value ent.Value) error { 957 switch name { 958 case revision.FieldType: 959 v, ok := value.(migrate.RevisionType) 960 if !ok { 961 return fmt.Errorf("unexpected type %T for field %s", value, name) 962 } 963 m.AddType(v) 964 return nil 965 case revision.FieldApplied: 966 v, ok := value.(int) 967 if !ok { 968 return fmt.Errorf("unexpected type %T for field %s", value, name) 969 } 970 m.AddApplied(v) 971 return nil 972 case revision.FieldTotal: 973 v, ok := value.(int) 974 if !ok { 975 return fmt.Errorf("unexpected type %T for field %s", value, name) 976 } 977 m.AddTotal(v) 978 return nil 979 case revision.FieldExecutionTime: 980 v, ok := value.(time.Duration) 981 if !ok { 982 return fmt.Errorf("unexpected type %T for field %s", value, name) 983 } 984 m.AddExecutionTime(v) 985 return nil 986 } 987 return fmt.Errorf("unknown Revision numeric field %s", name) 988 } 989 990 // ClearedFields returns all nullable fields that were cleared during this 991 // mutation. 992 func (m *RevisionMutation) ClearedFields() []string { 993 var fields []string 994 if m.FieldCleared(revision.FieldError) { 995 fields = append(fields, revision.FieldError) 996 } 997 if m.FieldCleared(revision.FieldErrorStmt) { 998 fields = append(fields, revision.FieldErrorStmt) 999 } 1000 if m.FieldCleared(revision.FieldPartialHashes) { 1001 fields = append(fields, revision.FieldPartialHashes) 1002 } 1003 return fields 1004 } 1005 1006 // FieldCleared returns a boolean indicating if a field with the given name was 1007 // cleared in this mutation. 1008 func (m *RevisionMutation) FieldCleared(name string) bool { 1009 _, ok := m.clearedFields[name] 1010 return ok 1011 } 1012 1013 // ClearField clears the value of the field with the given name. It returns an 1014 // error if the field is not defined in the schema. 1015 func (m *RevisionMutation) ClearField(name string) error { 1016 switch name { 1017 case revision.FieldError: 1018 m.ClearError() 1019 return nil 1020 case revision.FieldErrorStmt: 1021 m.ClearErrorStmt() 1022 return nil 1023 case revision.FieldPartialHashes: 1024 m.ClearPartialHashes() 1025 return nil 1026 } 1027 return fmt.Errorf("unknown Revision nullable field %s", name) 1028 } 1029 1030 // ResetField resets all changes in the mutation for the field with the given name. 1031 // It returns an error if the field is not defined in the schema. 1032 func (m *RevisionMutation) ResetField(name string) error { 1033 switch name { 1034 case revision.FieldDescription: 1035 m.ResetDescription() 1036 return nil 1037 case revision.FieldType: 1038 m.ResetType() 1039 return nil 1040 case revision.FieldApplied: 1041 m.ResetApplied() 1042 return nil 1043 case revision.FieldTotal: 1044 m.ResetTotal() 1045 return nil 1046 case revision.FieldExecutedAt: 1047 m.ResetExecutedAt() 1048 return nil 1049 case revision.FieldExecutionTime: 1050 m.ResetExecutionTime() 1051 return nil 1052 case revision.FieldError: 1053 m.ResetError() 1054 return nil 1055 case revision.FieldErrorStmt: 1056 m.ResetErrorStmt() 1057 return nil 1058 case revision.FieldHash: 1059 m.ResetHash() 1060 return nil 1061 case revision.FieldPartialHashes: 1062 m.ResetPartialHashes() 1063 return nil 1064 case revision.FieldOperatorVersion: 1065 m.ResetOperatorVersion() 1066 return nil 1067 } 1068 return fmt.Errorf("unknown Revision field %s", name) 1069 } 1070 1071 // AddedEdges returns all edge names that were set/added in this mutation. 1072 func (m *RevisionMutation) AddedEdges() []string { 1073 edges := make([]string, 0, 0) 1074 return edges 1075 } 1076 1077 // AddedIDs returns all IDs (to other nodes) that were added for the given edge 1078 // name in this mutation. 1079 func (m *RevisionMutation) AddedIDs(name string) []ent.Value { 1080 return nil 1081 } 1082 1083 // RemovedEdges returns all edge names that were removed in this mutation. 1084 func (m *RevisionMutation) RemovedEdges() []string { 1085 edges := make([]string, 0, 0) 1086 return edges 1087 } 1088 1089 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with 1090 // the given name in this mutation. 1091 func (m *RevisionMutation) RemovedIDs(name string) []ent.Value { 1092 return nil 1093 } 1094 1095 // ClearedEdges returns all edge names that were cleared in this mutation. 1096 func (m *RevisionMutation) ClearedEdges() []string { 1097 edges := make([]string, 0, 0) 1098 return edges 1099 } 1100 1101 // EdgeCleared returns a boolean which indicates if the edge with the given name 1102 // was cleared in this mutation. 1103 func (m *RevisionMutation) EdgeCleared(name string) bool { 1104 return false 1105 } 1106 1107 // ClearEdge clears the value of the edge with the given name. It returns an error 1108 // if that edge is not defined in the schema. 1109 func (m *RevisionMutation) ClearEdge(name string) error { 1110 return fmt.Errorf("unknown Revision unique edge %s", name) 1111 } 1112 1113 // ResetEdge resets all changes to the edge with the given name in this mutation. 1114 // It returns an error if the edge is not defined in the schema. 1115 func (m *RevisionMutation) ResetEdge(name string) error { 1116 return fmt.Errorf("unknown Revision edge %s", name) 1117 }