Skip to content

Commit

Permalink
Change type of Column.Pk from *bool to bool (#495)
Browse files Browse the repository at this point in the history
Change the type generated by the JSON schema for the `Column.Pk` field
from `*bool` to `bool`.

This simplifies use of the field when using `pgroll` from code.
  • Loading branch information
andrew-farries authored Nov 27, 2024
1 parent b03cef2 commit 491927c
Show file tree
Hide file tree
Showing 27 changed files with 184 additions and 186 deletions.
2 changes: 1 addition & 1 deletion internal/benchmarks/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ var migCreateTable = migrations.Migration{
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down
5 changes: 1 addition & 4 deletions pkg/migrations/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ func (c *Column) IsUnique() bool {

// IsPrimaryKey returns true if the column is part of the primary key
func (c *Column) IsPrimaryKey() bool {
if c.Pk != nil {
return *c.Pk
}
return false
return c.Pk
}

// HasImplicitDefault returns true if the column has an implicit default value
Expand Down
44 changes: 22 additions & 22 deletions pkg/migrations/op_add_column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAddColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestAddColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -273,7 +273,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand All @@ -288,7 +288,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "quantity",
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand All @@ -390,7 +390,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "quantity",
Expand Down Expand Up @@ -478,7 +478,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand All @@ -492,7 +492,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "quantity",
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand All @@ -603,7 +603,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "quantity",
Expand Down Expand Up @@ -716,7 +716,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -798,7 +798,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -880,7 +880,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -962,7 +962,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "id",
Type: "text",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -1145,7 +1145,7 @@ func TestAddNotNullColumnWithNoDefault(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -1212,7 +1212,7 @@ func TestAddColumnValidation(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -1442,7 +1442,7 @@ func TestAddColumnWithCheckConstraint(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -1517,7 +1517,7 @@ func TestAddColumnWithComment(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -1579,7 +1579,7 @@ func TestAddColumnDefaultTransformation(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
},
},
Expand Down Expand Up @@ -1633,7 +1633,7 @@ func TestAddColumnDefaultTransformation(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
},
},
Expand Down Expand Up @@ -1674,7 +1674,7 @@ func TestAddColumnToATableCreatedInTheSameMigration(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -1744,7 +1744,7 @@ func TestAddColumnInvalidNameLength(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
},
},
Expand Down
14 changes: 7 additions & 7 deletions pkg/migrations/op_alter_column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -374,7 +374,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand All @@ -389,7 +389,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -564,7 +564,7 @@ func TestAlterColumnValidation(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand All @@ -578,7 +578,7 @@ func TestAlterColumnValidation(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "title",
Expand Down
22 changes: 11 additions & 11 deletions pkg/migrations/op_change_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "username",
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand All @@ -171,7 +171,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "name",
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "integer",
Pk: ptr(true),
Pk: true,
},
{
Name: "age",
Expand Down Expand Up @@ -293,7 +293,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "integer",
Pk: ptr(true),
Pk: true,
},
{
Name: "username",
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "integer",
Pk: ptr(true),
Pk: true,
},
{
Name: "age",
Expand Down Expand Up @@ -417,7 +417,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "integer",
Pk: ptr(true),
Pk: true,
},
{
Name: "username",
Expand Down Expand Up @@ -474,7 +474,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "integer",
Pk: ptr(true),
Pk: true,
},
{
Name: "username",
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "username",
Expand Down Expand Up @@ -600,7 +600,7 @@ func TestChangeColumnType(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "username",
Expand Down Expand Up @@ -650,7 +650,7 @@ func TestChangeColumnTypeValidation(t *testing.T) {
{
Name: "id",
Type: "serial",
Pk: ptr(true),
Pk: true,
},
{
Name: "username",
Expand Down
Loading

0 comments on commit 491927c

Please sign in to comment.