@@ -33,15 +33,18 @@ import (
33
33
34
34
var validProxyByHostnameRegex = regexp .MustCompile (`^[a-zA-Z0-9._-]+$` )
35
35
36
- var errForeignKeyConstraint = & pq.Error {
37
- Code : "23503" ,
38
- Message : "update or delete on table violates foreign key constraint" ,
39
- }
40
-
41
- var errDuplicateKey = & pq.Error {
42
- Code : "23505" ,
43
- Message : "duplicate key value violates unique constraint" ,
44
- }
36
+ // A full mapping of error codes from pq v1.10.9 can be found here:
37
+ // https://github.com/lib/pq/blob/2a217b94f5ccd3de31aec4152a541b9ff64bed05/error.go#L75
38
+ var (
39
+ errForeignKeyConstraint = & pq.Error {
40
+ Code : "23503" , // "foreign_key_violation"
41
+ Message : "update or delete on table violates foreign key constraint" ,
42
+ }
43
+ errUniqueConstraint = & pq.Error {
44
+ Code : "23505" , // "unique_violation"
45
+ Message : "duplicate key value violates unique constraint" ,
46
+ }
47
+ )
45
48
46
49
// New returns an in-memory fake of the database.
47
50
func New () database.Store {
@@ -5809,7 +5812,7 @@ func (q *FakeQuerier) InsertDBCryptKey(_ context.Context, arg database.InsertDBC
5809
5812
5810
5813
for _ , key := range q .dbcryptKeys {
5811
5814
if key .Number == arg .Number {
5812
- return errDuplicateKey
5815
+ return errUniqueConstraint
5813
5816
}
5814
5817
}
5815
5818
@@ -5913,7 +5916,7 @@ func (q *FakeQuerier) InsertGroup(_ context.Context, arg database.InsertGroupPar
5913
5916
for _ , group := range q .groups {
5914
5917
if group .OrganizationID == arg .OrganizationID &&
5915
5918
group .Name == arg .Name {
5916
- return database.Group {}, errDuplicateKey
5919
+ return database.Group {}, errUniqueConstraint
5917
5920
}
5918
5921
}
5919
5922
@@ -5944,7 +5947,7 @@ func (q *FakeQuerier) InsertGroupMember(_ context.Context, arg database.InsertGr
5944
5947
for _ , member := range q .groupMembers {
5945
5948
if member .GroupID == arg .GroupID &&
5946
5949
member .UserID == arg .UserID {
5947
- return errDuplicateKey
5950
+ return errUniqueConstraint
5948
5951
}
5949
5952
}
5950
5953
@@ -6028,7 +6031,7 @@ func (q *FakeQuerier) InsertOAuth2ProviderApp(_ context.Context, arg database.In
6028
6031
6029
6032
for _ , app := range q .oauth2ProviderApps {
6030
6033
if app .Name == arg .Name {
6031
- return database.OAuth2ProviderApp {}, errDuplicateKey
6034
+ return database.OAuth2ProviderApp {}, errUniqueConstraint
6032
6035
}
6033
6036
}
6034
6037
@@ -6390,7 +6393,7 @@ func (q *FakeQuerier) InsertUser(_ context.Context, arg database.InsertUserParam
6390
6393
6391
6394
for _ , user := range q .users {
6392
6395
if user .Username == arg .Username && ! user .Deleted {
6393
- return database.User {}, errDuplicateKey
6396
+ return database.User {}, errUniqueConstraint
6394
6397
}
6395
6398
}
6396
6399
@@ -6803,7 +6806,7 @@ func (q *FakeQuerier) InsertWorkspaceProxy(_ context.Context, arg database.Inser
6803
6806
lastRegionID := int32 (0 )
6804
6807
for _ , p := range q .workspaceProxies {
6805
6808
if ! p .Deleted && p .Name == arg .Name {
6806
- return database.WorkspaceProxy {}, errDuplicateKey
6809
+ return database.WorkspaceProxy {}, errUniqueConstraint
6807
6810
}
6808
6811
if p .RegionID > lastRegionID {
6809
6812
lastRegionID = p .RegionID
@@ -7197,7 +7200,7 @@ func (q *FakeQuerier) UpdateOAuth2ProviderAppByID(_ context.Context, arg databas
7197
7200
7198
7201
for _ , app := range q .oauth2ProviderApps {
7199
7202
if app .Name == arg .Name && app .ID != arg .ID {
7200
- return database.OAuth2ProviderApp {}, errDuplicateKey
7203
+ return database.OAuth2ProviderApp {}, errUniqueConstraint
7201
7204
}
7202
7205
}
7203
7206
@@ -7258,11 +7261,7 @@ func (q *FakeQuerier) UpdateOrganization(_ context.Context, arg database.UpdateO
7258
7261
// non-unique names during updates.
7259
7262
for _ , org := range q .organizations {
7260
7263
if org .Name == arg .Name && org .ID != arg .ID {
7261
- // https://github.com/lib/pq/blob/3d613208bca2e74f2a20e04126ed30bcb5c4cc27/error.go#L178
7262
- return database.Organization {}, & pq.Error {
7263
- Code : pq .ErrorCode ("23505" ), // "unique_violation"
7264
- Constraint : string (database .UniqueOrganizationsName ),
7265
- }
7264
+ return database.Organization {}, errUniqueConstraint
7266
7265
}
7267
7266
}
7268
7267
@@ -7873,7 +7872,7 @@ func (q *FakeQuerier) UpdateWorkspace(_ context.Context, arg database.UpdateWork
7873
7872
continue
7874
7873
}
7875
7874
if other .Name == arg .Name {
7876
- return database.Workspace {}, errDuplicateKey
7875
+ return database.Workspace {}, errUniqueConstraint
7877
7876
}
7878
7877
}
7879
7878
@@ -8213,7 +8212,7 @@ func (q *FakeQuerier) UpdateWorkspaceProxy(_ context.Context, arg database.Updat
8213
8212
8214
8213
for _ , p := range q .workspaceProxies {
8215
8214
if p .Name == arg .Name && p .ID != arg .ID {
8216
- return database.WorkspaceProxy {}, errDuplicateKey
8215
+ return database.WorkspaceProxy {}, errUniqueConstraint
8217
8216
}
8218
8217
}
8219
8218
0 commit comments