Blyp Docs

Drizzle

Use this path when your project stores Blyp logs through Drizzle and your dialect is Postgres or MySQL.

Prerequisites

The CLI looks for Drizzle config files such as drizzle.config.ts, drizzle.config.js, drizzle.config.mjs, or drizzle.config.cjs.

Naming contract

Generated blypLogs schema for Postgres

import {
  boolean,
  doublePrecision,
  index,
  integer,
  jsonb,
  pgTable,
  text,
  timestamp,
  uuid,
  varchar,
} from "drizzle-orm/pg-core";

export const blypLogs = pgTable(
  "blyp_logs",
  {
    id: uuid("id").primaryKey(),
    timestamp: timestamp("timestamp", { withTimezone: true, precision: 6 }).notNull(),
    level: varchar("level", { length: 32 }).notNull(),
    message: text("message").notNull(),
    caller: text("caller"),
    type: varchar("type", { length: 64 }),
    groupId: varchar("group_id", { length: 191 }),
    method: varchar("method", { length: 16 }),
    path: text("path"),
    status: integer("status"),
    duration: doublePrecision("duration"),
    hasError: boolean("has_error").notNull(),
    data: jsonb("data"),
    bindings: jsonb("bindings"),
    error: jsonb("error"),
    events: jsonb("events"),
    record: jsonb("record").notNull(),
    createdAt: timestamp("created_at", { withTimezone: true, precision: 6 })
      .defaultNow()
      .notNull(),
  },
  (table) => [
    index("blyp_logs_timestamp_idx").on(table.timestamp),
    index("blyp_logs_level_timestamp_idx").on(table.level, table.timestamp),
    index("blyp_logs_type_timestamp_idx").on(table.type, table.timestamp),
    index("blyp_logs_group_id_timestamp_idx").on(table.groupId, table.timestamp),
  ],
);

Generated blypLogs schema for MySQL

import {
  boolean,
  datetime,
  double,
  index,
  int,
  json,
  mysqlTable,
  text,
  varchar,
} from "drizzle-orm/mysql-core";

export const blypLogs = mysqlTable(
  "blyp_logs",
  {
    id: varchar("id", { length: 36 }).primaryKey(),
    timestamp: datetime("timestamp", { fsp: 6, mode: "date" }).notNull(),
    level: varchar("level", { length: 32 }).notNull(),
    message: text("message").notNull(),
    caller: text("caller"),
    type: varchar("type", { length: 64 }),
    groupId: varchar("group_id", { length: 191 }),
    method: varchar("method", { length: 16 }),
    path: text("path"),
    status: int("status"),
    duration: double("duration"),
    hasError: boolean("has_error").notNull(),
    data: json("data"),
    bindings: json("bindings"),
    error: json("error"),
    events: json("events"),
    record: json("record").notNull(),
    createdAt: datetime("created_at", { fsp: 6, mode: "date" }).defaultNow().notNull(),
  },
  (table) => [
    index("blyp_logs_timestamp_idx").on(table.timestamp),
    index("blyp_logs_level_timestamp_idx").on(table.level, table.timestamp),
    index("blyp_logs_type_timestamp_idx").on(table.type, table.timestamp),
    index("blyp_logs_group_id_timestamp_idx").on(table.groupId, table.timestamp),
  ],
);

For the field-by-field contract, see Schema Contract.

blyp.config.ts example

import { createDrizzleDatabaseAdapter } from "@blyp/core/database";
import { db } from "./db";
import { blypLogs } from "./db/schema/blyp";

export default {
  destination: "database",
  database: {
    dialect: "postgres",
    adapter: createDrizzleDatabaseAdapter({
      db,
      table: blypLogs,
    }),
  },
};

Migration flow

blyp db:init
blyp db:migrate

Drizzle projects do not use blyp db:generate.

What blyp db:init does for Drizzle

The CLI resolves the Drizzle config, locates the schema target, finds the DB module, and then writes the Blyp schema in one of two ways:

It then prepares the migration workflow so the generated schema can be applied.

Failure cases

Likely Drizzle-specific failures include: