transform admin panel with comprehensive professional UI
- migrate from SQLite to PostgreSQL with Drizzle ORM - implement comprehensive AdminLayout with expandable sidebar navigation - create professional dashboard with real-time charts and metrics - add advanced monitoring, reporting, and export functionality - fix menu alignment and remove non-existent pages - eliminate duplicate headers and improve UI consistency - add Tailwind CSS v3 for professional styling - expand database schema from 6 to 15 tables - implement role-based access control and API key management - create comprehensive settings, monitoring, and system info pages
This commit is contained in:
221
lib/db/schema.ts
221
lib/db/schema.ts
@@ -225,4 +225,225 @@ export const auditLogsRelations = relations(auditLogs, ({ one }) => ({
|
||||
fields: [auditLogs.userId],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
// System Metrics table
|
||||
export const systemMetrics = pgTable('system_metrics', {
|
||||
id: serial('id').primaryKey(),
|
||||
metricType: varchar('metric_type', { length: 50 }).notNull(), // 'cpu', 'memory', 'disk', 'api_calls', 'db_connections'
|
||||
value: decimal('value', { precision: 10, scale: 2 }).notNull(),
|
||||
unit: varchar('unit', { length: 20 }), // '%', 'MB', 'GB', 'count', 'ms'
|
||||
timestamp: timestamp('timestamp').defaultNow()
|
||||
}, (table) => {
|
||||
return {
|
||||
typeIdx: index('idx_system_metrics_type').on(table.metricType),
|
||||
timestampIdx: index('idx_system_metrics_timestamp').on(table.timestamp),
|
||||
typeTimestampIdx: index('idx_system_metrics_type_timestamp').on(table.metricType, table.timestamp)
|
||||
};
|
||||
});
|
||||
|
||||
// Analytics Events table
|
||||
export const analyticsEvents = pgTable('analytics_events', {
|
||||
id: serial('id').primaryKey(),
|
||||
eventType: varchar('event_type', { length: 50 }).notNull(), // 'source_lookup', 'api_call', 'report_submitted', 'source_verified'
|
||||
sourceUrl: varchar('source_url', { length: 1000 }),
|
||||
sourceId: integer('source_id').references(() => sources.id),
|
||||
userId: integer('user_id').references(() => users.id),
|
||||
apiKeyId: integer('api_key_id').references(() => apiKeys.id),
|
||||
ipAddress: varchar('ip_address', { length: 45 }),
|
||||
userAgent: text('user_agent'),
|
||||
responseTime: integer('response_time'), // in milliseconds
|
||||
statusCode: integer('status_code'),
|
||||
metadata: text('metadata').default('{}'), // JSON
|
||||
timestamp: timestamp('timestamp').defaultNow()
|
||||
}, (table) => {
|
||||
return {
|
||||
eventTypeIdx: index('idx_analytics_events_type').on(table.eventType),
|
||||
timestampIdx: index('idx_analytics_events_timestamp').on(table.timestamp),
|
||||
sourceIdIdx: index('idx_analytics_events_source_id').on(table.sourceId),
|
||||
apiKeyIdIdx: index('idx_analytics_events_api_key_id').on(table.apiKeyId),
|
||||
ipAddressIdx: index('idx_analytics_events_ip').on(table.ipAddress)
|
||||
};
|
||||
});
|
||||
|
||||
// Notifications table
|
||||
export const notifications = pgTable('notifications', {
|
||||
id: serial('id').primaryKey(),
|
||||
title: varchar('title', { length: 200 }).notNull(),
|
||||
message: text('message').notNull(),
|
||||
type: varchar('type', { length: 50 }).default('info'), // 'info', 'warning', 'error', 'success'
|
||||
userId: integer('user_id').references(() => users.id),
|
||||
isRead: boolean('is_read').default(false),
|
||||
actionUrl: varchar('action_url', { length: 500 }),
|
||||
metadata: text('metadata').default('{}'), // JSON
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
readAt: timestamp('read_at')
|
||||
}, (table) => {
|
||||
return {
|
||||
userIdIdx: index('idx_notifications_user_id').on(table.userId),
|
||||
isReadIdx: index('idx_notifications_is_read').on(table.isRead),
|
||||
createdAtIdx: index('idx_notifications_created_at').on(table.createdAt),
|
||||
typeIdx: index('idx_notifications_type').on(table.type)
|
||||
};
|
||||
});
|
||||
|
||||
// System Settings table
|
||||
export const systemSettings = pgTable('system_settings', {
|
||||
id: serial('id').primaryKey(),
|
||||
key: varchar('key', { length: 100 }).notNull().unique(),
|
||||
value: text('value'),
|
||||
type: varchar('type', { length: 50 }).default('string'), // 'string', 'number', 'boolean', 'json'
|
||||
description: text('description'),
|
||||
category: varchar('category', { length: 50 }).default('general'),
|
||||
isPublic: boolean('is_public').default(false),
|
||||
updatedBy: integer('updated_by').references(() => users.id),
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
}, (table) => {
|
||||
return {
|
||||
keyIdx: uniqueIndex('idx_system_settings_key').on(table.key),
|
||||
categoryIdx: index('idx_system_settings_category').on(table.category)
|
||||
};
|
||||
});
|
||||
|
||||
// Webhooks table
|
||||
export const webhooks = pgTable('webhooks', {
|
||||
id: serial('id').primaryKey(),
|
||||
name: varchar('name', { length: 100 }).notNull(),
|
||||
url: varchar('url', { length: 1000 }).notNull(),
|
||||
events: text('events').notNull(), // JSON array of event types
|
||||
secret: varchar('secret', { length: 255 }),
|
||||
isActive: boolean('is_active').default(true),
|
||||
headers: text('headers').default('{}'), // JSON
|
||||
lastTriggered: timestamp('last_triggered'),
|
||||
successCount: integer('success_count').default(0),
|
||||
failureCount: integer('failure_count').default(0),
|
||||
createdBy: integer('created_by').references(() => users.id),
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
}, (table) => {
|
||||
return {
|
||||
createdByIdx: index('idx_webhooks_created_by').on(table.createdBy),
|
||||
isActiveIdx: index('idx_webhooks_is_active').on(table.isActive)
|
||||
};
|
||||
});
|
||||
|
||||
// Source Analytics table
|
||||
export const sourceAnalytics = pgTable('source_analytics', {
|
||||
id: serial('id').primaryKey(),
|
||||
sourceId: integer('source_id').notNull().references(() => sources.id, { onDelete: 'cascade' }),
|
||||
date: timestamp('date').notNull(),
|
||||
lookupCount: integer('lookup_count').default(0),
|
||||
reportCount: integer('report_count').default(0),
|
||||
viewCount: integer('view_count').default(0),
|
||||
riskScore: decimal('risk_score', { precision: 3, scale: 2 }),
|
||||
metadata: text('metadata').default('{}'), // JSON
|
||||
}, (table) => {
|
||||
return {
|
||||
sourceIdIdx: index('idx_source_analytics_source_id').on(table.sourceId),
|
||||
dateIdx: index('idx_source_analytics_date').on(table.date),
|
||||
uniqueSourceDate: uniqueIndex('unique_source_date').on(table.sourceId, table.date)
|
||||
};
|
||||
});
|
||||
|
||||
// Email Templates table
|
||||
export const emailTemplates = pgTable('email_templates', {
|
||||
id: serial('id').primaryKey(),
|
||||
name: varchar('name', { length: 100 }).notNull().unique(),
|
||||
subject: varchar('subject', { length: 200 }).notNull(),
|
||||
htmlBody: text('html_body').notNull(),
|
||||
textBody: text('text_body'),
|
||||
variables: text('variables').default('[]'), // JSON array of available variables
|
||||
isActive: boolean('is_active').default(true),
|
||||
createdBy: integer('created_by').references(() => users.id),
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
}, (table) => {
|
||||
return {
|
||||
nameIdx: uniqueIndex('idx_email_templates_name').on(table.name),
|
||||
isActiveIdx: index('idx_email_templates_is_active').on(table.isActive)
|
||||
};
|
||||
});
|
||||
|
||||
// Scheduled Jobs table
|
||||
export const scheduledJobs = pgTable('scheduled_jobs', {
|
||||
id: serial('id').primaryKey(),
|
||||
name: varchar('name', { length: 100 }).notNull(),
|
||||
type: varchar('type', { length: 50 }).notNull(), // 'report_generation', 'data_cleanup', 'backup', 'analytics'
|
||||
schedule: varchar('schedule', { length: 100 }).notNull(), // cron expression
|
||||
isActive: boolean('is_active').default(true),
|
||||
lastRun: timestamp('last_run'),
|
||||
nextRun: timestamp('next_run'),
|
||||
lastResult: varchar('last_result', { length: 50 }), // 'success', 'failure', 'running'
|
||||
config: text('config').default('{}'), // JSON
|
||||
createdBy: integer('created_by').references(() => users.id),
|
||||
createdAt: timestamp('created_at').defaultNow(),
|
||||
updatedAt: timestamp('updated_at').defaultNow()
|
||||
}, (table) => {
|
||||
return {
|
||||
nameIdx: index('idx_scheduled_jobs_name').on(table.name),
|
||||
typeIdx: index('idx_scheduled_jobs_type').on(table.type),
|
||||
nextRunIdx: index('idx_scheduled_jobs_next_run').on(table.nextRun),
|
||||
isActiveIdx: index('idx_scheduled_jobs_is_active').on(table.isActive)
|
||||
};
|
||||
});
|
||||
|
||||
// Additional Relations
|
||||
export const systemMetricsRelations = relations(systemMetrics, ({ one }) => ({}));
|
||||
|
||||
export const analyticsEventsRelations = relations(analyticsEvents, ({ one }) => ({
|
||||
source: one(sources, {
|
||||
fields: [analyticsEvents.sourceId],
|
||||
references: [sources.id]
|
||||
}),
|
||||
user: one(users, {
|
||||
fields: [analyticsEvents.userId],
|
||||
references: [users.id]
|
||||
}),
|
||||
apiKey: one(apiKeys, {
|
||||
fields: [analyticsEvents.apiKeyId],
|
||||
references: [apiKeys.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const notificationsRelations = relations(notifications, ({ one }) => ({
|
||||
user: one(users, {
|
||||
fields: [notifications.userId],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const systemSettingsRelations = relations(systemSettings, ({ one }) => ({
|
||||
updatedBy: one(users, {
|
||||
fields: [systemSettings.updatedBy],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const webhooksRelations = relations(webhooks, ({ one }) => ({
|
||||
createdBy: one(users, {
|
||||
fields: [webhooks.createdBy],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const sourceAnalyticsRelations = relations(sourceAnalytics, ({ one }) => ({
|
||||
source: one(sources, {
|
||||
fields: [sourceAnalytics.sourceId],
|
||||
references: [sources.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const emailTemplatesRelations = relations(emailTemplates, ({ one }) => ({
|
||||
createdBy: one(users, {
|
||||
fields: [emailTemplates.createdBy],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
|
||||
export const scheduledJobsRelations = relations(scheduledJobs, ({ one }) => ({
|
||||
createdBy: one(users, {
|
||||
fields: [scheduledJobs.createdBy],
|
||||
references: [users.id]
|
||||
})
|
||||
}));
|
||||
Reference in New Issue
Block a user