42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { sql } from "drizzle-orm";
|
|
import { pgTable, text, varchar, integer, boolean, timestamp, serial } from "drizzle-orm/pg-core";
|
|
import { createInsertSchema } from "drizzle-zod";
|
|
import { z } from "zod";
|
|
|
|
export const articles = pgTable("articles", {
|
|
id: serial("id").primaryKey(),
|
|
title: text("title").notNull(),
|
|
slug: varchar("slug", { length: 255 }).notNull().unique(),
|
|
excerpt: text("excerpt").notNull(),
|
|
content: text("content").notNull(),
|
|
coverImage: text("cover_image"),
|
|
category: varchar("category", { length: 100 }).notNull().default("News"),
|
|
author: varchar("author", { length: 255 }).notNull().default("Folx Music Television"),
|
|
featured: boolean("featured").notNull().default(false),
|
|
views: integer("views").notNull().default(0),
|
|
publishedAt: timestamp("published_at").notNull().defaultNow(),
|
|
});
|
|
|
|
export const insertArticleSchema = createInsertSchema(articles).omit({
|
|
id: true,
|
|
views: true,
|
|
publishedAt: true,
|
|
});
|
|
|
|
export type InsertArticle = z.infer<typeof insertArticleSchema>;
|
|
export type Article = typeof articles.$inferSelect;
|
|
|
|
export const users = pgTable("users", {
|
|
id: varchar("id").primaryKey().default(sql`gen_random_uuid()`),
|
|
username: text("username").notNull().unique(),
|
|
password: text("password").notNull(),
|
|
});
|
|
|
|
export const insertUserSchema = createInsertSchema(users).pick({
|
|
username: true,
|
|
password: true,
|
|
});
|
|
|
|
export type InsertUser = z.infer<typeof insertUserSchema>;
|
|
export type User = typeof users.$inferSelect;
|