Closed pitzzahh closed 1 month ago
The way you have it set up should work. Can you show me a snippet where I can see how you're defining relations?
The way you have it set up should work. Can you show me a snippet where I can see how you're defining relations?
Hi, thanks for the response. It works now, it was my fault that I did not include the relations as an export. I thought it works out of the box. I now created a sub directory containing the table relations and it now generates it properly.
import { pgTable, text, timestamp } from 'drizzle-orm/pg-core';
import { relations } from 'drizzle-orm';
import { employee } from '.';
import { createId } from '@paralleldrive/cuid2';
const appointmentInformation = pgTable('appointment_info', {
id: text('id')
.primaryKey()
.$defaultFn(() => createId()),
createdAt: timestamp('created_at', { precision: 3 }).defaultNow(),
updatedAt: timestamp('updated_at', { precision: 3 }).$onUpdate(() => new Date()),
appointmentDate: timestamp('appointment_date', { precision: 3 }).notNull(),
lastPromotionDate: timestamp('last_promotion', { precision: 3 }).notNull(),
employeeId: text('employee_id').notNull()
});
export const appointmentStatusRelations = relations(appointmentInformation, ({ one }) => {
return {
employee: one(employee, {
fields: [appointmentInformation.employeeId],
references: [employee.id]
})
};
});
export default appointmentInformation;
import { pgTable, text, timestamp } from 'drizzle-orm/pg-core'; import { relations } from 'drizzle-orm'; import { employee } from '.'; import { createId } from '@paralleldrive/cuid2'; const appointmentInformation = pgTable('appointment_info', { id: text('id') .primaryKey() .$defaultFn(() => createId()), createdAt: timestamp('created_at', { precision: 3 }).defaultNow(), updatedAt: timestamp('updated_at', { precision: 3 }).$onUpdate(() => new Date()), appointmentDate: timestamp('appointment_date', { precision: 3 }).notNull(), lastPromotionDate: timestamp('last_promotion', { precision: 3 }).notNull(), employeeId: text('employee_id').notNull() }); export const appointmentStatusRelations = relations(appointmentInformation, ({ one }) => { return { employee: one(employee, { fields: [appointmentInformation.employeeId], references: [employee.id] }) }; }); export default appointmentInformation;
this was fixed by separating the relations to a new file.
Hi. It generated the dbml and the svg output, however the relations are not present.
I have my schema per file and merged them in an index.ts, does it work with this? or does it need to be in a single schema file?
1 directory, 27 files `
export const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
const db = drizzle(pool, { schema }); const out = './schema.dbml'; const relational = true;
console.info(pgGenerate({ schema, out, relational }));
export default db;