From 0f4214f7a64483fbd216cf73c62efdc15eae355d Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:27:38 -0300 Subject: [PATCH] chore: event registry table migration --- .../20241216T160549_event_registry.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/migrations/src/migrations/20241216T160549_event_registry.ts diff --git a/scripts/migrations/src/migrations/20241216T160549_event_registry.ts b/scripts/migrations/src/migrations/20241216T160549_event_registry.ts new file mode 100644 index 0000000..0d57acc --- /dev/null +++ b/scripts/migrations/src/migrations/20241216T160549_event_registry.ts @@ -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. It's important to use Kysely and not Kysely. + * ref: https://kysely.dev/docs/migrations#migration-files + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export async function up(db: Kysely): Promise { + 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): Promise { + // Drop everything in reverse order + await db.schema.dropTable("events").execute(); +}