tasks to topics relations
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { relations } from 'drizzle-orm';
|
||||||
import { integer, pgTable, serial, timestamp, varchar } from 'drizzle-orm/pg-core';
|
import { integer, pgTable, serial, timestamp, varchar } from 'drizzle-orm/pg-core';
|
||||||
import { drizzle } from 'drizzle-orm/postgres-js';
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
||||||
import postgres from 'postgres';
|
import postgres from 'postgres';
|
||||||
@@ -5,6 +6,17 @@ import postgres from 'postgres';
|
|||||||
const client = postgres('postgresql://postgres:postgres@db:5432/db');
|
const client = postgres('postgresql://postgres:postgres@db:5432/db');
|
||||||
export const db = drizzle(client, {});
|
export const db = drizzle(client, {});
|
||||||
|
|
||||||
|
export const tasks = pgTable('tasks', {
|
||||||
|
id: serial('id').primaryKey(),
|
||||||
|
name: varchar('name', { length: 256 }),
|
||||||
|
createdAt: timestamp('created_at').defaultNow(),
|
||||||
|
updatedAt: timestamp('updated_at').defaultNow()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const tasksRelations = relations(tasks, ({ many }) => ({
|
||||||
|
tasksToTopics: many(tasksToTopics)
|
||||||
|
}))
|
||||||
|
|
||||||
export const topics = pgTable('topics', {
|
export const topics = pgTable('topics', {
|
||||||
id: serial('id').primaryKey(),
|
id: serial('id').primaryKey(),
|
||||||
name: varchar('name', { length: 256 }),
|
name: varchar('name', { length: 256 }),
|
||||||
@@ -13,6 +25,30 @@ export const topics = pgTable('topics', {
|
|||||||
updatedAt: timestamp('updated_at').defaultNow()
|
updatedAt: timestamp('updated_at').defaultNow()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const topicsRelations = relations(topics, ({ many }) => ({
|
||||||
|
topicsToTasks: many(tasksToTopics)
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const tasksToTopics = pgTable('tasks_to_topics', {
|
||||||
|
taskId: integer('task_id')
|
||||||
|
.notNull()
|
||||||
|
.references(() => tasks.id),
|
||||||
|
topicId: integer('topic_id')
|
||||||
|
.notNull()
|
||||||
|
.references(() => topics.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
export const taskToTopicsRelations = relations(tasksToTopics, ({ one }) => ({
|
||||||
|
task: one(tasks, {
|
||||||
|
fields: [tasksToTopics.taskId],
|
||||||
|
references: [tasks.id]
|
||||||
|
}),
|
||||||
|
topic: one(topics, {
|
||||||
|
fields: [tasksToTopics.topicId],
|
||||||
|
references: [topics.id]
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
|
||||||
export const universities = pgTable('universities', {
|
export const universities = pgTable('universities', {
|
||||||
id: serial('id').primaryKey(),
|
id: serial('id').primaryKey(),
|
||||||
name: varchar('name', { length: 256 }),
|
name: varchar('name', { length: 256 }),
|
||||||
@@ -36,11 +72,3 @@ export const publications = pgTable('publications', {
|
|||||||
updatedAt: timestamp('updated_at').defaultNow()
|
updatedAt: timestamp('updated_at').defaultNow()
|
||||||
});
|
});
|
||||||
|
|
||||||
export const tasks = pgTable('topics', {
|
|
||||||
id: serial('id').primaryKey(),
|
|
||||||
name: varchar('name', { length: 256 }),
|
|
||||||
createdAt: timestamp('created_at').defaultNow(),
|
|
||||||
updatedAt: timestamp('updated_at').defaultNow()
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user