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,8 +1,9 @@
import { app } from '@/app.ts';
import { app, db, schema } from '@/app.ts';
import { User } from '@/models/user.ts';
import { CustomError } from '@kevisual/router';
import { checkUsername } from './admin/user.ts';
import { nanoid } from 'nanoid';
import { sql } from 'drizzle-orm';
app
.route({
@@ -11,11 +12,15 @@ app
middleware: ['auth'],
})
.define(async (ctx) => {
const users = await User.findAll({
attributes: ['id', 'username', 'description', 'needChangePassword'],
order: [['updatedAt', 'DESC']],
logging: false,
});
const users = await db
.select({
id: schema.cfUser.id,
username: schema.cfUser.username,
description: schema.cfUser.description,
needChangePassword: schema.cfUser.needChangePassword,
})
.from(schema.cfUser)
.orderBy(sql`${schema.cfUser.updatedAt} DESC`);
ctx.body = users;
})
.addTo(app);
@@ -71,7 +76,7 @@ app
throw new CustomError(400, 'username is required');
}
checkUsername(username);
const findUserByUsername = await User.findOne({ where: { username } });
const findUserByUsername = await User.findOne({ username });
if (findUserByUsername) {
throw new CustomError(400, 'username already exists');
}