feat: replace Directus with custom Node.js GraphQL backend
Removes Directus 11 and replaces it with a lean, purpose-built backend: - packages/backend/: Fastify v5 + GraphQL Yoga v5 + Pothos (code-first) with Drizzle ORM, Redis sessions (session_token cookie), argon2 auth, Nodemailer, fluent-ffmpeg, and full gamification system ported from bundle - Frontend: @directus/sdk replaced by graphql-request v7; services.ts fully rewritten with identical signatures; directus.ts now re-exports from api.ts - Cookie renamed directus_session_token → session_token - Dev proxy target updated 8055 → 4000 - compose.yml: Directus service removed, backend service added (port 4000) - Dockerfile.backend: new multi-stage image with ffmpeg - Dockerfile: bundle build step and ffmpeg removed from frontend image - data-migration.ts: one-time script to migrate all Directus/sexy_ tables Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
90
packages/backend/src/db/schema/videos.ts
Normal file
90
packages/backend/src/db/schema/videos.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
index,
|
||||
uniqueIndex,
|
||||
primaryKey,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { users } from "./users.js";
|
||||
import { files } from "./files.js";
|
||||
|
||||
export const videos = pgTable(
|
||||
"videos",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
slug: text("slug").notNull(),
|
||||
title: text("title").notNull(),
|
||||
description: text("description"),
|
||||
image: text("image").references(() => files.id, { onDelete: "set null" }),
|
||||
movie: text("movie").references(() => files.id, { onDelete: "set null" }),
|
||||
tags: text("tags").array().default([]),
|
||||
upload_date: timestamp("upload_date").notNull().defaultNow(),
|
||||
premium: boolean("premium").default(false),
|
||||
featured: boolean("featured").default(false),
|
||||
likes_count: integer("likes_count").default(0),
|
||||
plays_count: integer("plays_count").default(0),
|
||||
},
|
||||
(t) => [
|
||||
uniqueIndex("videos_slug_idx").on(t.slug),
|
||||
index("videos_upload_date_idx").on(t.upload_date),
|
||||
index("videos_featured_idx").on(t.featured),
|
||||
],
|
||||
);
|
||||
|
||||
export const video_models = pgTable(
|
||||
"video_models",
|
||||
{
|
||||
video_id: text("video_id")
|
||||
.notNull()
|
||||
.references(() => videos.id, { onDelete: "cascade" }),
|
||||
user_id: text("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.video_id, t.user_id] })],
|
||||
);
|
||||
|
||||
export const video_likes = pgTable(
|
||||
"video_likes",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
video_id: text("video_id")
|
||||
.notNull()
|
||||
.references(() => videos.id, { onDelete: "cascade" }),
|
||||
user_id: text("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
},
|
||||
(t) => [
|
||||
index("video_likes_video_idx").on(t.video_id),
|
||||
index("video_likes_user_idx").on(t.user_id),
|
||||
],
|
||||
);
|
||||
|
||||
export const video_plays = pgTable(
|
||||
"video_plays",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
video_id: text("video_id")
|
||||
.notNull()
|
||||
.references(() => videos.id, { onDelete: "cascade" }),
|
||||
user_id: text("user_id").references(() => users.id, { onDelete: "set null" }),
|
||||
session_id: text("session_id"),
|
||||
duration_watched: integer("duration_watched"),
|
||||
completed: boolean("completed").default(false),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
date_updated: timestamp("date_updated"),
|
||||
},
|
||||
(t) => [
|
||||
index("video_plays_video_idx").on(t.video_id),
|
||||
index("video_plays_user_idx").on(t.user_id),
|
||||
index("video_plays_date_idx").on(t.date_created),
|
||||
],
|
||||
);
|
||||
|
||||
export type Video = typeof videos.$inferSelect;
|
||||
export type NewVideo = typeof videos.$inferInsert;
|
||||
Reference in New Issue
Block a user