Hub 2.5.0: a New install of Events 3.x installs the church's Accounts first
A release's "requires accounts" is met at install: Accounts then the product in one batch (the product runs only after Accounts succeeded; a failed Accounts fails the product's record and frees its ports). Accounts domain from the form, or accounts.<rest of the domain>. An Accounts older than required is refused. Contracts 1.8.0 vendored. 4 new tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+72
-10
@@ -232,6 +232,11 @@ async function advanceBatch(job, now) {
|
||||
if (j.deployment && j.type === 'uninstall') {
|
||||
await prisma.deployment.update({ where: { id: j.deployment.id }, data: { status: statusBeforeUninstall(j.deployment) } });
|
||||
}
|
||||
// Hub 2.5.0: the product after a failed Accounts install never ran: its record fails and its ports are freed.
|
||||
if (j.deployment && (j.type === 'install' || j.type === 'add-product')) {
|
||||
await prisma.deployment.update({ where: { id: j.deployment.id }, data: { status: 'failed' } });
|
||||
await prisma.port.deleteMany({ where: { port: { in: [j.deployment.webPort, j.deployment.apiPort] } } });
|
||||
}
|
||||
if (j.deployment && j.scheduled && j.type === 'deploy') {
|
||||
await emailSiteAdmin(j.deployment, `${PRODUCT_NAMES[j.deployment.product]} update postponed`, `The planned update of ${PRODUCT_NAMES[j.deployment.product]} at ${j.deployment.domain} has been postponed. Your site keeps running as it is; we'll let you know the new time.`);
|
||||
}
|
||||
@@ -423,7 +428,11 @@ async function newInstall(input, admin, now = new Date()) {
|
||||
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;
|
||||
// Hub 2.5.0: a release that needs a sibling (Cross Events 3.0: "— requires accounts 1.1.0") gets
|
||||
// it. A church without Accounts has it installed first, in the same batch; one with an older
|
||||
// Accounts is refused until it's updated.
|
||||
const first = await requiredFirst({ release, product, siblings, input, domain, server, now });
|
||||
const add = siblings.length > 0 || !!first;
|
||||
// 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.
|
||||
@@ -435,18 +444,39 @@ async function newInstall(input, admin, now = new Date()) {
|
||||
const dnsOk = await dnsPointsAtCentral(domain);
|
||||
if (dnsOk === false) warnings.push(`${domain} doesn't point at the central server yet (the install still runs).`);
|
||||
|
||||
if (first) {
|
||||
const dnsFirst = await dnsPointsAtCentral(first.domain);
|
||||
if (dnsFirst === false) warnings.push(`${first.domain} doesn't point at the central server yet (the install still runs).`);
|
||||
}
|
||||
|
||||
const deployment = await prisma.$transaction(async tx => {
|
||||
let licence = await tx.licence.findFirst({ where: { customerId: customer.id, product, status: { not: 'revoked' } }, include: { install: true } });
|
||||
if (licence?.install && !licence.install.releasedAt) throw fail(409, 'LICENCE_IN_USE', `${customer.name}'s ${PRODUCT_NAMES[product]} licence is already used by ${licence.install.url}.`);
|
||||
if (!licence) licence = (await generateLicence(tx, { customerId: customer.id, product, now })).licence;
|
||||
const ports = await servers.allocatePorts(tx, server.id, now);
|
||||
const d = await tx.deployment.create({
|
||||
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 } });
|
||||
const make = async (p, dom) => {
|
||||
let licence = await tx.licence.findFirst({ where: { customerId: customer.id, product: p, status: { not: 'revoked' } }, include: { install: true } });
|
||||
if (licence?.install && !licence.install.releasedAt) throw fail(409, 'LICENCE_IN_USE', `${customer.name}'s ${PRODUCT_NAMES[p]} licence is already used by ${licence.install.url}.`);
|
||||
if (!licence) licence = (await generateLicence(tx, { customerId: customer.id, product: p, now })).licence;
|
||||
const ports = await servers.allocatePorts(tx, server.id, now);
|
||||
const d = await tx.deployment.create({
|
||||
data: { serverId: server.id, customerId: customer.id, licenceId: licence.id, product: p, shortName, domain: dom, 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 } });
|
||||
return { d, ports };
|
||||
};
|
||||
// Accounts first (an install job), then the product next to it once that succeeded (a batch).
|
||||
const batchId = first ? servers.newId('batch') : null;
|
||||
if (first) {
|
||||
const a = await make('accounts', first.domain);
|
||||
await makeJob(tx, {
|
||||
serverId: server.id, type: siblings.length ? 'add-product' : 'install', deploymentId: a.d.id, createdById: admin?.id || null, notBefore: now, batchId, batchOrder: 0,
|
||||
args: siblings.length
|
||||
? { church: shortName, product: 'accounts', version: `accounts@${first.release.version}`, domain: first.domain, ports: a.ports }
|
||||
: { church: shortName, products: ['accounts'], versions: { accounts: `accounts@${first.release.version}` }, domains: { accounts: first.domain }, ports: { accounts: a.ports } },
|
||||
});
|
||||
}
|
||||
const { d, ports } = await make(product, domain);
|
||||
await makeJob(tx, add
|
||||
? {
|
||||
serverId: server.id, type: 'add-product', deploymentId: d.id, createdById: admin?.id || null, notBefore: now,
|
||||
...(batchId ? { batchId, batchOrder: 1, status: 'scheduled' } : {}),
|
||||
args: { church: shortName, product, version: `${product}@${release.version}`, domain, ports },
|
||||
}
|
||||
: {
|
||||
@@ -455,7 +485,39 @@ async function newInstall(input, admin, now = new Date()) {
|
||||
});
|
||||
return d;
|
||||
});
|
||||
return { deployment, warnings };
|
||||
return { deployment, warnings, ...(first ? { alsoInstalling: { product: 'accounts', domain: first.domain, version: first.release.version } } : {}) };
|
||||
}
|
||||
|
||||
/** `events.hope.co.za` → `accounts.hope.co.za`: the first label swapped (ROADMAP-v3 decision 6). */
|
||||
function accountsDomainFor(domain) {
|
||||
const parts = domain.split('.');
|
||||
return parts.length > 2 ? ['accounts', ...parts.slice(1)].join('.') : `accounts.${domain}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* What a release needs installed first (Hub 2.5.0): its required Accounts, when the church has none.
|
||||
* Null when nothing is needed; refused when the church's Accounts is older than required, or no
|
||||
* Accounts release is new enough.
|
||||
*/
|
||||
async function requiredFirst({ release, product, siblings, input, domain, server, now }) {
|
||||
if (product === 'accounts') return null;
|
||||
const need = (Array.isArray(release.requires) ? release.requires : []).find(q => q && q.product === 'accounts');
|
||||
if (!need) return null;
|
||||
const have = siblings.find(s => s.product === 'accounts');
|
||||
if (have) {
|
||||
if (have.version && compareVersions(have.version, need.version) < 0) {
|
||||
throw fail(409, 'REQUIREMENT_NOT_MET', `${PRODUCT_NAMES[product]} ${release.version} needs Accounts ${need.version} or later; this church has ${have.version}. Update its Accounts first.`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const accountsRelease = await releaseFor('accounts', null);
|
||||
if (compareVersions(accountsRelease.version, need.version) < 0) {
|
||||
throw fail(409, 'REQUIREMENT_NOT_MET', `${PRODUCT_NAMES[product]} ${release.version} needs Accounts ${need.version}; the newest Accounts release is ${accountsRelease.version}.`);
|
||||
}
|
||||
const accountsDomain = String(input.accountsDomain || accountsDomainFor(domain)).trim().toLowerCase();
|
||||
if (!DOMAIN.test(accountsDomain) || accountsDomain === domain) throw fail(400, 'BAD_REQUEST', 'Give Accounts its own domain, like accounts.hope.co.za.');
|
||||
await preflight(server, 'accounts', accountsRelease.version, now);
|
||||
return { release: accountsRelease, domain: accountsDomain };
|
||||
}
|
||||
|
||||
/** Proxy done (§7.8): check the public addresses, then Live and the welcome email. */
|
||||
|
||||
Reference in New Issue
Block a user