Skip to content

Commit 491927c

Browse files
Change type of Column.Pk from *bool to bool (#495)
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.
1 parent b03cef2 commit 491927c

27 files changed

+184
-186
lines changed

internal/benchmarks/benchmarks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ var migCreateTable = migrations.Migration{
235235
{
236236
Name: "id",
237237
Type: "serial",
238-
Pk: ptr(true),
238+
Pk: true,
239239
},
240240
{
241241
Name: "name",

pkg/migrations/column.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ func (c *Column) IsUnique() bool {
2020

2121
// IsPrimaryKey returns true if the column is part of the primary key
2222
func (c *Column) IsPrimaryKey() bool {
23-
if c.Pk != nil {
24-
return *c.Pk
25-
}
26-
return false
23+
return c.Pk
2724
}
2825

2926
// HasImplicitDefault returns true if the column has an implicit default value

pkg/migrations/op_add_column_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestAddColumn(t *testing.T) {
3030
{
3131
Name: "id",
3232
Type: "serial",
33-
Pk: ptr(true),
33+
Pk: true,
3434
},
3535
{
3636
Name: "name",
@@ -163,7 +163,7 @@ func TestAddColumn(t *testing.T) {
163163
{
164164
Name: "id",
165165
Type: "serial",
166-
Pk: ptr(true),
166+
Pk: true,
167167
},
168168
{
169169
Name: "name",
@@ -273,7 +273,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
273273
{
274274
Name: "id",
275275
Type: "serial",
276-
Pk: ptr(true),
276+
Pk: true,
277277
},
278278
{
279279
Name: "name",
@@ -288,7 +288,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
288288
{
289289
Name: "id",
290290
Type: "serial",
291-
Pk: ptr(true),
291+
Pk: true,
292292
},
293293
{
294294
Name: "quantity",
@@ -375,7 +375,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
375375
{
376376
Name: "id",
377377
Type: "serial",
378-
Pk: ptr(true),
378+
Pk: true,
379379
},
380380
{
381381
Name: "name",
@@ -390,7 +390,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
390390
{
391391
Name: "id",
392392
Type: "serial",
393-
Pk: ptr(true),
393+
Pk: true,
394394
},
395395
{
396396
Name: "quantity",
@@ -478,7 +478,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
478478
{
479479
Name: "id",
480480
Type: "serial",
481-
Pk: ptr(true),
481+
Pk: true,
482482
},
483483
{
484484
Name: "name",
@@ -492,7 +492,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
492492
{
493493
Name: "id",
494494
Type: "serial",
495-
Pk: ptr(true),
495+
Pk: true,
496496
},
497497
{
498498
Name: "quantity",
@@ -589,7 +589,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
589589
{
590590
Name: "id",
591591
Type: "serial",
592-
Pk: ptr(true),
592+
Pk: true,
593593
},
594594
{
595595
Name: "name",
@@ -603,7 +603,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
603603
{
604604
Name: "id",
605605
Type: "serial",
606-
Pk: ptr(true),
606+
Pk: true,
607607
},
608608
{
609609
Name: "quantity",
@@ -716,7 +716,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
716716
{
717717
Name: "id",
718718
Type: "serial",
719-
Pk: ptr(true),
719+
Pk: true,
720720
},
721721
{
722722
Name: "name",
@@ -798,7 +798,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
798798
{
799799
Name: "id",
800800
Type: "serial",
801-
Pk: ptr(true),
801+
Pk: true,
802802
},
803803
{
804804
Name: "name",
@@ -880,7 +880,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
880880
{
881881
Name: "id",
882882
Type: "serial",
883-
Pk: ptr(true),
883+
Pk: true,
884884
},
885885
{
886886
Name: "name",
@@ -962,7 +962,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
962962
{
963963
Name: "id",
964964
Type: "text",
965-
Pk: ptr(true),
965+
Pk: true,
966966
},
967967
{
968968
Name: "name",
@@ -1145,7 +1145,7 @@ func TestAddNotNullColumnWithNoDefault(t *testing.T) {
11451145
{
11461146
Name: "id",
11471147
Type: "serial",
1148-
Pk: ptr(true),
1148+
Pk: true,
11491149
},
11501150
{
11511151
Name: "name",
@@ -1212,7 +1212,7 @@ func TestAddColumnValidation(t *testing.T) {
12121212
{
12131213
Name: "id",
12141214
Type: "serial",
1215-
Pk: ptr(true),
1215+
Pk: true,
12161216
},
12171217
{
12181218
Name: "name",
@@ -1442,7 +1442,7 @@ func TestAddColumnWithCheckConstraint(t *testing.T) {
14421442
{
14431443
Name: "id",
14441444
Type: "serial",
1445-
Pk: ptr(true),
1445+
Pk: true,
14461446
},
14471447
{
14481448
Name: "name",
@@ -1517,7 +1517,7 @@ func TestAddColumnWithComment(t *testing.T) {
15171517
{
15181518
Name: "id",
15191519
Type: "serial",
1520-
Pk: ptr(true),
1520+
Pk: true,
15211521
},
15221522
{
15231523
Name: "name",
@@ -1579,7 +1579,7 @@ func TestAddColumnDefaultTransformation(t *testing.T) {
15791579
{
15801580
Name: "id",
15811581
Type: "serial",
1582-
Pk: ptr(true),
1582+
Pk: true,
15831583
},
15841584
},
15851585
},
@@ -1633,7 +1633,7 @@ func TestAddColumnDefaultTransformation(t *testing.T) {
16331633
{
16341634
Name: "id",
16351635
Type: "serial",
1636-
Pk: ptr(true),
1636+
Pk: true,
16371637
},
16381638
},
16391639
},
@@ -1674,7 +1674,7 @@ func TestAddColumnToATableCreatedInTheSameMigration(t *testing.T) {
16741674
{
16751675
Name: "id",
16761676
Type: "serial",
1677-
Pk: ptr(true),
1677+
Pk: true,
16781678
},
16791679
{
16801680
Name: "name",
@@ -1744,7 +1744,7 @@ func TestAddColumnInvalidNameLength(t *testing.T) {
17441744
{
17451745
Name: "id",
17461746
Type: "serial",
1747-
Pk: ptr(true),
1747+
Pk: true,
17481748
},
17491749
},
17501750
},

pkg/migrations/op_alter_column_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
3030
{
3131
Name: "id",
3232
Type: "serial",
33-
Pk: ptr(true),
33+
Pk: true,
3434
},
3535
{
3636
Name: "name",
@@ -186,7 +186,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
186186
{
187187
Name: "id",
188188
Type: "serial",
189-
Pk: ptr(true),
189+
Pk: true,
190190
},
191191
{
192192
Name: "name",
@@ -303,7 +303,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
303303
{
304304
Name: "id",
305305
Type: "serial",
306-
Pk: ptr(true),
306+
Pk: true,
307307
},
308308
{
309309
Name: "name",
@@ -374,7 +374,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
374374
{
375375
Name: "id",
376376
Type: "serial",
377-
Pk: ptr(true),
377+
Pk: true,
378378
},
379379
{
380380
Name: "name",
@@ -389,7 +389,7 @@ func TestAlterColumnMultipleSubOperations(t *testing.T) {
389389
{
390390
Name: "id",
391391
Type: "serial",
392-
Pk: ptr(true),
392+
Pk: true,
393393
},
394394
{
395395
Name: "name",
@@ -564,7 +564,7 @@ func TestAlterColumnValidation(t *testing.T) {
564564
{
565565
Name: "id",
566566
Type: "serial",
567-
Pk: ptr(true),
567+
Pk: true,
568568
},
569569
{
570570
Name: "name",
@@ -578,7 +578,7 @@ func TestAlterColumnValidation(t *testing.T) {
578578
{
579579
Name: "id",
580580
Type: "serial",
581-
Pk: ptr(true),
581+
Pk: true,
582582
},
583583
{
584584
Name: "title",

pkg/migrations/op_change_type_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestChangeColumnType(t *testing.T) {
3030
{
3131
Name: "id",
3232
Type: "serial",
33-
Pk: ptr(true),
33+
Pk: true,
3434
},
3535
{
3636
Name: "username",
@@ -151,7 +151,7 @@ func TestChangeColumnType(t *testing.T) {
151151
{
152152
Name: "id",
153153
Type: "serial",
154-
Pk: ptr(true),
154+
Pk: true,
155155
},
156156
{
157157
Name: "name",
@@ -171,7 +171,7 @@ func TestChangeColumnType(t *testing.T) {
171171
{
172172
Name: "id",
173173
Type: "serial",
174-
Pk: ptr(true),
174+
Pk: true,
175175
},
176176
{
177177
Name: "name",
@@ -228,7 +228,7 @@ func TestChangeColumnType(t *testing.T) {
228228
{
229229
Name: "id",
230230
Type: "integer",
231-
Pk: ptr(true),
231+
Pk: true,
232232
},
233233
{
234234
Name: "age",
@@ -293,7 +293,7 @@ func TestChangeColumnType(t *testing.T) {
293293
{
294294
Name: "id",
295295
Type: "integer",
296-
Pk: ptr(true),
296+
Pk: true,
297297
},
298298
{
299299
Name: "username",
@@ -358,7 +358,7 @@ func TestChangeColumnType(t *testing.T) {
358358
{
359359
Name: "id",
360360
Type: "integer",
361-
Pk: ptr(true),
361+
Pk: true,
362362
},
363363
{
364364
Name: "age",
@@ -417,7 +417,7 @@ func TestChangeColumnType(t *testing.T) {
417417
{
418418
Name: "id",
419419
Type: "integer",
420-
Pk: ptr(true),
420+
Pk: true,
421421
},
422422
{
423423
Name: "username",
@@ -474,7 +474,7 @@ func TestChangeColumnType(t *testing.T) {
474474
{
475475
Name: "id",
476476
Type: "integer",
477-
Pk: ptr(true),
477+
Pk: true,
478478
},
479479
{
480480
Name: "username",
@@ -525,7 +525,7 @@ func TestChangeColumnType(t *testing.T) {
525525
{
526526
Name: "id",
527527
Type: "serial",
528-
Pk: ptr(true),
528+
Pk: true,
529529
},
530530
{
531531
Name: "username",
@@ -600,7 +600,7 @@ func TestChangeColumnType(t *testing.T) {
600600
{
601601
Name: "id",
602602
Type: "serial",
603-
Pk: ptr(true),
603+
Pk: true,
604604
},
605605
{
606606
Name: "username",
@@ -650,7 +650,7 @@ func TestChangeColumnTypeValidation(t *testing.T) {
650650
{
651651
Name: "id",
652652
Type: "serial",
653-
Pk: ptr(true),
653+
Pk: true,
654654
},
655655
{
656656
Name: "username",

0 commit comments

Comments
 (0)