PSA/server/seeds/dev/18_documents.cjs
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

154 lines
5.5 KiB
JavaScript

exports.seed = async function (knex) {
// Get tenant first
const tenant = await knex('tenants').select('tenant').first();
if (!tenant) return;
// Insert documents
const documents = await knex('documents')
.insert([
{
tenant: tenant.tenant,
document_name: 'Alice Lost White Rabbit',
type_id: knex('document_types')
.where({
tenant: tenant.tenant,
type_name: 'Ticket'
})
.select('type_id')
.first(),
user_id: knex('users')
.where({
tenant: tenant.tenant,
username: 'glinda'
})
.select('user_id')
.first(),
created_by: knex('users')
.where({
tenant: tenant.tenant,
username: 'glinda'
})
.select('user_id')
.first(),
entered_at: knex.fn.now(),
content: 'Searched for White Rabbit in Wonderland. No luck yet.'
},
{
tenant: tenant.tenant,
document_name: 'Client Profile',
type_id: knex('document_types')
.where({
tenant: tenant.tenant,
type_name: 'Client'
})
.select('type_id')
.first(),
user_id: knex('users')
.where({
tenant: tenant.tenant,
username: 'glinda'
})
.select('user_id')
.first(),
created_by: knex('users')
.where({
tenant: tenant.tenant,
username: 'glinda'
})
.select('user_id')
.first(),
entered_at: knex.fn.now(),
content: 'Wonderland Client Profile and Details'
},
{
tenant: tenant.tenant,
document_name: 'White Rabbit Search Plan',
type_id: knex('document_types')
.where({
tenant: tenant.tenant,
type_name: 'Ticket'
})
.select('type_id')
.first(),
user_id: knex('users')
.where({
tenant: tenant.tenant,
username: 'glinda'
})
.select('user_id')
.first(),
created_by: knex('users')
.where({
tenant: tenant.tenant,
username: 'glinda'
})
.select('user_id')
.first(),
entered_at: knex.fn.now(),
content: `Further actions for White Rabbit search:
1. Check the rabbit hole near the old oak tree.
2. Interview the Cheshire Cat for possible sightings.
3. Set up carrot traps in key locations around Wonderland.
4. Distribute "Missing Rabbit" posters with detailed description and time-keeping habits.
5. Investigate any reports of pocket watch ticking in unusual places.
6. Coordinate with the Queen of Hearts'' guards for a palace grounds search.
7. Monitor all tea parties for any signs of the White Rabbit.
8. Check with the Mad Hatter for any recent hat orders fitting the White Rabbit''s size.
9. Explore the Tulgey Wood, a known shortcut for hurried rabbits.
10. Set up a hotline for Wonderland residents to report any rabbit sightings.`
}
])
.returning(['document_id']);
// Get the ticket ID we want to associate with
const ticketId = await knex('tickets')
.where({
tenant: tenant.tenant,
title: 'Lost White Rabbit'
})
.select('ticket_id')
.first();
// Get the client ID we want to associate with
const clientId = await knex('clients')
.where({
tenant: tenant.tenant,
client_name: 'Wonderland Inc'
})
.select('client_id')
.first();
// Create associations if we have the related entities
const associations = [];
if (ticketId) {
associations.push(
{
tenant: tenant.tenant,
document_id: documents[0].document_id,
entity_id: ticketId.ticket_id,
entity_type: 'ticket'
},
{
tenant: tenant.tenant,
document_id: documents[2].document_id,
entity_id: ticketId.ticket_id,
entity_type: 'ticket'
}
);
}
if (clientId) {
associations.push({
tenant: tenant.tenant,
document_id: documents[1].document_id,
entity_id: clientId.client_id,
entity_type: 'client'
});
}
if (associations.length > 0) {
await knex('document_associations').insert(associations);
}
};