27 lines
812 B
TypeScript
27 lines
812 B
TypeScript
import { pgTable, integer, json, varchar } from "drizzle-orm/pg-core";
|
|
import { relations } from "drizzle-orm";
|
|
|
|
export const usersTable = pgTable("users", {
|
|
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
|
username: varchar({ length: 50 }).notNull().unique(),
|
|
password: varchar().notNull(),
|
|
});
|
|
|
|
export const usersRelations = relations(usersTable, ({ many }) => ({
|
|
blocks: many(blocksTable),
|
|
}));
|
|
|
|
export const blocksTable = pgTable("blocks", {
|
|
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
|
tag: varchar({ length: 100 }).notNull().default(""),
|
|
lines: json().notNull().default([]),
|
|
authorId: integer(),
|
|
});
|
|
|
|
export const blocksRelations = relations(blocksTable, ({ one }) => ({
|
|
author: one(usersTable, {
|
|
fields: [blocksTable.authorId],
|
|
references: [usersTable.id],
|
|
}),
|
|
}));
|