generated from defi-wonderland/ts-turborepo-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: event registry table migration
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
scripts/migrations/src/migrations/20241216T160549_event_registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Kysely } from "kysely"; | ||
|
||
/** | ||
* The up function is called when you update your database schema to the next version and down when you go back to previous version. | ||
* The only argument for the functions is an instance of Kysely<any>. It's important to use Kysely<any> and not Kysely<YourDatabase>. | ||
* ref: https://kysely.dev/docs/migrations#migration-files | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export async function up(db: Kysely<any>): Promise<void> { | ||
const CHAIN_ID_TYPE = "integer"; | ||
|
||
await db.schema | ||
.createTable("events") | ||
.addColumn("chainId", CHAIN_ID_TYPE) | ||
.addColumn("blockNumber", "integer") | ||
.addColumn("blockTimestamp", "integer") | ||
.addColumn("logIndex", "integer") | ||
.addColumn("rawEvent", "jsonb") | ||
.addPrimaryKeyConstraint("events_pkey", ["chainId"]) | ||
.execute(); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export async function down(db: Kysely<any>): Promise<void> { | ||
// Drop everything in reverse order | ||
await db.schema.dropTable("events").execute(); | ||
} |