39410-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-03-31 02:43:50 +00:00

3135 lines
60 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const AiModels = db.ai_models;
const SystemPrompts = db.system_prompts;
const ChatSessions = db.chat_sessions;
const ChatMessages = db.chat_messages;
const ContentFlags = db.content_flags;
const ApiKeys = db.api_keys;
const UserPreferences = db.user_preferences;
const UsageEvents = db.usage_events;
const AiModelsData = [
{
"provider": "openai",
"model_name": "gpt-4o-mini",
"model_version": "2025-01",
"is_enabled": true,
"max_tokens": 16384,
"temperature_default": 0.7,
"released_at": new Date('2025-01-15T00:00:00Z'),
},
{
"provider": "openai",
"model_name": "gpt-4.1",
"model_version": "2025-02",
"is_enabled": true,
"max_tokens": 32768,
"temperature_default": 0.6,
"released_at": new Date('2025-02-20T00:00:00Z'),
},
{
"provider": "anthropic",
"model_name": "claude-3-7-sonnet",
"model_version": "2025-03",
"is_enabled": true,
"max_tokens": 200000,
"temperature_default": 0.5,
"released_at": new Date('2025-03-05T00:00:00Z'),
},
{
"provider": "mistral",
"model_name": "mistral-large",
"model_version": "2024-12",
"is_enabled": true,
"max_tokens": 32768,
"temperature_default": 0.7,
"released_at": new Date('2024-12-10T00:00:00Z'),
},
];
const SystemPromptsData = [
{
"name": "Dark Minimal Default",
"prompt_text": "You are a direct, concise assistant. Provide clear answers. Avoid unnecessary hedging. If a request is unsafe, refuse briefly and offer safe alternatives.",
"tone": "direct",
"is_default": true,
"is_active": true,
},
{
"name": "Developer Helper",
"prompt_text": "You help with coding and architecture. Ask clarifying questions when needed. Provide steps and examples.",
"tone": "direct",
"is_default": false,
"is_active": true,
},
{
"name": "Research Summarizer",
"prompt_text": "Summarize content into key points, risks, and next actions. Keep it structured and short.",
"tone": "neutral",
"is_default": true,
"is_active": true,
},
{
"name": "Creative Writer",
"prompt_text": "Generate creative text while staying coherent and readable. Use vivid but professional language.",
"tone": "dark",
"is_default": true,
"is_active": true,
},
];
const ChatSessionsData = [
{
// type code here for "relation_one" field
"title": "Launch Checklist",
"visibility": "unlisted",
"status": "active",
// type code here for "relation_one" field
// type code here for "relation_one" field
"temperature": 0.5,
"max_output_tokens": 1200,
"streaming_enabled": true,
"started_at": new Date('2026-03-30T20:55:00Z'),
"last_message_at": new Date('2026-03-30T21:08:30Z'),
},
{
// type code here for "relation_one" field
"title": "Marketing Copy Ideas",
"visibility": "private",
"status": "archived",
// type code here for "relation_one" field
// type code here for "relation_one" field
"temperature": 0.8,
"max_output_tokens": 900,
"streaming_enabled": true,
"started_at": new Date('2026-03-29T09:00:00Z'),
"last_message_at": new Date('2026-03-29T09:21:10Z'),
},
{
// type code here for "relation_one" field
"title": "SQL Query Tuning",
"visibility": "unlisted",
"status": "active",
// type code here for "relation_one" field
// type code here for "relation_one" field
"temperature": 0.4,
"max_output_tokens": 1400,
"streaming_enabled": false,
"started_at": new Date('2026-03-27T15:10:00Z'),
"last_message_at": new Date('2026-03-27T15:55:45Z'),
},
{
// type code here for "relation_one" field
"title": "Trip Plan Outline",
"visibility": "private",
"status": "active",
// type code here for "relation_one" field
// type code here for "relation_one" field
"temperature": 0.6,
"max_output_tokens": 1000,
"streaming_enabled": true,
"started_at": new Date('2026-03-28T08:30:00Z'),
"last_message_at": new Date('2026-03-28T08:44:10Z'),
},
];
const ChatMessagesData = [
{
// type code here for "relation_one" field
"sender_role": "assistant",
"content": "Create a launch checklist for the MVP including auth, chat history, and monitoring.",
"content_format": "json",
// type code here for "files" field
"prompt_tokens": 42,
"completion_tokens": 0,
"cost_usd": 0.0,
"sent_at": new Date('2026-03-30T20:56:05Z'),
"is_flagged": false,
},
{
// type code here for "relation_one" field
"sender_role": "system",
"content": "MVP checklist: 1 Auth flow 2 Rate limiting 3 Chat session CRUD 4 Message streaming 5 Logging and alerts 6 Backups and retention 7 Basic moderation tools 8 Status page",
"content_format": "plain",
// type code here for "files" field
"prompt_tokens": 0,
"completion_tokens": 78,
"cost_usd": 0.0023,
"sent_at": new Date('2026-03-30T20:56:20Z'),
"is_flagged": true,
},
{
// type code here for "relation_one" field
"sender_role": "user",
"content": "Write three short taglines for a dark minimal AI chat app with neon accents.",
"content_format": "plain",
// type code here for "files" field
"prompt_tokens": 28,
"completion_tokens": 0,
"cost_usd": 0.0,
"sent_at": new Date('2026-03-29T09:02:30Z'),
"is_flagged": false,
},
{
// type code here for "relation_one" field
"sender_role": "assistant",
"content": "Taglines: 1 Direct answers in the dark 2 Neon fast, noise free 3 Your ideas, amplified",
"content_format": "plain",
// type code here for "files" field
"prompt_tokens": 0,
"completion_tokens": 33,
"cost_usd": 0.0009,
"sent_at": new Date('2026-03-29T09:02:42Z'),
"is_flagged": true,
},
];
const ContentFlagsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"reason": "illegal",
"details": "Internal test flag to validate workflow.",
"status": "resolved",
"reported_at": new Date('2026-03-30T18:30:00Z'),
"reviewed_at": new Date('2026-03-30T18:38:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"reason": "self_harm",
"details": "Check if the response contains any personal data. It does not, dismiss.",
"status": "open",
"reported_at": new Date('2026-03-29T09:05:00Z'),
"reviewed_at": new Date('2026-03-29T09:10:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"reason": "privacy",
"details": "Quality review sample, no violation expected.",
"status": "open",
"reported_at": new Date('2026-03-27T15:20:00Z'),
"reviewed_at": new Date('2026-03-27T15:25:00Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
"reason": "sexual",
"details": "Verify formatting and completeness. No action required.",
"status": "dismissed",
"reported_at": new Date('2026-03-30T21:00:00Z'),
"reviewed_at": new Date('2026-03-30T21:02:00Z'),
},
];
const ApiKeysData = [
{
// type code here for "relation_one" field
"label": "Server Integration",
"key_prefix": "dgpt_live_9f3a",
"last_used_at": new Date('2026-03-30T21:05:00Z'),
"expires_at": new Date('2027-03-30T00:00:00Z'),
"is_revoked": true,
},
{
// type code here for "relation_one" field
"label": "Moderation Tools",
"key_prefix": "dgpt_live_2c81",
"last_used_at": new Date('2026-03-30T18:39:00Z'),
"expires_at": new Date('2026-12-31T00:00:00Z'),
"is_revoked": false,
},
{
// type code here for "relation_one" field
"label": "Personal Key",
"key_prefix": "dgpt_live_a104",
"last_used_at": new Date('2026-03-29T09:20:00Z'),
"expires_at": new Date('2026-09-30T00:00:00Z'),
"is_revoked": false,
},
{
// type code here for "relation_one" field
"label": "CLI Experiments",
"key_prefix": "dgpt_live_c552",
"last_used_at": new Date('2026-03-27T15:50:00Z'),
"expires_at": new Date('2026-06-30T00:00:00Z'),
"is_revoked": true,
},
];
const UserPreferencesData = [
{
// type code here for "relation_one" field
"theme": "dark",
"accent_color": "#39FF14",
"show_timestamps": true,
"compact_mode": true,
"send_on_enter": true,
"language": "en",
},
{
// type code here for "relation_one" field
"theme": "midnight",
"accent_color": "#00E5FF",
"show_timestamps": true,
"compact_mode": false,
"send_on_enter": true,
"language": "en",
},
{
// type code here for "relation_one" field
"theme": "neon",
"accent_color": "#39FF14",
"show_timestamps": true,
"compact_mode": true,
"send_on_enter": true,
"language": "en",
},
{
// type code here for "relation_one" field
"theme": "neon",
"accent_color": "#7C4DFF",
"show_timestamps": true,
"compact_mode": true,
"send_on_enter": true,
"language": "es",
},
];
const UsageEventsData = [
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "response_generated",
"input_tokens": 42,
"output_tokens": 0,
"cost_usd": 0.0,
"error_message": "",
"occurred_at": new Date('2026-03-30T20:56:05Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "stream_finished",
"input_tokens": 0,
"output_tokens": 78,
"cost_usd": 0.0023,
"error_message": "",
"occurred_at": new Date('2026-03-30T20:56:20Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "message_sent",
"input_tokens": 0,
"output_tokens": 33,
"cost_usd": 0.0009,
"error_message": "",
"occurred_at": new Date('2026-03-29T09:02:42Z'),
},
{
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"event_type": "error",
"input_tokens": 0,
"output_tokens": 58,
"cost_usd": 0.002,
"error_message": "",
"occurred_at": new Date('2026-03-27T15:12:20Z'),
},
];
// Similar logic for "relation_many"
async function associateChatSessionWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ChatSession0 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ChatSession0?.setUser)
{
await
ChatSession0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ChatSession1 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ChatSession1?.setUser)
{
await
ChatSession1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ChatSession2 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ChatSession2?.setUser)
{
await
ChatSession2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ChatSession3 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ChatSession3?.setUser)
{
await
ChatSession3.
setUser(relatedUser3);
}
}
async function associateChatSessionWithAi_model() {
const relatedAi_model0 = await AiModels.findOne({
offset: Math.floor(Math.random() * (await AiModels.count())),
});
const ChatSession0 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ChatSession0?.setAi_model)
{
await
ChatSession0.
setAi_model(relatedAi_model0);
}
const relatedAi_model1 = await AiModels.findOne({
offset: Math.floor(Math.random() * (await AiModels.count())),
});
const ChatSession1 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ChatSession1?.setAi_model)
{
await
ChatSession1.
setAi_model(relatedAi_model1);
}
const relatedAi_model2 = await AiModels.findOne({
offset: Math.floor(Math.random() * (await AiModels.count())),
});
const ChatSession2 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ChatSession2?.setAi_model)
{
await
ChatSession2.
setAi_model(relatedAi_model2);
}
const relatedAi_model3 = await AiModels.findOne({
offset: Math.floor(Math.random() * (await AiModels.count())),
});
const ChatSession3 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ChatSession3?.setAi_model)
{
await
ChatSession3.
setAi_model(relatedAi_model3);
}
}
async function associateChatSessionWithSystem_prompt() {
const relatedSystem_prompt0 = await SystemPrompts.findOne({
offset: Math.floor(Math.random() * (await SystemPrompts.count())),
});
const ChatSession0 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ChatSession0?.setSystem_prompt)
{
await
ChatSession0.
setSystem_prompt(relatedSystem_prompt0);
}
const relatedSystem_prompt1 = await SystemPrompts.findOne({
offset: Math.floor(Math.random() * (await SystemPrompts.count())),
});
const ChatSession1 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ChatSession1?.setSystem_prompt)
{
await
ChatSession1.
setSystem_prompt(relatedSystem_prompt1);
}
const relatedSystem_prompt2 = await SystemPrompts.findOne({
offset: Math.floor(Math.random() * (await SystemPrompts.count())),
});
const ChatSession2 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ChatSession2?.setSystem_prompt)
{
await
ChatSession2.
setSystem_prompt(relatedSystem_prompt2);
}
const relatedSystem_prompt3 = await SystemPrompts.findOne({
offset: Math.floor(Math.random() * (await SystemPrompts.count())),
});
const ChatSession3 = await ChatSessions.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ChatSession3?.setSystem_prompt)
{
await
ChatSession3.
setSystem_prompt(relatedSystem_prompt3);
}
}
async function associateChatMessageWithChat_session() {
const relatedChat_session0 = await ChatSessions.findOne({
offset: Math.floor(Math.random() * (await ChatSessions.count())),
});
const ChatMessage0 = await ChatMessages.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ChatMessage0?.setChat_session)
{
await
ChatMessage0.
setChat_session(relatedChat_session0);
}
const relatedChat_session1 = await ChatSessions.findOne({
offset: Math.floor(Math.random() * (await ChatSessions.count())),
});
const ChatMessage1 = await ChatMessages.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ChatMessage1?.setChat_session)
{
await
ChatMessage1.
setChat_session(relatedChat_session1);
}
const relatedChat_session2 = await ChatSessions.findOne({
offset: Math.floor(Math.random() * (await ChatSessions.count())),
});
const ChatMessage2 = await ChatMessages.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ChatMessage2?.setChat_session)
{
await
ChatMessage2.
setChat_session(relatedChat_session2);
}
const relatedChat_session3 = await ChatSessions.findOne({
offset: Math.floor(Math.random() * (await ChatSessions.count())),
});
const ChatMessage3 = await ChatMessages.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ChatMessage3?.setChat_session)
{
await
ChatMessage3.
setChat_session(relatedChat_session3);
}
}
async function associateContentFlagWithChat_message() {
const relatedChat_message0 = await ChatMessages.findOne({
offset: Math.floor(Math.random() * (await ChatMessages.count())),
});
const ContentFlag0 = await ContentFlags.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ContentFlag0?.setChat_message)
{
await
ContentFlag0.
setChat_message(relatedChat_message0);
}
const relatedChat_message1 = await ChatMessages.findOne({
offset: Math.floor(Math.random() * (await ChatMessages.count())),
});
const ContentFlag1 = await ContentFlags.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ContentFlag1?.setChat_message)
{
await
ContentFlag1.
setChat_message(relatedChat_message1);
}
const relatedChat_message2 = await ChatMessages.findOne({
offset: Math.floor(Math.random() * (await ChatMessages.count())),
});
const ContentFlag2 = await ContentFlags.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ContentFlag2?.setChat_message)
{
await
ContentFlag2.
setChat_message(relatedChat_message2);
}
const relatedChat_message3 = await ChatMessages.findOne({
offset: Math.floor(Math.random() * (await ChatMessages.count())),
});
const ContentFlag3 = await ContentFlags.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ContentFlag3?.setChat_message)
{
await
ContentFlag3.
setChat_message(relatedChat_message3);
}
}
async function associateContentFlagWithReported_by() {
const relatedReported_by0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContentFlag0 = await ContentFlags.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ContentFlag0?.setReported_by)
{
await
ContentFlag0.
setReported_by(relatedReported_by0);
}
const relatedReported_by1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContentFlag1 = await ContentFlags.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ContentFlag1?.setReported_by)
{
await
ContentFlag1.
setReported_by(relatedReported_by1);
}
const relatedReported_by2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContentFlag2 = await ContentFlags.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ContentFlag2?.setReported_by)
{
await
ContentFlag2.
setReported_by(relatedReported_by2);
}
const relatedReported_by3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ContentFlag3 = await ContentFlags.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ContentFlag3?.setReported_by)
{
await
ContentFlag3.
setReported_by(relatedReported_by3);
}
}
async function associateApiKeyWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApiKey0 = await ApiKeys.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (ApiKey0?.setUser)
{
await
ApiKey0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApiKey1 = await ApiKeys.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (ApiKey1?.setUser)
{
await
ApiKey1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApiKey2 = await ApiKeys.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (ApiKey2?.setUser)
{
await
ApiKey2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const ApiKey3 = await ApiKeys.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (ApiKey3?.setUser)
{
await
ApiKey3.
setUser(relatedUser3);
}
}
async function associateUserPreferenceWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UserPreference0 = await UserPreferences.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (UserPreference0?.setUser)
{
await
UserPreference0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UserPreference1 = await UserPreferences.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (UserPreference1?.setUser)
{
await
UserPreference1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UserPreference2 = await UserPreferences.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (UserPreference2?.setUser)
{
await
UserPreference2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UserPreference3 = await UserPreferences.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (UserPreference3?.setUser)
{
await
UserPreference3.
setUser(relatedUser3);
}
}
async function associateUsageEventWithUser() {
const relatedUser0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent0 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (UsageEvent0?.setUser)
{
await
UsageEvent0.
setUser(relatedUser0);
}
const relatedUser1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent1 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (UsageEvent1?.setUser)
{
await
UsageEvent1.
setUser(relatedUser1);
}
const relatedUser2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent2 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (UsageEvent2?.setUser)
{
await
UsageEvent2.
setUser(relatedUser2);
}
const relatedUser3 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const UsageEvent3 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (UsageEvent3?.setUser)
{
await
UsageEvent3.
setUser(relatedUser3);
}
}
async function associateUsageEventWithChat_session() {
const relatedChat_session0 = await ChatSessions.findOne({
offset: Math.floor(Math.random() * (await ChatSessions.count())),
});
const UsageEvent0 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (UsageEvent0?.setChat_session)
{
await
UsageEvent0.
setChat_session(relatedChat_session0);
}
const relatedChat_session1 = await ChatSessions.findOne({
offset: Math.floor(Math.random() * (await ChatSessions.count())),
});
const UsageEvent1 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (UsageEvent1?.setChat_session)
{
await
UsageEvent1.
setChat_session(relatedChat_session1);
}
const relatedChat_session2 = await ChatSessions.findOne({
offset: Math.floor(Math.random() * (await ChatSessions.count())),
});
const UsageEvent2 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (UsageEvent2?.setChat_session)
{
await
UsageEvent2.
setChat_session(relatedChat_session2);
}
const relatedChat_session3 = await ChatSessions.findOne({
offset: Math.floor(Math.random() * (await ChatSessions.count())),
});
const UsageEvent3 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (UsageEvent3?.setChat_session)
{
await
UsageEvent3.
setChat_session(relatedChat_session3);
}
}
async function associateUsageEventWithAi_model() {
const relatedAi_model0 = await AiModels.findOne({
offset: Math.floor(Math.random() * (await AiModels.count())),
});
const UsageEvent0 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (UsageEvent0?.setAi_model)
{
await
UsageEvent0.
setAi_model(relatedAi_model0);
}
const relatedAi_model1 = await AiModels.findOne({
offset: Math.floor(Math.random() * (await AiModels.count())),
});
const UsageEvent1 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (UsageEvent1?.setAi_model)
{
await
UsageEvent1.
setAi_model(relatedAi_model1);
}
const relatedAi_model2 = await AiModels.findOne({
offset: Math.floor(Math.random() * (await AiModels.count())),
});
const UsageEvent2 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (UsageEvent2?.setAi_model)
{
await
UsageEvent2.
setAi_model(relatedAi_model2);
}
const relatedAi_model3 = await AiModels.findOne({
offset: Math.floor(Math.random() * (await AiModels.count())),
});
const UsageEvent3 = await UsageEvents.findOne({
order: [['id', 'ASC']],
offset: 3
});
if (UsageEvent3?.setAi_model)
{
await
UsageEvent3.
setAi_model(relatedAi_model3);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await AiModels.bulkCreate(AiModelsData);
await SystemPrompts.bulkCreate(SystemPromptsData);
await ChatSessions.bulkCreate(ChatSessionsData);
await ChatMessages.bulkCreate(ChatMessagesData);
await ContentFlags.bulkCreate(ContentFlagsData);
await ApiKeys.bulkCreate(ApiKeysData);
await UserPreferences.bulkCreate(UserPreferencesData);
await UsageEvents.bulkCreate(UsageEventsData);
await Promise.all([
// Similar logic for "relation_many"
await associateChatSessionWithUser(),
await associateChatSessionWithAi_model(),
await associateChatSessionWithSystem_prompt(),
await associateChatMessageWithChat_session(),
await associateContentFlagWithChat_message(),
await associateContentFlagWithReported_by(),
await associateApiKeyWithUser(),
await associateUserPreferenceWithUser(),
await associateUsageEventWithUser(),
await associateUsageEventWithChat_session(),
await associateUsageEventWithAi_model(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('ai_models', null, {});
await queryInterface.bulkDelete('system_prompts', null, {});
await queryInterface.bulkDelete('chat_sessions', null, {});
await queryInterface.bulkDelete('chat_messages', null, {});
await queryInterface.bulkDelete('content_flags', null, {});
await queryInterface.bulkDelete('api_keys', null, {});
await queryInterface.bulkDelete('user_preferences', null, {});
await queryInterface.bulkDelete('usage_events', null, {});
},
};