Pharmacy Management System - Copy this React, Tailwind Component to your project
Import { InferSelectModel, relations } from 'drizzle orm'; import { boolean, pgTable, real, text, timestamp, uuid } from 'drizzle orm/pg core'; // Define the 'users' table export const userTable = pgTable('users', { id: uuid('id').primaryKey().defaultRandom(), username: text('username').unique().notNull(), passwordHash: text('password_hash').notNull(), role: text('role').notNull(), createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), }); // Define the 'phones' table export const phoneTable = pgTable('phones', { id: uuid('id').primaryKey().defaultRandom(), createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), userId: uuid('user_id').references(() => userTable.id, { onDelete: 'set null', // Change to 'set null' to avoid cascade deletes }), customerId: uuid('customer_id').references(() => customerTable.id, { onDelete: 'set null', // Change to 'set null' to avoid cascade deletes }), number: text('number').unique().notNull(), type: text('type').notNull(), }); export const phoneRelations = relations(phoneTable, ({ one }) => ({ user: one(userTable, { fields: [phoneTable.userId], references: [userTable.id], }), customer: one(customerTable, { fields: [phoneTable.customerId], references: [customerTable.id], }), })); // Define the 'customers' table export const customerTable = pgTable('customers', { id: uuid('id').primaryKey().defaultRandom(), createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), firstName: text('first_name').notNull(), lastName: text('last_name').notNull(), }); // Define the 'special_orders' table export const specialOrderTable = pgTable('special_orders', { id: uuid('id').primaryKey().defaultRandom(), createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), status: text('status').default('Pending').notNull(), fulfillmentDate: timestamp('fulfillment_date'), notes: text('notes'), customerId: uuid('customer_id').references(() => customerTable.id, { onDelete: 'cascade', // Automatically delete related special orders when a customer is deleted }), }); export const specialOrderRelations = relations(specialOrderTable, ({ one, many }) => ({ customer: one(customerTable, { fields: [specialOrderTable.customerId], references: [customerTable.id], }), items: many(specialOrderItemTable), })); // Define the 'special_order_items' table export const specialOrderItemTable = pgTable('special_order_items', { id: uuid('id').primaryKey().defaultRandom(), createdAt: timestamp('created_at').defaultNow().notNull(), updatedAt: timestamp('updated_at').defaultNow().notNull(), specialOrderId: uuid('special_order_id') .notNull() .references(() => specialOrderTable.id, { onDelete: 'cascade', // Automatically delete related items when a special order is deleted }), productName: text('product_name').notNull(), description: text('description'), quantity: real('quantity').notNull(), status: text('status').default('Pending').notNull(), isUrgent: boolean('is_urgent'), }); export const specialOrderItemRelations = relations(specialOrderItemTable, ({ one }) => ({ order: one(specialOrderTable, { fields: [specialOrderItemTable.specialOrderId], references: [specialOrderTable.id], }), })); export type User = InferSelectModel<typeof userTable>; export type SpecialOrder = InferSelectModel<typeof specialOrderTable>; export type SpecialOrderItem = InferSelectModel<typeof specialOrderItemTable>; export type Customer = InferSelectModel<typeof customerTable>; export type Phone = InferSelectModel<typeof phoneTable>; create a professional pharmacy management system according to this schema in more creative way
