Skip to content

Commit 07b211f

Browse files
authored
feat: add transactions view to prisma seeds (#147)
1 parent 524c2ef commit 07b211f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

apps/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"generate": "prisma generate",
99
"dev": "pnpm generate && tsup --watch --onSuccess 'pnpm start'",
1010
"start": "node ./dist/index.js",
11-
"db:seed": "tsx ./prisma/seed.ts",
11+
"db:seed": "tsx ./prisma/seed",
1212
"db:seed:dev": "pnpm db:seed dev",
1313
"db:seed:prod": "pnpm db:seed prod",
1414
"db:migrate": "prisma migrate dev"

apps/api/prisma/seed.ts renamed to apps/api/prisma/seed/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
treasureRuby,
77
} from "@treasure-dev/tdk-core";
88
import { arbitrum, arbitrumSepolia, mainnet, sepolia } from "thirdweb/chains";
9+
import upsertTransactionsViewSql from "./transactions-view";
910

1011
type RemoteEnvironment = "dev" | "prod";
1112
type Environment = "local" | RemoteEnvironment;
@@ -241,6 +242,8 @@ const createProject = async ({
241242
});
242243
}
243244

245+
await upsertTransactionsViewSql(prisma);
246+
244247
await prisma.$disconnect();
245248
} catch (err) {
246249
console.error(err);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Prisma, type PrismaClient } from "@prisma/client";
2+
3+
const upsertTransactionsViewSql = Prisma.sql`
4+
CREATE OR REPLACE VIEW
5+
"smart_account"."transactions" AS (
6+
SELECT
7+
(body ->> 'chain'::text) AS chain,
8+
(body ->> 'chain_id'::text) AS chain_id,
9+
to_timestamp((((body ->> 'block_timestamp'::text))::numeric)::double precision) AS block_timestamp,
10+
(body ->> 'to_address'::text) AS to_address,
11+
(body ->> 'id'::text) AS id,
12+
(body ->> 'from_address'::text) AS from_address,
13+
(body ->> 'transaction_hash'::text) AS transaction_hash,
14+
((body ->> 'block_number'::text))::numeric AS block_number,
15+
((body ->> 'value'::text))::numeric AS value,
16+
((body ->> 'transaction_index'::text))::numeric AS transaction_index
17+
FROM
18+
smart_account.transactions_jsonb
19+
);
20+
`;
21+
22+
export default (prisma: PrismaClient) => {
23+
return prisma.$queryRaw(upsertTransactionsViewSql);
24+
};

0 commit comments

Comments
 (0)