-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
78 additions
and
68 deletions.
There are no files selected for viewing
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
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
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
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
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,11 @@ | ||
import { Database, Migrator } from '../../db' | ||
import { SequencerDbSchema } from './schema' | ||
import * as migrations from './migrations' | ||
|
||
export * from './schema' | ||
|
||
export type SequencerDb = Database<SequencerDbSchema> | ||
|
||
export const getMigrator = (db: Database<SequencerDbSchema>) => { | ||
return new Migrator(db.db, migrations) | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/pds/src/sequencer/db/migrations/20231012T200556520Z-init.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,35 @@ | ||
import { Kysely } from 'kysely' | ||
|
||
export async function up(db: Kysely<unknown>): Promise<void> { | ||
await db.schema | ||
.createTable('repo_seq') | ||
.addColumn('seq', 'integer', (col) => col.autoIncrement().primaryKey()) | ||
.addColumn('did', 'varchar', (col) => col.notNull()) | ||
.addColumn('eventType', 'varchar', (col) => col.notNull()) | ||
.addColumn('event', 'blob', (col) => col.notNull()) | ||
.addColumn('invalidated', 'int2', (col) => col.notNull().defaultTo(0)) | ||
.addColumn('sequencedAt', 'varchar', (col) => col.notNull()) | ||
.execute() | ||
// for filtering seqs based on did | ||
await db.schema | ||
.createIndex('repo_seq_did_idx') | ||
.on('repo_seq') | ||
.column('did') | ||
.execute() | ||
// for filtering seqs based on event type | ||
await db.schema | ||
.createIndex('repo_seq_event_type_idx') | ||
.on('repo_seq') | ||
.column('eventType') | ||
.execute() | ||
// for entering into the seq stream at a particular time | ||
await db.schema | ||
.createIndex('repo_seq_sequenced_at_index') | ||
.on('repo_seq') | ||
.column('sequencedAt') | ||
.execute() | ||
} | ||
|
||
export async function down(db: Kysely<unknown>): Promise<void> { | ||
await db.schema.dropTable('repo_seq').execute() | ||
} |
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,5 @@ | ||
// NOTE this file can be edited by hand, but it is also appended to by the migration:create command. | ||
// It's important that every migration is exported from here with the proper name. We'd simplify | ||
// this with kysely's FileMigrationProvider, but it doesn't play nicely with the build process. | ||
|
||
export * as _20231012T200556520Z from './20231012T200556520Z-init' |
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
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
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
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
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