feat(backend): initial setup for cms backend service
This commit is contained in:
62
backend/src/db/schema.ts
Normal file
62
backend/src/db/schema.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
// Users table - stores Gitea user info for audit and access control
|
||||
export const users = sqliteTable('users', {
|
||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
giteaId: text('gitea_id').notNull().unique(),
|
||||
giteaUsername: text('gitea_username').notNull(),
|
||||
giteaEmail: text('gitea_email'),
|
||||
displayName: text('display_name'),
|
||||
avatarUrl: text('avatar_url'),
|
||||
role: text('role').default('admin'),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).default(sql`(unixepoch())`),
|
||||
lastLogin: integer('last_login', { mode: 'timestamp' }),
|
||||
});
|
||||
|
||||
// Events table
|
||||
export const events = sqliteTable('events', {
|
||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
title: text('title').notNull(),
|
||||
date: text('date').notNull(),
|
||||
description: text('description').notNull(),
|
||||
imageUrl: text('image_url').notNull(),
|
||||
displayOrder: integer('display_order').notNull(),
|
||||
isPublished: integer('is_published', { mode: 'boolean' }).default(true),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).default(sql`(unixepoch())`),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).default(sql`(unixepoch())`),
|
||||
});
|
||||
|
||||
// Gallery images table
|
||||
export const galleryImages = sqliteTable('gallery_images', {
|
||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
imageUrl: text('image_url').notNull(),
|
||||
altText: text('alt_text').notNull(),
|
||||
displayOrder: integer('display_order').notNull(),
|
||||
isPublished: integer('is_published', { mode: 'boolean' }).default(true),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).default(sql`(unixepoch())`),
|
||||
});
|
||||
|
||||
// Content sections table (for text-based sections)
|
||||
export const contentSections = sqliteTable('content_sections', {
|
||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
sectionName: text('section_name').notNull().unique(),
|
||||
contentJson: text('content_json', { mode: 'json' }).notNull(),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).default(sql`(unixepoch())`),
|
||||
});
|
||||
|
||||
// Site settings table (global config)
|
||||
export const siteSettings = sqliteTable('site_settings', {
|
||||
key: text('key').primaryKey(),
|
||||
value: text('value').notNull(),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).default(sql`(unixepoch())`),
|
||||
});
|
||||
|
||||
// Publish history (audit log)
|
||||
export const publishHistory = sqliteTable('publish_history', {
|
||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
userId: text('user_id').references(() => users.id),
|
||||
commitHash: text('commit_hash'),
|
||||
commitMessage: text('commit_message'),
|
||||
publishedAt: integer('published_at', { mode: 'timestamp' }).default(sql`(unixepoch())`),
|
||||
});
|
||||
Reference in New Issue
Block a user