mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修改表唯一约束
This commit is contained in:
parent
a3a62f65dd
commit
891619ad55
|
@ -30,10 +30,10 @@ export const initEnvPosition = 9999999999;
|
||||||
|
|
||||||
interface EnvInstance extends Model<Env, Env>, Env {}
|
interface EnvInstance extends Model<Env, Env>, Env {}
|
||||||
export const EnvModel = sequelize.define<EnvInstance>('Env', {
|
export const EnvModel = sequelize.define<EnvInstance>('Env', {
|
||||||
value: DataTypes.STRING,
|
value: { type: DataTypes.STRING, unique: 'compositeIndex' },
|
||||||
timestamp: DataTypes.STRING,
|
timestamp: DataTypes.STRING,
|
||||||
status: DataTypes.NUMBER,
|
status: DataTypes.NUMBER,
|
||||||
position: DataTypes.NUMBER,
|
position: DataTypes.NUMBER,
|
||||||
name: DataTypes.STRING,
|
name: { type: DataTypes.STRING, unique: 'compositeIndex' },
|
||||||
remarks: DataTypes.STRING,
|
remarks: DataTypes.STRING,
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,10 +4,11 @@ import config from '../config/index';
|
||||||
export const sequelize = new Sequelize({
|
export const sequelize = new Sequelize({
|
||||||
dialect: 'sqlite',
|
dialect: 'sqlite',
|
||||||
storage: `${config.dbPath}database.sqlite`,
|
storage: `${config.dbPath}database.sqlite`,
|
||||||
logging: false,
|
|
||||||
pool: {
|
pool: {
|
||||||
max: 6,
|
max: 6,
|
||||||
min: 0,
|
min: 0,
|
||||||
idle: 30000,
|
idle: 30000,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export type ResponseType<T> = { code: number; data?: T; message?: string };
|
||||||
|
|
|
@ -35,7 +35,7 @@ export enum CrontabStatus {
|
||||||
|
|
||||||
interface AppInstance extends Model<App, App>, App {}
|
interface AppInstance extends Model<App, App>, App {}
|
||||||
export const AppModel = sequelize.define<AppInstance>('App', {
|
export const AppModel = sequelize.define<AppInstance>('App', {
|
||||||
name: DataTypes.STRING,
|
name: { type: DataTypes.STRING, unique: 'name' },
|
||||||
scopes: DataTypes.JSON,
|
scopes: DataTypes.JSON,
|
||||||
client_id: DataTypes.STRING,
|
client_id: DataTypes.STRING,
|
||||||
client_secret: DataTypes.STRING,
|
client_secret: DataTypes.STRING,
|
||||||
|
|
|
@ -11,9 +11,18 @@ import { sequelize } from '../data';
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
try {
|
try {
|
||||||
await sequelize.sync({ alter: true });
|
await sequelize.sync();
|
||||||
await new Promise((resolve) => setTimeout(() => resolve(null), 5000));
|
await new Promise((resolve) => setTimeout(() => resolve(null), 5000));
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// const queryInterface = sequelize.getQueryInterface();
|
||||||
|
// await queryInterface.addIndex('Crontabs', ['command'], { unique: true });
|
||||||
|
// await queryInterface.addIndex('Envs', ['name', 'value'], { unique: true });
|
||||||
|
// await queryInterface.addIndex('Apps', ['name'], { unique: true });
|
||||||
|
// } catch (error) {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
const crondbExist = await fileExist(config.cronDbFile);
|
const crondbExist = await fileExist(config.cronDbFile);
|
||||||
const dependenceDbExist = await fileExist(config.dependenceDbFile);
|
const dependenceDbExist = await fileExist(config.dependenceDbFile);
|
||||||
const envDbExist = await fileExist(config.envDbFile);
|
const envDbExist = await fileExist(config.envDbFile);
|
||||||
|
|
|
@ -31,12 +31,6 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async insert(payload: Crontab): Promise<Crontab> {
|
public async insert(payload: Crontab): Promise<Crontab> {
|
||||||
const cron = await CrontabModel.findOne({
|
|
||||||
where: { command: payload.command },
|
|
||||||
});
|
|
||||||
if (cron) {
|
|
||||||
return cron;
|
|
||||||
}
|
|
||||||
return await CrontabModel.create(payload, { returning: true });
|
return await CrontabModel.create(payload, { returning: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,12 @@ export default class EnvService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async insert(payloads: Env[]): Promise<Env[]> {
|
public async insert(payloads: Env[]): Promise<Env[]> {
|
||||||
const docs = await EnvModel.bulkCreate(payloads);
|
const result = [];
|
||||||
return docs;
|
for (const env of payloads) {
|
||||||
|
const doc = await EnvModel.create(env, { returning: true });
|
||||||
|
result.push(doc);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async update(payload: Env): Promise<Env> {
|
public async update(payload: Env): Promise<Env> {
|
||||||
|
|
|
@ -24,8 +24,8 @@ export default class OpenService {
|
||||||
return { ...doc, tokens: [] };
|
return { ...doc, tokens: [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async insert(payloads: App): Promise<App> {
|
public async insert(payload: App): Promise<App> {
|
||||||
const doc = await AppModel.create(payloads, { returning: true });
|
const doc = await AppModel.create(payload, { returning: true });
|
||||||
return doc.get({ plain: true }) as App;
|
return doc.get({ plain: true }) as App;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user