Hub 2.3.0: install Accounts (first product, or added next to a church's others)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -142,6 +142,7 @@ async function afterJob(job, { exportKey }, now) {
|
||||
|
||||
switch (job.type) {
|
||||
case 'install':
|
||||
case 'add-product':
|
||||
if (!deployment) break;
|
||||
if (ok) {
|
||||
const version = job.report?.result?.versions?.[deployment.product] || null;
|
||||
@@ -239,7 +240,7 @@ async function tick(now = new Date()) {
|
||||
if (job.noticeId) await endNotice(job.noticeId, now);
|
||||
await emailJoshua(`Missed job: ${job.type} on ${job.server.name}`, `${updated.message}\nNothing ran. A new time needs a new notice to the church.\n\n${hubUrl()}/jobs/${job.id}`);
|
||||
if (job.batchId) await advanceBatch(updated, now);
|
||||
if (job.type === 'install' && job.deploymentId) {
|
||||
if ((job.type === 'install' || job.type === 'add-product') && job.deploymentId) {
|
||||
await prisma.deployment.update({ where: { id: job.deploymentId }, data: { status: 'failed' } });
|
||||
}
|
||||
}
|
||||
@@ -378,10 +379,17 @@ async function preflight(server, product, version, now) {
|
||||
if (parts.length) throw fail(409, 'CONFIG_MISSING', `${parts.join('; ')} (Servers → ${server.name} → Configuration).`);
|
||||
}
|
||||
|
||||
/** New install (§7): licence, ports, the install job. */
|
||||
/** Products the Hub can install so far (Accounts from Hub 2.3.0, docs/ACCOUNTS-1.0-PLAN.md §9). */
|
||||
const INSTALLABLE = new Set(['events', 'accounts']);
|
||||
|
||||
/**
|
||||
* New install (§7): licence, ports, the install job. A church already on that server (the same
|
||||
* short name, another product) gets the product added next to its others (an `add-product` job,
|
||||
* `crosscode add`), e.g. Accounts next to Events.
|
||||
*/
|
||||
async function newInstall(input, admin, now = new Date()) {
|
||||
const product = input.product || 'events';
|
||||
if (product !== 'events') throw fail(400, 'BAD_REQUEST', 'Only Cross Events can be installed so far.');
|
||||
if (!INSTALLABLE.has(product)) throw fail(400, 'BAD_REQUEST', `${PRODUCT_NAMES[product] || product} can't be installed from the Hub yet.`);
|
||||
const shortName = String(input.shortName || '').trim();
|
||||
if (!SHORT_NAME.test(shortName)) throw fail(400, 'BAD_REQUEST', 'The short name is 2–31 characters: a-z, 0-9 and -, starting with a letter.');
|
||||
const domain = String(input.domain || '').trim().toLowerCase();
|
||||
@@ -396,7 +404,13 @@ async function newInstall(input, admin, now = new Date()) {
|
||||
if (!server) throw fail(404, 'NOT_FOUND', 'Server not found.');
|
||||
const release = await releaseFor(product, input.version || null);
|
||||
await preflight(server, product, release.version, now);
|
||||
if (await prisma.deployment.findFirst({ where: { shortName, status: { notIn: ['removed', 'failed'] } } })) throw fail(409, 'SHORT_NAME_TAKEN', `The short name ${shortName} is already used.`);
|
||||
// The church's other products: the same short name means the same church folder on one server.
|
||||
const siblings = await prisma.deployment.findMany({ where: { shortName, status: { notIn: ['removed', 'failed'] } } });
|
||||
if (siblings.some(s => s.product === product)) throw fail(409, 'SHORT_NAME_TAKEN', `${shortName} already has ${PRODUCT_NAMES[product]}.`);
|
||||
if (siblings.some(s => s.customerId !== customer.id)) throw fail(409, 'SHORT_NAME_TAKEN', `The short name ${shortName} is already used by another customer.`);
|
||||
if (siblings.some(s => s.serverId !== server.id)) throw fail(409, 'OTHER_SERVER', `${shortName}'s other products are on another server; a church's products go on one server.`);
|
||||
if (siblings.some(s => s.status !== 'live' && s.status !== 'waiting_for_proxy')) throw fail(409, 'BUSY', `Wait until ${shortName}'s other install has finished.`);
|
||||
const add = siblings.length > 0;
|
||||
// The name is free again after a failed install (its ports were already freed) or an uninstall.
|
||||
// A failed install's record goes; a removed one keeps its history under another name (the
|
||||
// database allows one install per short name and product). Found in the VM test.
|
||||
@@ -417,10 +431,15 @@ async function newInstall(input, admin, now = new Date()) {
|
||||
data: { serverId: server.id, customerId: customer.id, licenceId: licence.id, product, shortName, domain, webPort: ports.web, apiPort: ports.api, timezone: input.timezone || null, adminName: input.adminName || null, adminEmail: adminEmail || null, status: 'installing' },
|
||||
});
|
||||
await tx.port.updateMany({ where: { port: { in: [ports.web, ports.api] } }, data: { deploymentId: d.id } });
|
||||
await makeJob(tx, {
|
||||
serverId: server.id, type: 'install', deploymentId: d.id, createdById: admin?.id || null, notBefore: now,
|
||||
args: { church: shortName, products: [product], versions: { [product]: `${product}@${release.version}` }, domains: { [product]: domain }, ports: { [product]: ports } },
|
||||
});
|
||||
await makeJob(tx, add
|
||||
? {
|
||||
serverId: server.id, type: 'add-product', deploymentId: d.id, createdById: admin?.id || null, notBefore: now,
|
||||
args: { church: shortName, product, version: `${product}@${release.version}`, domain, ports },
|
||||
}
|
||||
: {
|
||||
serverId: server.id, type: 'install', deploymentId: d.id, createdById: admin?.id || null, notBefore: now,
|
||||
args: { church: shortName, products: [product], versions: { [product]: `${product}@${release.version}` }, domains: { [product]: domain }, ports: { [product]: ports } },
|
||||
});
|
||||
return d;
|
||||
});
|
||||
return { deployment, warnings };
|
||||
|
||||
Reference in New Issue
Block a user