-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.ts
43 lines (40 loc) · 2.06 KB
/
schema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { index, integer, primaryKey, real, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core'
export const validators = sqliteTable('validators', {
id: integer('id').primaryKey({ autoIncrement: true, onConflict: 'replace' }),
name: text('name').default('Unknown validator').notNull(),
address: text('address').notNull().unique(),
description: text('description'),
fee: real('fee').default(-1),
isPool: integer('is_pool', { mode: 'boolean' }).default(false),
isMaintainedByNimiq: integer('is_maintained_by_nimiq', { mode: 'boolean' }).default(false),
icon: text('icon').notNull(),
website: text('website'),
}, table => ({
uniqueAddress: uniqueIndex('validators_address_unique').on(table.address),
}))
export const scores = sqliteTable('scores', {
validatorId: integer('validator_id').notNull().references(() => validators.id, { onDelete: 'cascade' }),
fromEpoch: integer('from_epoch').notNull(),
toEpoch: integer('to_epoch').notNull(),
total: real('total').notNull(),
liveness: real('liveness').notNull(),
size: real('size').notNull(),
reliability: real('reliability').notNull(),
}, table => ({
idxValidatorId: index('idx_validator_id').on(table.validatorId),
compositePrimaryKey: primaryKey({ columns: [table.validatorId, table.fromEpoch, table.toEpoch] }),
}))
export const activity = sqliteTable('activity', {
validatorId: integer('validator_id').notNull().references(() => validators.id, { onDelete: 'cascade' }),
epochNumber: integer('epoch_number').notNull(),
likelihood: integer('likelihood').notNull(),
rewarded: integer('rewarded').notNull(),
missed: integer('missed').notNull(),
sizeRatio: integer('size_ratio').notNull(),
// TODO Remove sizeRatioViaSlots bool and instead store also the sizeRatioPrecise
// sizeRatioViaSlots: integer('size_ratio_via_slots').notNull(),
sizeRatioViaSlots: integer('size_ratio_via_slots', { mode: 'boolean' }).notNull(),
}, table => ({
idxElectionBlock: index('idx_election_block').on(table.epochNumber),
compositePrimaryKey: primaryKey({ columns: [table.validatorId, table.epochNumber] }),
}))