schema/events.ts

meterguard · packages/database/src/schema/events.ts · typescript · MIT
database

Drizzle ORM schema defining an immutable events table for usage logging.

// Source: https://github.com/geminimir/meterguard | License: MIT | Copyright 2025 StripeMeter Contributors
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Events table schema - The immutable ledger of all usage events
 */

import { pgTable, text, uuid, numeric, timestamp, jsonb, index } from 'drizzle-orm/pg-core';

export const events = pgTable('events', {
  // Primary key - deterministic idempotency key
  idempotencyKey: text('idempotency_key').primaryKey(),
  
  // Core fields
  tenantId: uuid('tenant_id').notNull(),
  metric: text('metric').notNull(),
  customerRef: text('customer_ref').notNull(),
  resourceId: text('resource_id'),
  quantity: numeric('quantity', { precision: 20, scale: 6 }).notNull(),
  ts: timestamp('ts', { withTimezone: true }).notNull(),
  m

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key