Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from lobehub:main #111

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

# Changelog

### [Version 1.35.8](https://github.com/lobehub/lobe-chat/compare/v1.35.7...v1.35.8)

<sup>Released on **2024-12-03**</sup>

#### ♻ Code Refactoring

- **misc**: Move schema and migration folder.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

- **misc**: Move schema and migration folder, closes [#4874](https://github.com/lobehub/lobe-chat/issues/4874) ([9aa16d4](https://github.com/lobehub/lobe-chat/commit/9aa16d4))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>

### [Version 1.35.7](https://github.com/lobehub/lobe-chat/compare/v1.35.6...v1.35.7)

<sup>Released on **2024-12-03**</sup>
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.database
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ COPY --from=builder /deps/node_modules/pg /app/node_modules/pg
COPY --from=builder /deps/node_modules/drizzle-orm /app/node_modules/drizzle-orm

# Copy database migrations
COPY --from=builder /app/src/database/server/migrations /app/migrations
COPY --from=builder /app/src/database/migrations /app/migrations
COPY --from=builder /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs
COPY --from=builder /app/scripts/migrateServerDB/errorHint.js /app/errorHint.js

Expand Down
7 changes: 7 additions & 0 deletions changelog/v1.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
[
{
"children": {
"improvements": ["Move schema and migration folder."]
},
"date": "2024-12-03",
"version": "1.35.8"
},
{
"children": {},
"date": "2024-12-03",
Expand Down
4 changes: 2 additions & 2 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default {
url: connectionString,
},
dialect: 'postgresql',
out: './src/database/server/migrations',
out: './src/database/migrations',

schema: './src/database/server/schemas/lobechat',
schema: './src/database/schemas',
strict: true,
} satisfies Config;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lobehub/chat",
"version": "1.35.7",
"version": "1.35.8",
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
"keywords": [
"framework",
Expand Down
2 changes: 1 addition & 1 deletion scripts/migrateServerDB/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dotenv.config();

const runMigrations = async () => {
await migrator.migrate(serverDB, {
migrationsFolder: join(__dirname, '../../src/database/server/migrations'),
migrationsFolder: join(__dirname, '../../src/database/migrations'),
});
console.log('✅ database migration pass.');
// eslint-disable-next-line unicorn/no-process-exit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createInsertSchema } from 'drizzle-zod';

import { LobeAgentChatConfig, LobeAgentTTSConfig } from '@/types/agent';

import { idGenerator, randomSlug } from '../../utils/idGenerator';
import { idGenerator, randomSlug } from '@/database/utils/idGenerator';
import { timestamps } from './_helpers';
import { files, knowledgeBases } from './file';
import { users } from './user';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from 'drizzle-orm/pg-core';
import { createInsertSchema } from 'drizzle-zod';

import { idGenerator } from '../../utils/idGenerator';
import { idGenerator } from '@/database/utils/idGenerator';
import { accessedAt, createdAt, timestamps } from './_helpers';
import { asyncTasks } from './asyncTask';
import { chunks } from './rag';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'drizzle-orm/pg-core';
import { createSelectSchema } from 'drizzle-zod';

import { idGenerator } from '../../utils/idGenerator';
import { idGenerator } from '@/database/utils/idGenerator';
import { timestamps } from './_helpers';
import { agents } from './agent';
import { files } from './file';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { boolean, integer, pgTable, text, unique, uniqueIndex, varchar } from 'drizzle-orm/pg-core';
import { createInsertSchema } from 'drizzle-zod';

import { idGenerator, randomSlug } from '../../utils/idGenerator';
import { idGenerator, randomSlug } from '@/database/utils/idGenerator';
import { timestamps } from './_helpers';
import { users } from './user';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { boolean, jsonb, pgTable, text, unique } from 'drizzle-orm/pg-core';
import { createInsertSchema } from 'drizzle-zod';

import { idGenerator } from '../../utils/idGenerator';
import { idGenerator } from '@/database/utils/idGenerator';
import { timestamps, timestamptz } from './_helpers';
import { sessions } from './session';
import { users } from './user';
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ws from 'ws';
import { serverDBEnv } from '@/config/db';
import { isServerMode } from '@/const/version';

import * as schema from '../schemas/lobechat';
import * as schema from '../../schemas';

export const getDBInstance = (): NeonDatabase<typeof schema> => {
if (!isServerMode) return {} as any;
Expand Down
4 changes: 2 additions & 2 deletions src/database/server/core/dbForTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ws from 'ws';

import { serverDBEnv } from '@/config/db';

import * as schema from '../schemas/lobechat';
import * as schema from '../../schemas';

export const getTestDBInstance = async () => {
let connectionString = serverDBEnv.DATABASE_TEST_URL;
Expand All @@ -24,7 +24,7 @@ export const getTestDBInstance = async () => {
const db = nodeDrizzle(client, { schema });

await nodeMigrator.migrate(db, {
migrationsFolder: join(__dirname, '../migrations'),
migrationsFolder: join(__dirname, '../../migrations'),
});

return db;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/_test_template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getTestDBInstance } from '@/database/server/core/dbForTest';

import { sessionGroups, users } from '../../schemas/lobechat';
import { sessionGroups, users } from '../../../schemas';
import { SessionGroupModel } from '../sessionGroup';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
knowledgeBases,
sessions,
users,
} from '../../schemas/lobechat';
} from '../../../schemas';
import { AgentModel } from '../agent';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/asyncTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { getTestDBInstance } from '@/database/server/core/dbForTest';
import { AsyncTaskStatus, AsyncTaskType } from '@/types/asyncTask';

import { asyncTasks, users } from '../../schemas/lobechat';
import { asyncTasks, users } from '../../../schemas';
import { ASYNC_TASK_TIMEOUT, AsyncTaskModel } from '../asyncTask';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/chunk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
files,
unstructuredChunks,
users,
} from '../../schemas/lobechat';
} from '../../../schemas';
import { ChunkModel } from '../chunk';
import { codeEmbedding, designThinkingQuery, designThinkingQuery2 } from './fixtures/embedding';

Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
knowledgeBaseFiles,
knowledgeBases,
users,
} from '../../schemas/lobechat';
} from '../../../schemas';
import { FileModel } from '../file';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/knowledgeBase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
knowledgeBaseFiles,
knowledgeBases,
users,
} from '../../schemas/lobechat';
} from '../../../schemas';
import { KnowledgeBaseModel } from '../knowledgeBase';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
sessions,
topics,
users,
} from '../../schemas/lobechat';
} from '../../../schemas';
import { MessageModel } from '../message';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/nextauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
nextauthSessions,
nextauthVerificationTokens,
users,
} from '@/database/server/schemas/lobechat';
} from '@/database/schemas';
import { LobeNextAuthDbAdapter } from '@/libs/next-auth/adapter';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getTestDBInstance } from '@/database/server/core/dbForTest';

import { NewInstalledPlugin, installedPlugins, users } from '../../schemas/lobechat';
import { NewInstalledPlugin, installedPlugins, users } from '../../../schemas';
import { PluginModel } from '../plugin';

let serverDB = await getTestDBInstance();
Expand Down
4 changes: 2 additions & 2 deletions src/database/server/models/__tests__/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
sessions,
topics,
users,
} from '../../schemas/lobechat';
import { idGenerator } from '../../utils/idGenerator';
} from '../../../schemas';
import { idGenerator } from '@/database/utils/idGenerator';
import { SessionModel } from '../session';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/sessionGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getTestDBInstance } from '@/database/server/core/dbForTest';

import { sessionGroups, users } from '../../schemas/lobechat';
import { sessionGroups, users } from '../../../schemas';
import { SessionGroupModel } from '../sessionGroup';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/topic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getTestDBInstance } from '@/database/server/core/dbForTest';

import { messages, sessions, topics, users } from '../../schemas/lobechat';
import { messages, sessions, topics, users } from '../../../schemas';
import { CreateTopicParams, TopicModel } from '../topic';

let serverDB = await getTestDBInstance();
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { KeyVaultsGateKeeper } from '@/server/modules/KeyVaultsEncrypt';
import { UserGuide, UserPreference } from '@/types/user';
import { UserSettings } from '@/types/user/settings';

import { userSettings, users } from '../../schemas/lobechat';
import { userSettings, users } from '../../../schemas';
import { SessionModel } from '../session';
import { UserModel } from '../user';

Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/_template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { and, desc } from 'drizzle-orm/expressions';

import { serverDB } from '@/database/server';

import { NewSessionGroup, SessionGroupItem, sessionGroups } from '../schemas/lobechat';
import { NewSessionGroup, SessionGroupItem, sessionGroups } from '../../schemas';

export class TemplateModel {
private userId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
agentsToSessions,
files,
knowledgeBases,
} from '@/database/server/schemas/lobechat';
} from '@/database/schemas';

export class AgentModel {
private userId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/asyncTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
AsyncTaskType,
} from '@/types/asyncTask';

import { AsyncTaskSelectItem, NewAsyncTaskItem, asyncTasks } from '../schemas/lobechat';
import { AsyncTaskSelectItem, NewAsyncTaskItem, asyncTasks } from '../../schemas';

// set timeout to about 5 minutes, and give 2s padding time
export const ASYNC_TASK_TIMEOUT = 298 * 1000;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
fileChunks,
files,
unstructuredChunks,
} from '../schemas/lobechat';
} from '../../schemas';

export class ChunkModel {
private userId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/embedding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { and } from 'drizzle-orm/expressions';

import { serverDB } from '@/database/server';

import { NewEmbeddingsItem, embeddings } from '../schemas/lobechat';
import { NewEmbeddingsItem, embeddings } from '../../schemas';

export class EmbeddingModel {
private userId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
files,
globalFiles,
knowledgeBaseFiles,
} from '../schemas/lobechat';
} from '../../schemas';

export class FileModel {
private readonly userId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/knowledgeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { and, desc } from 'drizzle-orm/expressions';
import { serverDB } from '@/database/server';
import { KnowledgeBaseItem } from '@/types/knowledgeBase';

import { NewKnowledgeBase, knowledgeBaseFiles, knowledgeBases } from '../schemas/lobechat';
import { NewKnowledgeBase, knowledgeBaseFiles, knowledgeBases } from '../../schemas';

export class KnowledgeBaseModel {
private userId: string;
Expand Down
4 changes: 2 additions & 2 deletions src/database/server/models/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { count } from 'drizzle-orm';
import { and, asc, desc, eq, gte, inArray, isNull, like, lt } from 'drizzle-orm/expressions';

import { serverDB } from '@/database/server/core/db';
import { idGenerator } from '@/database/server/utils/idGenerator';
import { idGenerator } from '@/database/utils/idGenerator';
import { getFullFileUrl } from '@/server/utils/files';
import {
ChatFileItem,
Expand All @@ -28,7 +28,7 @@ import {
messageTranslates,
messages,
messagesFiles,
} from '../schemas/lobechat';
} from '../../schemas';

export interface QueryMessageParams {
current?: number;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { and, desc, eq } from 'drizzle-orm/expressions';

import { serverDB } from '@/database/server';

import { InstalledPluginItem, NewInstalledPlugin, installedPlugins } from '../schemas/lobechat';
import { InstalledPluginItem, NewInstalledPlugin, installedPlugins } from '../../schemas';

export class PluginModel {
private userId: string;
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/ragEval/dataset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { and, desc, eq } from 'drizzle-orm';

import { serverDB } from '@/database/server';
import { NewEvalDatasetsItem, evalDatasets } from '@/database/server/schemas/lobechat';
import { NewEvalDatasetsItem, evalDatasets } from '@/database/schemas';
import { RAGEvalDataSetItem } from '@/types/eval';

export class EvalDatasetModel {
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/ragEval/datasetRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
NewEvalDatasetRecordsItem,
evalDatasetRecords,
files,
} from '@/database/server/schemas/lobechat';
} from '@/database/schemas';
import { EvalDatasetRecordRefFile } from '@/types/eval';

export class EvalDatasetRecordModel {
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/ragEval/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
evalDatasets,
evalEvaluation,
evaluationRecords,
} from '@/database/server/schemas/lobechat';
} from '@/database/schemas';
import { EvalEvaluationStatus, RAGEvalEvaluationItem } from '@/types/eval';

export class EvalEvaluationModel {
Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/ragEval/evaluationRecord.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { and, eq } from 'drizzle-orm';

import { serverDB } from '@/database/server';
import { NewEvaluationRecordsItem, evaluationRecords } from '@/database/server/schemas/lobechat';
import { NewEvaluationRecordsItem, evaluationRecords } from '@/database/schemas';

export class EvaluationRecordModel {
private userId: string;
Expand Down
Loading
Loading