feat: добавить новый backend и cabinet

- добавлен новый Nest backend для auth, projects и project access tokens
- добавлена control-plane схема БД и миграция Drizzle
- перенесён старый backend в old-backend
- добавлен React/Vite cabinet с auth-only входом и Mantine layout
- обновлены workspace scripts и lockfile
This commit is contained in:
2026-05-12 09:22:04 +03:00
parent d49449c30c
commit 98295d0569
113 changed files with 3426 additions and 169 deletions

View File

@@ -0,0 +1,29 @@
CREATE TYPE "public"."project_access_token_status" AS ENUM('active', 'revoked');--> statement-breakpoint
CREATE TABLE "project_access_tokens" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"project_id" uuid NOT NULL,
"name" text NOT NULL,
"token_prefix" text NOT NULL,
"token_hash" text NOT NULL,
"scopes" jsonb NOT NULL,
"status" "project_access_token_status" DEFAULT 'active' NOT NULL,
"last_used_at" timestamp with time zone,
"revoked_at" timestamp with time zone,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "projects" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"slug" text NOT NULL,
"name" text NOT NULL,
"status" "project_status" DEFAULT 'active' NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "project_access_tokens" ADD CONSTRAINT "project_access_tokens_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "project_access_tokens_project_id_idx" ON "project_access_tokens" USING btree ("project_id");--> statement-breakpoint
CREATE UNIQUE INDEX "project_access_tokens_prefix_idx" ON "project_access_tokens" USING btree ("token_prefix");--> statement-breakpoint
CREATE UNIQUE INDEX "project_access_tokens_hash_idx" ON "project_access_tokens" USING btree ("token_hash");--> statement-breakpoint
CREATE UNIQUE INDEX "projects_slug_idx" ON "projects" USING btree ("slug");

View File

@@ -0,0 +1,967 @@
{
"id": "611b84db-81ef-47a6-bc62-fa7e797d88da",
"prevId": "f407b041-197f-4277-8c7d-2b5ce920adc5",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.allowed_image_hosts": {
"name": "allowed_image_hosts",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"hostname": {
"name": "hostname",
"type": "text",
"primaryKey": false,
"notNull": true
},
"enabled": {
"name": "enabled",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"allowed_image_hosts_hostname_idx": {
"name": "allowed_image_hosts_hostname_idx",
"columns": [
{
"expression": "hostname",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.image_asset_versions": {
"name": "image_asset_versions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"asset_id": {
"name": "asset_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"version": {
"name": "version",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"source_url": {
"name": "source_url",
"type": "text",
"primaryKey": false,
"notNull": true
},
"source_host": {
"name": "source_host",
"type": "text",
"primaryKey": false,
"notNull": true
},
"source_hash": {
"name": "source_hash",
"type": "text",
"primaryKey": false,
"notNull": true
},
"original_s3_key": {
"name": "original_s3_key",
"type": "text",
"primaryKey": false,
"notNull": false
},
"width": {
"name": "width",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"height": {
"name": "height",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"content_type": {
"name": "content_type",
"type": "text",
"primaryKey": false,
"notNull": false
},
"size_bytes": {
"name": "size_bytes",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"image_asset_versions_asset_version_idx": {
"name": "image_asset_versions_asset_version_idx",
"columns": [
{
"expression": "asset_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "version",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"image_asset_versions_source_hash_idx": {
"name": "image_asset_versions_source_hash_idx",
"columns": [
{
"expression": "source_hash",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"image_asset_versions_asset_id_image_assets_id_fk": {
"name": "image_asset_versions_asset_id_image_assets_id_fk",
"tableFrom": "image_asset_versions",
"tableTo": "image_assets",
"columnsFrom": [
"asset_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.image_assets": {
"name": "image_assets",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"project_id": {
"name": "project_id",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"public_id": {
"name": "public_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"current_version": {
"name": "current_version",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 1
},
"status": {
"name": "status",
"type": "asset_status",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'active'"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"image_assets_public_id_idx": {
"name": "image_assets_public_id_idx",
"columns": [
{
"expression": "public_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"image_assets_project_id_idx": {
"name": "image_assets_project_id_idx",
"columns": [
{
"expression": "project_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"image_assets_project_id_image_projects_id_fk": {
"name": "image_assets_project_id_image_projects_id_fk",
"tableFrom": "image_assets",
"tableTo": "image_projects",
"columnsFrom": [
"project_id"
],
"columnsTo": [
"id"
],
"onDelete": "restrict",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.image_projects": {
"name": "image_projects",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"status": {
"name": "status",
"type": "project_status",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'active'"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"image_projects_slug_idx": {
"name": "image_projects_slug_idx",
"columns": [
{
"expression": "slug",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.image_variants": {
"name": "image_variants",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"asset_id": {
"name": "asset_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"asset_version_id": {
"name": "asset_version_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"asset_version": {
"name": "asset_version",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"preset": {
"name": "preset",
"type": "text",
"primaryKey": false,
"notNull": true
},
"variant_hash": {
"name": "variant_hash",
"type": "text",
"primaryKey": false,
"notNull": true
},
"requested_format": {
"name": "requested_format",
"type": "requested_format",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'auto'"
},
"format": {
"name": "format",
"type": "variant_format",
"typeSchema": "public",
"primaryKey": false,
"notNull": true
},
"width": {
"name": "width",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"height": {
"name": "height",
"type": "integer",
"primaryKey": false,
"notNull": false
},
"resize_mode": {
"name": "resize_mode",
"type": "resize_mode",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'fit'"
},
"quality": {
"name": "quality",
"type": "integer",
"primaryKey": false,
"notNull": true
},
"s3_key": {
"name": "s3_key",
"type": "text",
"primaryKey": false,
"notNull": true
},
"content_type": {
"name": "content_type",
"type": "text",
"primaryKey": false,
"notNull": false
},
"etag": {
"name": "etag",
"type": "text",
"primaryKey": false,
"notNull": false
},
"status": {
"name": "status",
"type": "variant_status",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'pending'"
},
"size_bytes": {
"name": "size_bytes",
"type": "bigint",
"primaryKey": false,
"notNull": false
},
"error": {
"name": "error",
"type": "text",
"primaryKey": false,
"notNull": false
},
"attempt_count": {
"name": "attempt_count",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"last_accessed_at": {
"name": "last_accessed_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"image_variants_lookup_idx": {
"name": "image_variants_lookup_idx",
"columns": [
{
"expression": "asset_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "asset_version",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "preset",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "width",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "height",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "resize_mode",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "quality",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "format",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"image_variants_s3_key_idx": {
"name": "image_variants_s3_key_idx",
"columns": [
{
"expression": "s3_key",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"image_variants_variant_hash_idx": {
"name": "image_variants_variant_hash_idx",
"columns": [
{
"expression": "variant_hash",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"image_variants_status_idx": {
"name": "image_variants_status_idx",
"columns": [
{
"expression": "status",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"image_variants_asset_id_image_assets_id_fk": {
"name": "image_variants_asset_id_image_assets_id_fk",
"tableFrom": "image_variants",
"tableTo": "image_assets",
"columnsFrom": [
"asset_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"image_variants_asset_version_id_image_asset_versions_id_fk": {
"name": "image_variants_asset_version_id_image_asset_versions_id_fk",
"tableFrom": "image_variants",
"tableTo": "image_asset_versions",
"columnsFrom": [
"asset_version_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.project_access_tokens": {
"name": "project_access_tokens",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"project_id": {
"name": "project_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"token_prefix": {
"name": "token_prefix",
"type": "text",
"primaryKey": false,
"notNull": true
},
"token_hash": {
"name": "token_hash",
"type": "text",
"primaryKey": false,
"notNull": true
},
"scopes": {
"name": "scopes",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"status": {
"name": "status",
"type": "project_access_token_status",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'active'"
},
"last_used_at": {
"name": "last_used_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"revoked_at": {
"name": "revoked_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": false
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"project_access_tokens_project_id_idx": {
"name": "project_access_tokens_project_id_idx",
"columns": [
{
"expression": "project_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"project_access_tokens_prefix_idx": {
"name": "project_access_tokens_prefix_idx",
"columns": [
{
"expression": "token_prefix",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"project_access_tokens_hash_idx": {
"name": "project_access_tokens_hash_idx",
"columns": [
{
"expression": "token_hash",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"project_access_tokens_project_id_projects_id_fk": {
"name": "project_access_tokens_project_id_projects_id_fk",
"tableFrom": "project_access_tokens",
"tableTo": "projects",
"columnsFrom": [
"project_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.projects": {
"name": "projects",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"slug": {
"name": "slug",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"status": {
"name": "status",
"type": "project_status",
"typeSchema": "public",
"primaryKey": false,
"notNull": true,
"default": "'active'"
},
"created_at": {
"name": "created_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp with time zone",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"projects_slug_idx": {
"name": "projects_slug_idx",
"columns": [
{
"expression": "slug",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {
"public.asset_status": {
"name": "asset_status",
"schema": "public",
"values": [
"active",
"disabled",
"deleted"
]
},
"public.project_access_token_status": {
"name": "project_access_token_status",
"schema": "public",
"values": [
"active",
"revoked"
]
},
"public.project_status": {
"name": "project_status",
"schema": "public",
"values": [
"active",
"disabled"
]
},
"public.requested_format": {
"name": "requested_format",
"schema": "public",
"values": [
"auto",
"avif",
"webp",
"jpg",
"png"
]
},
"public.resize_mode": {
"name": "resize_mode",
"schema": "public",
"values": [
"fit",
"fill"
]
},
"public.variant_format": {
"name": "variant_format",
"schema": "public",
"values": [
"avif",
"webp",
"jpg",
"png"
]
},
"public.variant_status": {
"name": "variant_status",
"schema": "public",
"values": [
"pending",
"processing",
"ready",
"failed"
]
}
},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -22,6 +22,13 @@
"when": 1778007484095,
"tag": "0002_grey_ser_duncan",
"breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1778563561633,
"tag": "0004_complex_yellowjacket",
"breakpoints": true
}
]
}
}

View File

@@ -3,6 +3,7 @@ import {
boolean,
index,
integer,
jsonb,
pgEnum,
pgTable,
text,
@@ -12,12 +13,22 @@ import {
} from "drizzle-orm/pg-core"
export const assetStatusEnum = pgEnum("asset_status", ["active", "disabled", "deleted"])
export const projectAccessTokenStatusEnum = pgEnum("project_access_token_status", ["active", "revoked"])
export const projectStatusEnum = pgEnum("project_status", ["active", "disabled"])
export const variantFormatEnum = pgEnum("variant_format", ["avif", "webp", "jpg", "png"])
export const requestedFormatEnum = pgEnum("requested_format", ["auto", "avif", "webp", "jpg", "png"])
export const resizeModeEnum = pgEnum("resize_mode", ["fit", "fill"])
export const variantStatusEnum = pgEnum("variant_status", ["pending", "processing", "ready", "failed"])
export type ProjectAccessTokenScope =
| "assets:read"
| "assets:write"
| "assets:delete"
| "presets:read"
| "presets:write"
| "builds:read"
| "builds:write"
const timestamps = {
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
@@ -35,6 +46,41 @@ export const allowedImageHosts = pgTable(
(table) => [uniqueIndex("allowed_image_hosts_hostname_idx").on(table.hostname)],
)
export const projects = pgTable(
"projects",
{
id: uuid("id").primaryKey().defaultRandom(),
slug: text("slug").notNull(),
name: text("name").notNull(),
status: projectStatusEnum("status").notNull().default("active"),
...timestamps,
},
(table) => [uniqueIndex("projects_slug_idx").on(table.slug)],
)
export const projectAccessTokens = pgTable(
"project_access_tokens",
{
id: uuid("id").primaryKey().defaultRandom(),
projectId: uuid("project_id")
.notNull()
.references(() => projects.id, { onDelete: "cascade" }),
name: text("name").notNull(),
tokenPrefix: text("token_prefix").notNull(),
tokenHash: text("token_hash").notNull(),
scopes: jsonb("scopes").$type<ProjectAccessTokenScope[]>().notNull(),
status: projectAccessTokenStatusEnum("status").notNull().default("active"),
lastUsedAt: timestamp("last_used_at", { withTimezone: true }),
revokedAt: timestamp("revoked_at", { withTimezone: true }),
...timestamps,
},
(table) => [
index("project_access_tokens_project_id_idx").on(table.projectId),
uniqueIndex("project_access_tokens_prefix_idx").on(table.tokenPrefix),
uniqueIndex("project_access_tokens_hash_idx").on(table.tokenHash),
],
)
export const imageProjects = pgTable(
"image_projects",
{