Skip to content

Commit

Permalink
Update all usages of Column.Unique
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-farries committed Nov 27, 2024
1 parent 0a0b006 commit 48438a6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion internal/benchmarks/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ var migCreateTable = migrations.Migration{
Name: "name",
Type: "varchar(255)",
Nullable: true,
Unique: ptr(false),
Unique: false,
},
},
},
Expand Down
5 changes: 1 addition & 4 deletions pkg/migrations/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ func (c *Column) IsNullable() bool {

// IsUnique returns true if the column values must be unique
func (c *Column) IsUnique() bool {
if c.Unique != nil {
return *c.Unique
}
return false
return c.Unique
}

// IsPrimaryKey returns true if the column is part of the primary key
Expand Down
32 changes: 16 additions & 16 deletions pkg/migrations/op_add_column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestAddColumn(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestAddColumn(t *testing.T) {
Name: "description",
Type: "integer",
Nullable: false,
Unique: ptr(true),
Unique: true,
},
Up: "'this is a description'",
},
Expand All @@ -168,7 +168,7 @@ func TestAddColumn(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -380,7 +380,7 @@ func TestAddForeignKeyColumn(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -721,7 +721,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -803,7 +803,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -885,7 +885,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -967,7 +967,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -1050,7 +1050,7 @@ func TestAddColumnWithUpSql(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
Nullable: false,
},
},
Expand Down Expand Up @@ -1150,7 +1150,7 @@ func TestAddNotNullColumnWithNoDefault(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -1217,7 +1217,7 @@ func TestAddColumnValidation(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand All @@ -1237,7 +1237,7 @@ func TestAddColumnValidation(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
Nullable: true,
},
},
Expand All @@ -1258,7 +1258,7 @@ func TestAddColumnValidation(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
Nullable: false,
},
},
Expand Down Expand Up @@ -1447,7 +1447,7 @@ func TestAddColumnWithCheckConstraint(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -1522,7 +1522,7 @@ func TestAddColumnWithComment(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down
16 changes: 8 additions & 8 deletions pkg/migrations/op_create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestCreateTable(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestCreateTable(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestCreateTable(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestCreateTable(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -460,7 +460,7 @@ func TestCreateTable(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
Comment: ptr("the username"),
},
},
Expand Down Expand Up @@ -509,7 +509,7 @@ func TestCreateTableValidation(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -567,7 +567,7 @@ func TestCreateTableValidation(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand All @@ -593,7 +593,7 @@ func TestCreateTableValidation(t *testing.T) {
{
Name: invalidName,
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions pkg/migrations/op_drop_constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func TestDropConstraint(t *testing.T) {
{
Name: "name",
Type: "text",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -426,7 +426,7 @@ func TestDropConstraint(t *testing.T) {
{
Name: "name",
Type: "text",
Unique: ptr(true),
Unique: true,
Default: ptr("'anonymous'"),
},
},
Expand Down Expand Up @@ -521,7 +521,7 @@ func TestDropConstraint(t *testing.T) {
{
Name: "department_id",
Type: "integer",
Unique: ptr(true),
Unique: true,
References: &migrations.ForeignKeyReference{
Name: "fk_employee_department",
Table: "departments",
Expand Down Expand Up @@ -573,7 +573,7 @@ func TestDropConstraint(t *testing.T) {
Name: "title",
Type: "text",
Nullable: true,
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down Expand Up @@ -730,7 +730,7 @@ func TestDropConstraint(t *testing.T) {
{
Name: "title",
Type: "text",
Unique: ptr(true),
Unique: true,
Nullable: false,
},
},
Expand Down Expand Up @@ -781,7 +781,7 @@ func TestDropConstraint(t *testing.T) {
{
Name: "title",
Type: "text",
Unique: ptr(true),
Unique: true,
Nullable: false,
Comment: ptr("the title of the post"),
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/migrations/op_drop_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDropTable(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/migrations/op_set_replica_identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestSetReplicaIdentityValidation(t *testing.T) {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/roll/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ func createTableOp(tableName string) *migrations.OpCreateTable {
{
Name: "name",
Type: "varchar(255)",
Unique: ptr(true),
Unique: true,
},
},
}
Expand Down

0 comments on commit 48438a6

Please sign in to comment.