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:
37
packages/backend/src/db/schema/articles.ts
Normal file
37
packages/backend/src/db/schema/articles.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
index,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { users } from "./users.js";
|
||||
import { files } from "./files.js";
|
||||
|
||||
export const articles = pgTable(
|
||||
"articles",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
slug: text("slug").notNull(),
|
||||
title: text("title").notNull(),
|
||||
excerpt: text("excerpt"),
|
||||
content: text("content"),
|
||||
image: text("image").references(() => files.id, { onDelete: "set null" }),
|
||||
tags: text("tags").array().default([]),
|
||||
publish_date: timestamp("publish_date").notNull().defaultNow(),
|
||||
author: text("author").references(() => users.id, { onDelete: "set null" }),
|
||||
category: text("category"),
|
||||
featured: boolean("featured").default(false),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
date_updated: timestamp("date_updated"),
|
||||
},
|
||||
(t) => [
|
||||
uniqueIndex("articles_slug_idx").on(t.slug),
|
||||
index("articles_publish_date_idx").on(t.publish_date),
|
||||
index("articles_featured_idx").on(t.featured),
|
||||
],
|
||||
);
|
||||
|
||||
export type Article = typeof articles.$inferSelect;
|
||||
export type NewArticle = typeof articles.$inferInsert;
|
||||
30
packages/backend/src/db/schema/comments.ts
Normal file
30
packages/backend/src/db/schema/comments.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
index,
|
||||
integer,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { users } from "./users.js";
|
||||
|
||||
export const comments = pgTable(
|
||||
"comments",
|
||||
{
|
||||
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
|
||||
collection: text("collection").notNull(), // 'videos' | 'recordings'
|
||||
item_id: text("item_id").notNull(),
|
||||
comment: text("comment").notNull(),
|
||||
user_id: text("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
date_updated: timestamp("date_updated"),
|
||||
},
|
||||
(t) => [
|
||||
index("comments_collection_item_idx").on(t.collection, t.item_id),
|
||||
index("comments_user_idx").on(t.user_id),
|
||||
],
|
||||
);
|
||||
|
||||
export type Comment = typeof comments.$inferSelect;
|
||||
export type NewComment = typeof comments.$inferInsert;
|
||||
27
packages/backend/src/db/schema/files.ts
Normal file
27
packages/backend/src/db/schema/files.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
bigint,
|
||||
integer,
|
||||
index,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
export const files = pgTable(
|
||||
"files",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
title: text("title"),
|
||||
description: text("description"),
|
||||
filename: text("filename").notNull(),
|
||||
mime_type: text("mime_type"),
|
||||
filesize: bigint("filesize", { mode: "number" }),
|
||||
duration: integer("duration"),
|
||||
uploaded_by: text("uploaded_by"),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
},
|
||||
(t) => [index("files_uploaded_by_idx").on(t.uploaded_by)],
|
||||
);
|
||||
|
||||
export type File = typeof files.$inferSelect;
|
||||
export type NewFile = typeof files.$inferInsert;
|
||||
94
packages/backend/src/db/schema/gamification.ts
Normal file
94
packages/backend/src/db/schema/gamification.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
integer,
|
||||
real,
|
||||
index,
|
||||
pgEnum,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { users } from "./users.js";
|
||||
import { recordings } from "./recordings.js";
|
||||
|
||||
export const achievementStatusEnum = pgEnum("achievement_status", [
|
||||
"draft",
|
||||
"published",
|
||||
]);
|
||||
|
||||
export const achievements = pgTable(
|
||||
"achievements",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
code: text("code").notNull(),
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
icon: text("icon"),
|
||||
category: text("category"),
|
||||
required_count: integer("required_count").notNull().default(1),
|
||||
points_reward: integer("points_reward").notNull().default(0),
|
||||
status: achievementStatusEnum("status").notNull().default("published"),
|
||||
sort: integer("sort").default(0),
|
||||
},
|
||||
(t) => [uniqueIndex("achievements_code_idx").on(t.code)],
|
||||
);
|
||||
|
||||
export const user_achievements = pgTable(
|
||||
"user_achievements",
|
||||
{
|
||||
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
|
||||
user_id: text("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
achievement_id: text("achievement_id")
|
||||
.notNull()
|
||||
.references(() => achievements.id, { onDelete: "cascade" }),
|
||||
progress: integer("progress").default(0),
|
||||
date_unlocked: timestamp("date_unlocked"),
|
||||
},
|
||||
(t) => [
|
||||
index("user_achievements_user_idx").on(t.user_id),
|
||||
uniqueIndex("user_achievements_unique_idx").on(t.user_id, t.achievement_id),
|
||||
],
|
||||
);
|
||||
|
||||
export const user_points = pgTable(
|
||||
"user_points",
|
||||
{
|
||||
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
|
||||
user_id: text("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
action: text("action").notNull(),
|
||||
points: integer("points").notNull(),
|
||||
recording_id: text("recording_id").references(() => recordings.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
},
|
||||
(t) => [
|
||||
index("user_points_user_idx").on(t.user_id),
|
||||
index("user_points_date_idx").on(t.date_created),
|
||||
],
|
||||
);
|
||||
|
||||
export const user_stats = pgTable(
|
||||
"user_stats",
|
||||
{
|
||||
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
|
||||
user_id: text("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
total_raw_points: integer("total_raw_points").default(0),
|
||||
total_weighted_points: real("total_weighted_points").default(0),
|
||||
recordings_count: integer("recordings_count").default(0),
|
||||
playbacks_count: integer("playbacks_count").default(0),
|
||||
comments_count: integer("comments_count").default(0),
|
||||
achievements_count: integer("achievements_count").default(0),
|
||||
last_updated: timestamp("last_updated").defaultNow(),
|
||||
},
|
||||
(t) => [uniqueIndex("user_stats_user_idx").on(t.user_id)],
|
||||
);
|
||||
|
||||
export type Achievement = typeof achievements.$inferSelect;
|
||||
export type UserStats = typeof user_stats.$inferSelect;
|
||||
7
packages/backend/src/db/schema/index.ts
Normal file
7
packages/backend/src/db/schema/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export * from "./files.js";
|
||||
export * from "./users.js";
|
||||
export * from "./videos.js";
|
||||
export * from "./articles.js";
|
||||
export * from "./recordings.js";
|
||||
export * from "./comments.js";
|
||||
export * from "./gamification.js";
|
||||
73
packages/backend/src/db/schema/recordings.ts
Normal file
73
packages/backend/src/db/schema/recordings.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
pgEnum,
|
||||
index,
|
||||
uniqueIndex,
|
||||
jsonb,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { users } from "./users.js";
|
||||
import { videos } from "./videos.js";
|
||||
|
||||
export const recordingStatusEnum = pgEnum("recording_status", [
|
||||
"draft",
|
||||
"published",
|
||||
"archived",
|
||||
]);
|
||||
|
||||
export const recordings = pgTable(
|
||||
"recordings",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
title: text("title").notNull(),
|
||||
description: text("description"),
|
||||
slug: text("slug").notNull(),
|
||||
duration: integer("duration").notNull(),
|
||||
events: jsonb("events").$type<object[]>().default([]),
|
||||
device_info: jsonb("device_info").$type<object[]>().default([]),
|
||||
user_id: text("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
status: recordingStatusEnum("status").notNull().default("draft"),
|
||||
tags: text("tags").array().default([]),
|
||||
linked_video: text("linked_video").references(() => videos.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
featured: boolean("featured").default(false),
|
||||
public: boolean("public").default(false),
|
||||
original_recording_id: text("original_recording_id"),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
date_updated: timestamp("date_updated"),
|
||||
},
|
||||
(t) => [
|
||||
uniqueIndex("recordings_slug_idx").on(t.slug),
|
||||
index("recordings_user_idx").on(t.user_id),
|
||||
index("recordings_status_idx").on(t.status),
|
||||
index("recordings_public_idx").on(t.public),
|
||||
],
|
||||
);
|
||||
|
||||
export const recording_plays = pgTable(
|
||||
"recording_plays",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
recording_id: text("recording_id")
|
||||
.notNull()
|
||||
.references(() => recordings.id, { onDelete: "cascade" }),
|
||||
user_id: text("user_id").references(() => users.id, { onDelete: "set null" }),
|
||||
duration_played: integer("duration_played").default(0),
|
||||
completed: boolean("completed").default(false),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
date_updated: timestamp("date_updated"),
|
||||
},
|
||||
(t) => [
|
||||
index("recording_plays_recording_idx").on(t.recording_id),
|
||||
index("recording_plays_user_idx").on(t.user_id),
|
||||
],
|
||||
);
|
||||
|
||||
export type Recording = typeof recordings.$inferSelect;
|
||||
export type NewRecording = typeof recordings.$inferInsert;
|
||||
60
packages/backend/src/db/schema/users.ts
Normal file
60
packages/backend/src/db/schema/users.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
pgEnum,
|
||||
boolean,
|
||||
index,
|
||||
uniqueIndex,
|
||||
integer,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { files } from "./files.js";
|
||||
|
||||
export const roleEnum = pgEnum("user_role", ["model", "viewer", "admin"]);
|
||||
|
||||
export const users = pgTable(
|
||||
"users",
|
||||
{
|
||||
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
email: text("email").notNull(),
|
||||
password_hash: text("password_hash").notNull(),
|
||||
first_name: text("first_name"),
|
||||
last_name: text("last_name"),
|
||||
artist_name: text("artist_name"),
|
||||
slug: text("slug"),
|
||||
description: text("description"),
|
||||
tags: text("tags").array().default([]),
|
||||
role: roleEnum("role").notNull().default("viewer"),
|
||||
avatar: text("avatar").references(() => files.id, { onDelete: "set null" }),
|
||||
banner: text("banner").references(() => files.id, { onDelete: "set null" }),
|
||||
email_verified: boolean("email_verified").notNull().default(false),
|
||||
email_verify_token: text("email_verify_token"),
|
||||
password_reset_token: text("password_reset_token"),
|
||||
password_reset_expiry: timestamp("password_reset_expiry"),
|
||||
date_created: timestamp("date_created").notNull().defaultNow(),
|
||||
date_updated: timestamp("date_updated"),
|
||||
},
|
||||
(t) => [
|
||||
uniqueIndex("users_email_idx").on(t.email),
|
||||
uniqueIndex("users_slug_idx").on(t.slug),
|
||||
index("users_role_idx").on(t.role),
|
||||
],
|
||||
);
|
||||
|
||||
export const user_photos = pgTable(
|
||||
"user_photos",
|
||||
{
|
||||
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
|
||||
user_id: text("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
file_id: text("file_id")
|
||||
.notNull()
|
||||
.references(() => files.id, { onDelete: "cascade" }),
|
||||
sort: integer("sort").default(0),
|
||||
},
|
||||
(t) => [index("user_photos_user_idx").on(t.user_id)],
|
||||
);
|
||||
|
||||
export type User = typeof users.$inferSelect;
|
||||
export type NewUser = typeof users.$inferInsert;
|
||||
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