Refactor app management to use Drizzle ORM

- Replaced Sequelize models with Drizzle ORM for app and app list management.
- Updated routes in app-manager to utilize new database queries.
- Removed obsolete Sequelize model files for app, app list, and app domain.
- Introduced new helper functions for app and app domain management.
- Enhanced user app management with improved file handling and user migration.
- Adjusted public API routes to align with new database structure.
- Implemented caching mechanisms for domain management.
This commit is contained in:
2026-02-07 01:26:16 +08:00
parent d62a75842f
commit 7dfa96d165
40 changed files with 1066 additions and 1171 deletions

View File

@@ -1,6 +1,6 @@
import { app } from '@/app.ts';
import { AppModel } from '../module/index.ts';
import { app, db, schema } from '@/app.ts';
import { ConfigPermission } from '@kevisual/permission';
import { eq, desc, asc } from 'drizzle-orm';
// curl http://localhost:4005/api/router?path=app&key=public-list
// TODO:
@@ -11,23 +11,20 @@ app
})
.define(async (ctx) => {
const { username = 'root', status = 'running', page = 1, pageSize = 100, order = 'DESC' } = ctx.query.data || {};
const { rows, count } = await AppModel.findAndCountAll({
where: {
status,
user: username,
},
attributes: {
exclude: [],
},
order: [['updatedAt', order]],
limit: pageSize,
offset: (page - 1) * pageSize,
distinct: true,
logging: false,
});
const offset = (page - 1) * pageSize;
const apps = await db.select().from(schema.kvApp)
.where(eq(schema.kvApp.user, username))
.orderBy(order === 'DESC' ? desc(schema.kvApp.updatedAt) : asc(schema.kvApp.updatedAt))
.limit(pageSize)
.offset(offset);
// Note: Drizzle doesn't have a direct equivalent to findAndCountAll
// We need to do a separate count query
const countResult = await db.select({ count: schema.kvApp.id }).from(schema.kvApp)
.where(eq(schema.kvApp.user, username));
const count = countResult.length;
ctx.body = {
list: rows.map((item) => {
return ConfigPermission.getDataPublicPermission(item.toJSON());
list: apps.map((item) => {
return ConfigPermission.getDataPublicPermission(item);
}),
pagination: {
total: count,