First cut
This commit is contained in:
63
db/models.js
Normal file
63
db/models.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Sequelize, DataTypes } from 'sequelize';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export const sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: join(__dirname, '../data/jobs.sqlite'),
|
||||
logging: false,
|
||||
});
|
||||
|
||||
export const Job = sequelize.define('Job', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
prompt: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
},
|
||||
// Base64 data URL stored for replay; in production use object storage
|
||||
imageDataUrl: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: false,
|
||||
},
|
||||
imageMimeType: {
|
||||
type: DataTypes.STRING(64),
|
||||
allowNull: false,
|
||||
defaultValue: 'image/jpeg',
|
||||
},
|
||||
status: {
|
||||
// queued | running | done | error
|
||||
type: DataTypes.STRING(16),
|
||||
allowNull: false,
|
||||
defaultValue: 'queued',
|
||||
},
|
||||
result: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
errorMessage: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
model: {
|
||||
type: DataTypes.STRING(128),
|
||||
allowNull: false,
|
||||
defaultValue: 'anthropic/claude-sonnet-4.6',
|
||||
},
|
||||
inputTokens: { type: DataTypes.INTEGER, allowNull: true },
|
||||
outputTokens: { type: DataTypes.INTEGER, allowNull: true },
|
||||
}, {
|
||||
tableName: 'jobs',
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
export async function initDb() {
|
||||
const { mkdirSync } = await import('fs');
|
||||
mkdirSync(join(__dirname, '../data'), { recursive: true });
|
||||
await sequelize.sync();
|
||||
}
|
||||
Reference in New Issue
Block a user