100 lines
1.9 KiB
TypeScript

import { sequelize } from '../../../modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
export interface AppData {
files: { name: string; path: string }[];
}
export type AppType = 'web-single' | 'web-module';
export enum AppStatus {
running = 'running',
stop = 'stop',
}
export type App = Partial<InstanceType<typeof AppModel>>;
/**
* APP 管理
*/
export class AppModel extends Model {
declare id: string;
declare data: AppData;
declare title: string;
declare description: string;
declare version: string;
declare domain: string;
declare appType: string;
declare key: string;
declare type: string;
declare uid: string;
declare user: string;
declare status: string;
}
AppModel.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
comment: 'id',
},
title: {
type: DataTypes.STRING,
defaultValue: '',
},
description: {
type: DataTypes.STRING,
defaultValue: '',
},
data: {
type: DataTypes.JSON,
defaultValue: {},
},
version: {
type: DataTypes.STRING,
defaultValue: '',
},
domain: {
type: DataTypes.STRING,
defaultValue: '',
},
appType: {
type: DataTypes.STRING,
defaultValue: '',
},
key: {
type: DataTypes.STRING,
// 和 uid 组合唯一
},
type: {
type: DataTypes.STRING,
defaultValue: '',
},
uid: {
type: DataTypes.UUID,
allowNull: true,
},
user: {
type: DataTypes.STRING,
allowNull: true,
},
status: {
type: DataTypes.STRING,
defaultValue: 'running', // stop, running
},
},
{
sequelize,
tableName: 'kv_app',
paranoid: true,
indexes: [
{
unique: true,
fields: ['key', 'uid'],
},
],
},
);
AppModel.sync({ alter: true, logging: false }).catch((e) => {
console.error('AppModel sync', e);
});