Files
Void-Homelab/migrate/spaces.js
root 1a10bfea0d feat(migrate): ensureSpace helper
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 22:18:44 +10:00

13 lines
460 B
JavaScript

import { pool } from '../lib/db/pool.js';
import * as spaces from '../lib/db/repos/spaces.js';
const SYS = { kind: 'system', id: null };
// Returns the id of the space with `slug`, creating it if absent. Idempotent.
export async function ensureSpace(slug, name) {
const { rows: [r] } = await pool.query(`SELECT id FROM spaces WHERE slug=$1`, [slug]);
if (r) return r.id;
const created = await spaces.create({ slug, name }, SYS);
return created.id;
}