Drizzle
Use this path when your project stores Blyp logs through Drizzle and your dialect is Postgres or MySQL.
Prerequisites
drizzle-orminstalleddrizzle-kitinstalled- a Drizzle config file exists at the project root
- a schema target exists or can be created
- the CLI can discover your DB module
The CLI looks for Drizzle config files such as drizzle.config.ts, drizzle.config.js, drizzle.config.mjs, or drizzle.config.cjs.
Naming contract
- SQL table name:
blyp_logs - Drizzle export:
blypLogs - adapter config uses
table: blypLogs
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:migrateDrizzle 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:
- if the schema target is a directory, it creates
blyp.ts - if the schema target is a file, it appends the Blyp schema to that file
It then prepares the migration workflow so the generated schema can be applied.
Failure cases
Likely Drizzle-specific failures include:
- no Drizzle config file at the project root
- no Drizzle schema hints, so the CLI cannot determine where the schema belongs
drizzle-ormmissing frompackage.jsondrizzle-kitmissing frompackage.json- the requested Blyp dialect does not match the Drizzle config dialect
- an existing
blypLogsschema exists but does not match the Blyp contract - the runtime adapter receives the wrong table symbol instead of
blypLogs