mattvalgreen
mattvalgreen
DTDrizzle Team
Created by mattvalgreen on 11/2/2024 in #help
Foreign Key, is this method deprecated?
facing a lot of problems using this syntax, somebody can help me? import { foreignKey, index, pgTable, primaryKey, text, timestamp, uuid, } from "drizzle-orm/pg-core"; export const profiles = pgTable("profiles", { id: uuid("id").primaryKey().notNull(), username: text("username").notNull().unique(), createAt: timestamp("created_at").defaultNow().notNull(), }); export const posts = pgTable( "posts", { id: uuid("id").primaryKey().notNull().defaultRandom(), profileId: uuid("profile_id") .notNull() .references(() => profiles.id), parentId: uuid("parent_id"), content: text("content").notNull(), createAt: timestamp("created_at").defaultNow().notNull(), }, (table) => ({ parentReference: foreignKey({ columns: [table.parentId], foreignColumns: [table.id], name: "post_parent_id_fkey", }), createdAtIdx: index("posts_created_at_idx").on(table.createAt), profileIdIdx: index("posts_profile_id_idx").on(table.profileId), parentIdIdx: index("posts_parent_id_idx").on(table.parentId), }) );
3 replies