File tree 2 files changed +36
-2
lines changed 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import { DBAccountEntry } from './typeorm/entity/db-account-entry';
14
14
import { TransactionalAccountingDBImpl } from './typeorm/accounting-db-impl' ;
15
15
import { DBWorkspace } from './typeorm/entity/db-workspace' ;
16
16
import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance' ;
17
- import { DBSubscription } from './typeorm/entity/db-subscription' ;
17
+ import { DBPaymentSourceInfo , DBSubscription } from './typeorm/entity/db-subscription' ;
18
18
import { testContainer } from './test-container' ;
19
19
import { TypeORM } from './typeorm/typeorm' ;
20
20
const expect = chai . expect ;
@@ -136,6 +136,28 @@ export class AccountingDBSpec {
136
136
expectExactlyOne ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , rightBefore ( later ) ) , dbSubscription ) ;
137
137
expect ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , later ) ) . to . be . an ( 'array' ) . and . empty ;
138
138
}
139
+
140
+ // see https://github.com/gitpod-io/gitpod/issues/7171
141
+ @test public async bug7171 ( ) {
142
+ const paymentSourceInfo : DBPaymentSourceInfo = {
143
+ id : "bar" ,
144
+ resourceVersion : 1 ,
145
+ userId : "foo" ,
146
+ status : "valid" ,
147
+ cardExpiryMonth : 12 ,
148
+ cardExpiryYear : 2021
149
+ } ;
150
+ await this . db . storePaymentSourceInfo ( paymentSourceInfo ) ;
151
+ const paymentSourceInfo2 : DBPaymentSourceInfo = {
152
+ id : "bar" ,
153
+ resourceVersion : 1 ,
154
+ userId : "foo" ,
155
+ status : "expiring" ,
156
+ cardExpiryMonth : 12 ,
157
+ cardExpiryYear : 2021
158
+ } ;
159
+ await this . db . storePaymentSourceInfo ( paymentSourceInfo2 ) ;
160
+ }
139
161
}
140
162
141
163
const expectExactlyOne = < T > ( result : T [ ] , expectation : T ) => {
Original file line number Diff line number Diff line change @@ -260,7 +260,19 @@ export class TypeORMAccountingDBImpl implements AccountingDB {
260
260
261
261
async storePaymentSourceInfo ( info : DBPaymentSourceInfo ) : Promise < DBPaymentSourceInfo > {
262
262
const repo = await this . getPaymentSourceRepo ( ) ;
263
- return repo . save ( info ) ;
263
+ // see https://github.com/gitpod-io/gitpod/issues/7171
264
+ // TypeORM seems to have problems with number type primary columns
265
+ const existing = await repo . findOne ( { id : info . id , resourceVersion : info . resourceVersion } ) ;
266
+ if ( existing ) {
267
+ for ( const prop in info ) {
268
+ if ( prop != "resourceVersion" ) {
269
+ ( existing as any ) [ prop ] = ( info as any ) [ prop ] ;
270
+ }
271
+ }
272
+ return repo . save ( existing ) ;
273
+ } else {
274
+ return repo . save ( info ) ;
275
+ }
264
276
}
265
277
}
266
278
You can’t perform that action at this time.
0 commit comments