37801-vm/backend/src/db/seeders/20231127130745-sample-data.js
2026-01-25 11:38:53 +00:00

1955 lines
36 KiB
JavaScript

const db = require('../models');
const Users = db.users;
const Projects = db.projects;
const Scripts = db.scripts;
const Builds = db.builds;
const VmConfigs = db.vm_configs;
const OpcodeSets = db.opcode_sets;
const Constants = db.constants;
const AuditLogs = db.audit_logs;
const ProjectsData = [
{
"name": "luartex-core",
"description": "Core VM runtime and instruction set definitions",
// type code here for "relation_one" field
"repo_url": "https://example.com/luartex-core.git",
"license_key": "CORE-2025-0001",
"is_public": true,
},
{
"name": "luartex-web",
"description": "Web UI and build orchestration for Luartex",
// type code here for "relation_one" field
"repo_url": "https://example.com/luartex-web.git",
"license_key": "WEB-2025-0002",
"is_public": true,
},
{
"name": "examples-and-demos",
"description": "Sample scripts and demo projects for tutorials",
// type code here for "relation_one" field
"repo_url": "https://example.com/luartex-examples.git",
"license_key": "DEMO-2025-0003",
"is_public": true,
},
];
const ScriptsData = [
{
"title": "auth_handler",
"source_language": "lua",
// type code here for "relation_one" field
// type code here for "files" field
// type code here for "files" field
"status": "built",
"checksum": "b6f8d2c4",
"lines_count": 220,
},
{
"title": "save_to_datastore",
"source_language": "lua5.1",
// type code here for "relation_one" field
// type code here for "files" field
// type code here for "files" field
"status": "draft",
"checksum": "f2a9c7e1",
"lines_count": 98,
},
{
"title": "ui_sync_worker",
"source_language": "luau",
// type code here for "relation_one" field
// type code here for "files" field
// type code here for "files" field
"status": "draft",
"checksum": "d1c3b8a7",
"lines_count": 156,
},
];
const BuildsData = [
{
"version": "2025.01.01",
// type code here for "relation_one" field
// type code here for "relation_one" field
"issued_at": new Date('2025-01-15T09:30:00Z'),
"expires_at": new Date('2026-01-15T09:30:00Z'),
// type code here for "files" field
"notes": "Stable build for production runtime",
"success": true,
},
{
"version": "2025.01.02-ci",
// type code here for "relation_one" field
// type code here for "relation_one" field
"issued_at": new Date('2025-01-20T04:00:00Z'),
"expires_at": new Date('2025-07-20T04:00:00Z'),
// type code here for "files" field
"notes": "CI quick-build for integration tests",
"success": true,
},
{
"version": "2025.02.01-exp",
// type code here for "relation_one" field
// type code here for "relation_one" field
"issued_at": new Date('2025-02-10T12:00:00Z'),
"expires_at": new Date('2026-02-10T12:00:00Z'),
// type code here for "files" field
"notes": "Experimental opcode testing build",
"success": false,
},
];
const VmConfigsData = [
{
"name": "production-default",
"description": "Production VM configuration with balanced limits",
// type code here for "relation_one" field
"randomize_opcodes": true,
"max_stack": 256,
"entry_function": "main",
},
{
"name": "ci-fast",
"description": "CI build VM with deterministic opcodes",
// type code here for "relation_one" field
"randomize_opcodes": false,
"max_stack": 128,
"entry_function": "runner",
},
{
"name": "research-extended",
"description": "Research VM enabling experimental opcodes",
// type code here for "relation_one" field
"randomize_opcodes": true,
"max_stack": 1024,
"entry_function": "start",
},
];
const OpcodeSetsData = [
{
"name": "stable-v1",
"version": "1.0.0",
// type code here for "files" field
"opcode_count": 64,
"shuffled": false,
"notes": "Default production opcode mapping",
},
{
"name": "randomized-v1",
"version": "1.1.0",
// type code here for "files" field
"opcode_count": 64,
"shuffled": true,
"notes": "Shuffled opcode ids for additional diversity",
},
{
"name": "experimental",
"version": "0.9.0",
// type code here for "files" field
"opcode_count": 96,
"shuffled": true,
"notes": "Extended opcode set for research",
},
];
const ConstantsData = [
{
"key": "DEFAULT_TIMEOUT",
"value": "5000",
"encrypted": false,
"usage_count": 12,
// type code here for "relation_one" field
},
{
"key": "API_ENDPOINT",
"value": "https://api.example.com/v1",
"encrypted": true,
"usage_count": 7,
// type code here for "relation_one" field
},
{
"key": "MAX_RETRIES",
"value": "3",
"encrypted": false,
"usage_count": 4,
// type code here for "relation_one" field
},
];
const AuditLogsData = [
{
"action": "build_triggered",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"timestamp": new Date('2025-01-15T09:35:00Z'),
"details": "Scheduled production build",
},
{
"action": "vm_config_updated",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"timestamp": new Date('2025-02-11T10:12:00Z'),
"details": "Enabled experimental opcodes for research VM",
},
{
"action": "opcode_set_published",
// type code here for "relation_one" field
// type code here for "relation_one" field
// type code here for "relation_one" field
"timestamp": new Date('2025-01-10T07:00:00Z'),
"details": "Published stable-v1 opcode mapping",
},
];
// Similar logic for "relation_many"
async function associateProjectWithOwner() {
const relatedOwner0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project0 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Project0?.setOwner)
{
await
Project0.
setOwner(relatedOwner0);
}
const relatedOwner1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project1 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Project1?.setOwner)
{
await
Project1.
setOwner(relatedOwner1);
}
const relatedOwner2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const Project2 = await Projects.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Project2?.setOwner)
{
await
Project2.
setOwner(relatedOwner2);
}
}
async function associateScriptWithProject() {
const relatedProject0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Script0 = await Scripts.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Script0?.setProject)
{
await
Script0.
setProject(relatedProject0);
}
const relatedProject1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Script1 = await Scripts.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Script1?.setProject)
{
await
Script1.
setProject(relatedProject1);
}
const relatedProject2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Script2 = await Scripts.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Script2?.setProject)
{
await
Script2.
setProject(relatedProject2);
}
}
async function associateBuildWithScript() {
const relatedScript0 = await Scripts.findOne({
offset: Math.floor(Math.random() * (await Scripts.count())),
});
const Build0 = await Builds.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Build0?.setScript)
{
await
Build0.
setScript(relatedScript0);
}
const relatedScript1 = await Scripts.findOne({
offset: Math.floor(Math.random() * (await Scripts.count())),
});
const Build1 = await Builds.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Build1?.setScript)
{
await
Build1.
setScript(relatedScript1);
}
const relatedScript2 = await Scripts.findOne({
offset: Math.floor(Math.random() * (await Scripts.count())),
});
const Build2 = await Builds.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Build2?.setScript)
{
await
Build2.
setScript(relatedScript2);
}
}
async function associateBuildWithVm_config() {
const relatedVm_config0 = await VmConfigs.findOne({
offset: Math.floor(Math.random() * (await VmConfigs.count())),
});
const Build0 = await Builds.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Build0?.setVm_config)
{
await
Build0.
setVm_config(relatedVm_config0);
}
const relatedVm_config1 = await VmConfigs.findOne({
offset: Math.floor(Math.random() * (await VmConfigs.count())),
});
const Build1 = await Builds.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Build1?.setVm_config)
{
await
Build1.
setVm_config(relatedVm_config1);
}
const relatedVm_config2 = await VmConfigs.findOne({
offset: Math.floor(Math.random() * (await VmConfigs.count())),
});
const Build2 = await Builds.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Build2?.setVm_config)
{
await
Build2.
setVm_config(relatedVm_config2);
}
}
async function associateVmConfigWithOpcode_set() {
const relatedOpcode_set0 = await OpcodeSets.findOne({
offset: Math.floor(Math.random() * (await OpcodeSets.count())),
});
const VmConfig0 = await VmConfigs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (VmConfig0?.setOpcode_set)
{
await
VmConfig0.
setOpcode_set(relatedOpcode_set0);
}
const relatedOpcode_set1 = await OpcodeSets.findOne({
offset: Math.floor(Math.random() * (await OpcodeSets.count())),
});
const VmConfig1 = await VmConfigs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (VmConfig1?.setOpcode_set)
{
await
VmConfig1.
setOpcode_set(relatedOpcode_set1);
}
const relatedOpcode_set2 = await OpcodeSets.findOne({
offset: Math.floor(Math.random() * (await OpcodeSets.count())),
});
const VmConfig2 = await VmConfigs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (VmConfig2?.setOpcode_set)
{
await
VmConfig2.
setOpcode_set(relatedOpcode_set2);
}
}
async function associateConstantWithOwner_project() {
const relatedOwner_project0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Constant0 = await Constants.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (Constant0?.setOwner_project)
{
await
Constant0.
setOwner_project(relatedOwner_project0);
}
const relatedOwner_project1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Constant1 = await Constants.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (Constant1?.setOwner_project)
{
await
Constant1.
setOwner_project(relatedOwner_project1);
}
const relatedOwner_project2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const Constant2 = await Constants.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (Constant2?.setOwner_project)
{
await
Constant2.
setOwner_project(relatedOwner_project2);
}
}
async function associateAuditLogWithActor() {
const relatedActor0 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AuditLog0 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AuditLog0?.setActor)
{
await
AuditLog0.
setActor(relatedActor0);
}
const relatedActor1 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AuditLog1 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AuditLog1?.setActor)
{
await
AuditLog1.
setActor(relatedActor1);
}
const relatedActor2 = await Users.findOne({
offset: Math.floor(Math.random() * (await Users.count())),
});
const AuditLog2 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AuditLog2?.setActor)
{
await
AuditLog2.
setActor(relatedActor2);
}
}
async function associateAuditLogWithTarget_project() {
const relatedTarget_project0 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const AuditLog0 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AuditLog0?.setTarget_project)
{
await
AuditLog0.
setTarget_project(relatedTarget_project0);
}
const relatedTarget_project1 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const AuditLog1 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AuditLog1?.setTarget_project)
{
await
AuditLog1.
setTarget_project(relatedTarget_project1);
}
const relatedTarget_project2 = await Projects.findOne({
offset: Math.floor(Math.random() * (await Projects.count())),
});
const AuditLog2 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AuditLog2?.setTarget_project)
{
await
AuditLog2.
setTarget_project(relatedTarget_project2);
}
}
async function associateAuditLogWithTarget_script() {
const relatedTarget_script0 = await Scripts.findOne({
offset: Math.floor(Math.random() * (await Scripts.count())),
});
const AuditLog0 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 0
});
if (AuditLog0?.setTarget_script)
{
await
AuditLog0.
setTarget_script(relatedTarget_script0);
}
const relatedTarget_script1 = await Scripts.findOne({
offset: Math.floor(Math.random() * (await Scripts.count())),
});
const AuditLog1 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 1
});
if (AuditLog1?.setTarget_script)
{
await
AuditLog1.
setTarget_script(relatedTarget_script1);
}
const relatedTarget_script2 = await Scripts.findOne({
offset: Math.floor(Math.random() * (await Scripts.count())),
});
const AuditLog2 = await AuditLogs.findOne({
order: [['id', 'ASC']],
offset: 2
});
if (AuditLog2?.setTarget_script)
{
await
AuditLog2.
setTarget_script(relatedTarget_script2);
}
}
module.exports = {
up: async (queryInterface, Sequelize) => {
await Projects.bulkCreate(ProjectsData);
await Scripts.bulkCreate(ScriptsData);
await Builds.bulkCreate(BuildsData);
await VmConfigs.bulkCreate(VmConfigsData);
await OpcodeSets.bulkCreate(OpcodeSetsData);
await Constants.bulkCreate(ConstantsData);
await AuditLogs.bulkCreate(AuditLogsData);
await Promise.all([
// Similar logic for "relation_many"
await associateProjectWithOwner(),
await associateScriptWithProject(),
await associateBuildWithScript(),
await associateBuildWithVm_config(),
await associateVmConfigWithOpcode_set(),
await associateConstantWithOwner_project(),
await associateAuditLogWithActor(),
await associateAuditLogWithTarget_project(),
await associateAuditLogWithTarget_script(),
]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.bulkDelete('projects', null, {});
await queryInterface.bulkDelete('scripts', null, {});
await queryInterface.bulkDelete('builds', null, {});
await queryInterface.bulkDelete('vm_configs', null, {});
await queryInterface.bulkDelete('opcode_sets', null, {});
await queryInterface.bulkDelete('constants', null, {});
await queryInterface.bulkDelete('audit_logs', null, {});
},
};