This commit is contained in:
38
src/lib/server/db/schema/progress.ts
Normal file
38
src/lib/server/db/schema/progress.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { integer, pgTable, text, unique } from 'drizzle-orm/pg-core';
|
||||
import { id, timestamps } from './helpers';
|
||||
|
||||
export const tasks = pgTable('tasks', {
|
||||
id: id(),
|
||||
name: text('name').notNull(),
|
||||
currentPoints: integer('current_points').notNull().default(0),
|
||||
totalPoints: integer('total_points').notNull().default(1),
|
||||
notes: text('notes'),
|
||||
...timestamps
|
||||
});
|
||||
|
||||
export const topics = pgTable('topics', {
|
||||
id: id(),
|
||||
name: text('name').notNull(),
|
||||
emoji: text('emoji'),
|
||||
...timestamps
|
||||
});
|
||||
|
||||
export const tasksToTopics = pgTable(
|
||||
'tasks_to_topics',
|
||||
{
|
||||
id: id(),
|
||||
taskId: integer('task_id')
|
||||
.notNull()
|
||||
.references(() => tasks.id, { onDelete: 'cascade' }),
|
||||
topicId: integer('topic_id')
|
||||
.notNull()
|
||||
.references(() => topics.id, { onDelete: 'cascade' }),
|
||||
...timestamps
|
||||
},
|
||||
(table) => [unique().on(table.taskId, table.topicId)]
|
||||
);
|
||||
|
||||
export type Task = typeof tasks.$inferSelect;
|
||||
export type NewTask = typeof tasks.$inferInsert;
|
||||
export type Topic = typeof topics.$inferSelect;
|
||||
export type NewTopic = typeof topics.$inferInsert;
|
||||
Reference in New Issue
Block a user