@@ -275,8 +275,17 @@ export async function migrate<T>(db: Kysely<T>, schemaName: string) {
275275 . addColumn ( "amountInUSD" , "real" )
276276 . addColumn ( "amountInRoundMatchToken" , BIGINT_TYPE )
277277
278+ . addColumn ( "attestationTxnId" , "integer" )
279+
278280 . addPrimaryKeyConstraint ( "donations_pkey" , [ "id" ] )
279281
282+ . addForeignKeyConstraint (
283+ "donations_attestation_txns_fkey" ,
284+ [ "attestationTxnId" ] ,
285+ "attestation_txns" ,
286+ [ "id" ] ,
287+ ( cb ) => cb . onDelete ( "set null" )
288+ )
280289 . execute ( ) ;
281290
282291 await schema
@@ -299,6 +308,7 @@ export async function migrate<T>(db: Kysely<T>, schemaName: string) {
299308
300309 await schema
301310 . createTable ( "attestations" )
311+ . addColumn ( "id" , "serial" , ( col ) => col . primaryKey ( ) )
302312 . addColumn ( "uid" , "text" )
303313 . addColumn ( "chainId" , CHAIN_ID_TYPE )
304314 . addColumn ( "fee" , BIGINT_TYPE )
@@ -310,20 +320,19 @@ export async function migrate<T>(db: Kysely<T>, schemaName: string) {
310320 . addColumn ( "timestamp" , "timestamptz" )
311321 . addColumn ( "metadataCid" , "text" )
312322 . addColumn ( "metadata" , "jsonb" )
313- . addPrimaryKeyConstraint ( "gitcoin_attestations_pkey" , [ "uid" , "chainId" ] )
323+ . addUniqueConstraint ( "gitcoin_attestations_pkey" , [ "uid" , "chainId" ] )
314324 . execute ( ) ;
315325
316- // Should we link donation to attesation tx?
317-
318326 await schema
319327 . createTable ( "attestation_txns" )
328+ . addColumn ( "id" , "serial" , ( col ) => col . primaryKey ( ) )
320329 . addColumn ( "txnHash" , "text" )
321330 . addColumn ( "chainId" , CHAIN_ID_TYPE )
322331
323332 . addColumn ( "attestationUid" , "text" )
324333 . addColumn ( "attestationChainId" , CHAIN_ID_TYPE )
325334
326- . addPrimaryKeyConstraint ( "attestation_txns_pkey" , [ "txnHash" , "chainId" ] )
335+ . addUniqueConstraint ( "attestation_txns_pkey" , [ "txnHash" , "chainId" ] )
327336
328337 . addForeignKeyConstraint (
329338 "attestation_txns_attestations_fkey" ,
0 commit comments