Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Sep 24, 2024
1 parent c6ebcb1 commit 10ad830
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,24 +622,25 @@ export class Database {
}

case "InsertAttestation": {
const attestationData = change.attestation.attestationData;
const transactionsData = change.attestation.transactionsData;

// Insert into attestations
const attestation = await this.#db
.withSchema(this.chainDataSchemaName)
.insertInto("attestations")
.values(change.attestation.attestationData)
.returning(["uid", "chainId"])
.values(attestationData)
.execute();

// Insert into attestation transactions
const transactionsData = change.attestation.transactionsData;
const attestationTxns: AttestationTxnTable[] = [];
for (let i = 0; i < transactionsData.length; i++) {
// Link transaction to attestation
attestationTxns.push({
chainId: transactionsData[i].chainId,
txnHash: transactionsData[i].txnHash,
attestationUid: attestation[0].uid,
attestationChainId: attestation[0].chainId,
attestationUid: attestationData.uid,
attestationChainId: attestationData.chainId,
});
}
await this.#db
Expand Down
20 changes: 10 additions & 10 deletions src/database/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,18 @@ export async function migrate<T>(db: Kysely<T>, schemaName: string) {
.addColumn("amountInRoundMatchToken", BIGINT_TYPE)

// Add the foreign key columns
.addColumn("attestationTxnHash", "integer")
.addColumn("attestationTxnChainId", CHAIN_ID_TYPE)
// .addColumn("attestationTxnHash", "integer")
// .addColumn("attestationTxnChainId", CHAIN_ID_TYPE)

.addPrimaryKeyConstraint("donations_pkey", ["id"])

.addForeignKeyConstraint(
"donations_attestation_txns_fkey",
["attestationTxnHash", "attestationTxnChainId"],
"attestation_txns",
["txnHash", "chainId"],
(cb) => cb.onDelete("set null")
)
// .addForeignKeyConstraint(
// "donations_attestation_txns_fkey",
// ["attestationTxnHash", "attestationTxnChainId"],
// "attestation_txns",
// ["txnHash", "chainId"],
// (cb) => cb.onDelete("set null")
// )
.execute();

await schema
Expand Down Expand Up @@ -334,7 +334,7 @@ export async function migrate<T>(db: Kysely<T>, schemaName: string) {
.addColumn("attestationChainId", CHAIN_ID_TYPE)

// Add Constraints
.addUniqueConstraint("attestation_txns_pkey", ["txnHash", "chainId"])
.addUniqueConstraint("unique_txnHash_chainId", ["txnHash", "chainId"])

.addForeignKeyConstraint(
"attestation_txns_attestations_fkey",
Expand Down

0 comments on commit 10ad830

Please sign in to comment.