Skip to content

Commit 27d09ec

Browse files
authored
Add missing doc comments to exported symbols (#392)
While going through pgroll codebase I see that it is also really nicely documented overall. I took this chance to add doc comments to the remaining non-documented exported symbols.
1 parent b72ce2a commit 27d09ec

18 files changed

+62
-5
lines changed

pkg/migrations/check.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
package migrations
44

5+
// Validate checks that the CheckConstraint is valid
56
func (c *CheckConstraint) Validate() error {
67
if c.Name == "" {
78
return FieldRequiredError{Name: "name"}

pkg/migrations/column.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
package migrations
44

5+
// IsNullable returns true if the column is nullable
56
func (c *Column) IsNullable() bool {
67
if c.Nullable != nil {
78
return *c.Nullable
89
}
910
return false
1011
}
1112

13+
// IsUnique returns true if the column values must be unique
1214
func (c *Column) IsUnique() bool {
1315
if c.Unique != nil {
1416
return *c.Unique
1517
}
1618
return false
1719
}
1820

21+
// IsPrimaryKey returns true if the column is part of the primary key
1922
func (c *Column) IsPrimaryKey() bool {
2023
if c.Pk != nil {
2124
return *c.Pk

pkg/migrations/duplicate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"github.com/xataio/pgroll/pkg/schema"
1515
)
1616

17+
// Duplicator duplicates a column in a table, including all constraints and
18+
// comments.
1719
type Duplicator struct {
1820
conn db.DB
1921
table *schema.Table
@@ -40,16 +42,19 @@ func NewColumnDuplicator(conn db.DB, table *schema.Table, column *schema.Column)
4042
}
4143
}
4244

45+
// WithType sets the type of the new column.
4346
func (d *Duplicator) WithType(t string) *Duplicator {
4447
d.withType = t
4548
return d
4649
}
4750

51+
// WithoutConstraint excludes a constraint from being duplicated.
4852
func (d *Duplicator) WithoutConstraint(c string) *Duplicator {
4953
d.withoutConstraint = c
5054
return d
5155
}
5256

57+
// WithoutNotNull excludes the NOT NULL constraint from being duplicated.
5358
func (d *Duplicator) WithoutNotNull() *Duplicator {
5459
d.withoutNotNull = true
5560
return d
@@ -182,14 +187,17 @@ func (d *Duplicator) Duplicate(ctx context.Context) error {
182187
return nil
183188
}
184189

190+
// DiplicationName returns the name of a duplicated column.
185191
func DuplicationName(name string) string {
186192
return "_pgroll_dup_" + name
187193
}
188194

195+
// IsDuplicatedName returns true if the name is a duplicated column name.
189196
func IsDuplicatedName(name string) bool {
190197
return strings.HasPrefix(name, "_pgroll_dup_")
191198
}
192199

200+
// StripDuplicationPrefix removes the duplication prefix from a column name.
193201
func StripDuplicationPrefix(name string) string {
194202
return strings.TrimPrefix(name, "_pgroll_dup_")
195203
}

pkg/migrations/fk_reference.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/xataio/pgroll/pkg/schema"
99
)
1010

11+
// Validate checks that the ForeignKeyReference is valid
1112
func (f *ForeignKeyReference) Validate(s *schema.Schema) error {
1213
if f.Name == "" {
1314
return FieldRequiredError{Name: "name"}

pkg/migrations/migrations.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
type CallbackFn func(int64)
1515

16+
// Operation is an operation that can be applied to a schema
1617
type Operation interface {
1718
// Start will apply the required changes to enable supporting the new schema
1819
// version in the database (through a view)
@@ -22,31 +23,33 @@ type Operation interface {
2223

2324
// Complete will update the database schema to match the current version
2425
// after calling Start.
25-
// This method should be called once the previous version is no longer used
26+
// This method should be called once the previous version is no longer used.
2627
Complete(ctx context.Context, conn db.DB, tr SQLTransformer, s *schema.Schema) error
2728

2829
// Rollback will revert the changes made by Start. It is not possible to
2930
// rollback a completed migration.
3031
Rollback(ctx context.Context, conn db.DB, tr SQLTransformer) error
3132

32-
// Validate returns a descriptive error if the operation cannot be applied to the given schema
33+
// Validate returns a descriptive error if the operation cannot be applied to the given schema.
3334
Validate(ctx context.Context, s *schema.Schema) error
3435
}
3536

3637
// IsolatedOperation is an operation that cannot be executed with other operations
37-
// in the same migration
38+
// in the same migration.
3839
type IsolatedOperation interface {
39-
// this operation is isolated when executed on start, cannot be executed with other operations
40+
// this operation is isolated when executed on start, cannot be executed with other operations.
4041
IsIsolated() bool
4142
}
4243

43-
// RequiresSchemaRefreshOperation is an operation that requires the resulting schema to be refreshed
44+
// RequiresSchemaRefreshOperation is an operation that requires the resulting schema to be refreshed.
4445
type RequiresSchemaRefreshOperation interface {
4546
// this operation requires the resulting schema to be refreshed when executed on start
4647
RequiresSchemaRefresh()
4748
}
4849

50+
// SQLTransformer is an interface that can be used to transform SQL statements.
4951
type SQLTransformer interface {
52+
// TransformSQL will transform the given SQL statement.
5053
TransformSQL(sql string) (string, error)
5154
}
5255

pkg/migrations/op_add_column.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,12 @@ func (o *OpAddColumn) addCheckConstraint(ctx context.Context, conn db.DB) error
234234
return err
235235
}
236236

237+
// NotNullConstraintName returns the name of the NOT NULL constraint for the given column
237238
func NotNullConstraintName(columnName string) string {
238239
return "_pgroll_check_not_null_" + columnName
239240
}
240241

242+
// IsNotNullConstraintName returns true if the given name is a NOT NULL constraint name
241243
func IsNotNullConstraintName(name string) bool {
242244
return strings.HasPrefix(name, "_pgroll_check_not_null_")
243245
}

pkg/migrations/op_common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ const (
3636

3737
const temporaryPrefix = "_pgroll_new_"
3838

39+
// TemporaryName returns a temporary name for a given name.
3940
func TemporaryName(name string) string {
4041
return temporaryPrefix + name
4142
}
4243

44+
// ReadMigration reads a migration from an io.Reader, like a file.
4345
func ReadMigration(r io.Reader) (*Migration, error) {
4446
byteValue, err := io.ReadAll(r)
4547
if err != nil {
@@ -166,6 +168,7 @@ func (v Operations) MarshalJSON() ([]byte, error) {
166168
return buf.Bytes(), nil
167169
}
168170

171+
// OperationName returns the name of the operation.
169172
func OperationName(op Operation) OpName {
170173
switch op.(type) {
171174
case *OpCreateTable:

pkg/migrations/op_create_table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func columnsToSQL(cols []Column, tr SQLTransformer) (string, error) {
126126
return sql, nil
127127
}
128128

129+
// ColumnToSQL generates the SQL for a column definition.
129130
func ColumnToSQL(col Column, tr SQLTransformer) (string, error) {
130131
sql := fmt.Sprintf("%s %s", pq.QuoteIdentifier(col.Name), col.Type)
131132

pkg/migrations/op_drop_not_null.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/xataio/pgroll/pkg/schema"
1010
)
1111

12+
// OpDropNotNull is an operation that drops the NOT NULL constraint from a column
1213
type OpDropNotNull struct {
1314
Table string `json:"table"`
1415
Column string `json:"column"`

pkg/migrations/op_raw_sql.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (o *OpRawSQL) Validate(ctx context.Context, s *schema.Schema) error {
6565
return nil
6666
}
6767

68+
// IsIsolated returns true if the operation is isolated and should be run with other operations.
6869
func (o *OpRawSQL) IsIsolated() bool {
6970
return !o.OnComplete
7071
}

0 commit comments

Comments
 (0)