github.com/iasthc/atlas/cmd/atlas@v0.0.0-20230523071841-73246df3f88d/internal/migrate/ent/schema/revision.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  package schema
     6  
     7  import (
     8  	"time"
     9  
    10  	"github.com/iasthc/atlas/sql/migrate"
    11  
    12  	"entgo.io/ent"
    13  	"entgo.io/ent/dialect/entsql"
    14  	"entgo.io/ent/schema"
    15  	"entgo.io/ent/schema/field"
    16  )
    17  
    18  // DefaultRevisionSchema is the default schema for storing revisions table.
    19  const DefaultRevisionSchema = "atlas_schema_revisions"
    20  
    21  // Revision holds the schema definition for the Revision entity.
    22  type Revision struct {
    23  	ent.Schema
    24  }
    25  
    26  // Fields of the Revision.
    27  func (Revision) Fields() []ent.Field {
    28  	return []ent.Field{
    29  		field.String("id").
    30  			StorageKey("version").
    31  			Immutable(),
    32  		field.String("description").
    33  			Immutable(),
    34  		field.Uint("type").
    35  			GoType(migrate.RevisionType(0)).
    36  			Default(uint(migrate.RevisionTypeExecute)),
    37  		field.Int("applied").
    38  			NonNegative().
    39  			Default(0),
    40  		field.Int("total").
    41  			NonNegative().
    42  			Default(0),
    43  		field.Time("executed_at").
    44  			Immutable(),
    45  		field.Int64("execution_time").
    46  			GoType(time.Duration(0)),
    47  		field.Text("error").
    48  			Optional(),
    49  		field.Text("error_stmt").
    50  			Optional(),
    51  		field.String("hash"),
    52  		field.Strings("partial_hashes").
    53  			Optional(),
    54  		field.String("operator_version"),
    55  	}
    56  }
    57  
    58  // Annotations of the Revision.
    59  func (Revision) Annotations() []schema.Annotation {
    60  	return []schema.Annotation{
    61  		entsql.Annotation{Table: DefaultRevisionSchema},
    62  	}
    63  }