schema generates wrong index
I have this schema:
why is creating a composite index like:
export const historyFiles = pgTable('history_files', {
id: serial('id').primaryKey(),
fileId: integer('file_id')
.references(() => files.id)
.notNull(),
historyId: integer('history_id')
.references(() => histories.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export const historyFiles = pgTable('history_files', {
id: serial('id').primaryKey(),
fileId: integer('file_id')
.references(() => files.id)
.notNull(),
historyId: integer('history_id')
.references(() => histories.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
history_files_file_id_users_id_fk
2 Replies
can you show whole schema file? so I can generate it on my end?
also would be great if you can share kit and orm versions
export const histories = pgTable('histories', {
id: serial('id').primaryKey(),
medicalHistoryNumber: text('medical_history_number').notNull(),
doctor: text('doctor').notNull(),
division: text('division').notNull(),
comments: text('comments').notNull(),
date: timestamp('date').notNull(),
type: historyTypeEnum('type').notNull(),
state: historyStateEnum('state').notNull(),
creatorId: integer('creator_id')
.references(() => users.id)
.notNull(),
hospitalId: integer('hospital_id')
.references(() => organizations.id)
.notNull(),
providerId: integer('provider_id')
.references(() => organizations.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export const historyFiles = pgTable('history_files', {
id: serial('id').primaryKey(),
fileId: integer('file_id')
.references(() => files.id)
.notNull(),
historyId: integer('history_id')
.references(() => histories.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export const files = pgTable('files', {
id: serial('id').primaryKey(),
filename: text('filename').notNull(),
key: text('key').notNull(),
uploadedBy: integer('uploaded_by')
.references(() => users.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export const histories = pgTable('histories', {
id: serial('id').primaryKey(),
medicalHistoryNumber: text('medical_history_number').notNull(),
doctor: text('doctor').notNull(),
division: text('division').notNull(),
comments: text('comments').notNull(),
date: timestamp('date').notNull(),
type: historyTypeEnum('type').notNull(),
state: historyStateEnum('state').notNull(),
creatorId: integer('creator_id')
.references(() => users.id)
.notNull(),
hospitalId: integer('hospital_id')
.references(() => organizations.id)
.notNull(),
providerId: integer('provider_id')
.references(() => organizations.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export const historyFiles = pgTable('history_files', {
id: serial('id').primaryKey(),
fileId: integer('file_id')
.references(() => files.id)
.notNull(),
historyId: integer('history_id')
.references(() => histories.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export const files = pgTable('files', {
id: serial('id').primaryKey(),
filename: text('filename').notNull(),
key: text('key').notNull(),
uploadedBy: integer('uploaded_by')
.references(() => users.id)
.notNull(),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
"drizzle-orm": "^0.23.13",
"drizzle-kit": "^0.17.4",
"drizzle-orm": "^0.23.13",
"drizzle-kit": "^0.17.4",