fix(deploy): migrate after stop and shrink DB pool
Stage migrate hit ER_CON_COUNT_ERROR while live still held the pool. Build in stage with DATABASE_POOL_SIZE=5, run db:migrate only after stopping the service (with retries), and lower the default pool from 40 to 10. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
687e1f9fb0
commit
fa40eebeed
4 files changed
+34
-7
No files matched your search
+1
-1
@@ -8,7 +8,7 @@ const schema = z.object({
|
||||
.enum(["development", "test", "production"])
|
||||
.default("development"),
|
||||
DATABASE_URL: z.string().url(),
|
||||
DATABASE_POOL_SIZE: z.coerce.number().int().positive().default(40),
|
||||
DATABASE_POOL_SIZE: z.coerce.number().int().positive().default(10),
|
||||
DATABASE_IDLE_TIMEOUT_MS: z.coerce.number().int().positive().default(300_000),
|
||||
DATABASE_CONNECT_TIMEOUT_MS: z.coerce
|
||||
.number()
|
||||
|
||||
@@ -14,6 +14,7 @@ describe("production deploy workflow", () => {
|
||||
expect(deployJob).toContain("/var/tmp/atom-nexst-stage-");
|
||||
expect(deployJob).toContain('ln -sfn "${LIVE}/.env"');
|
||||
expect(deployJob).toContain("-e storage");
|
||||
expect(deployJob).toContain("DATABASE_POOL_SIZE=");
|
||||
expect(deployJob).not.toContain("SKIP_ENV_VALIDATION=1");
|
||||
expect(deployJob).toContain("pnpm install --frozen-lockfile");
|
||||
});
|
||||
@@ -25,7 +26,7 @@ describe("production deploy workflow", () => {
|
||||
const reclaimAt = deployJob.indexOf(
|
||||
'sudo chown -R "$' + "{DEPLOY_USER}:" + '$' + '{DEPLOY_GROUP}"',
|
||||
);
|
||||
const fetchAt = deployJob.indexOf("git -C \"${LIVE}\" fetch origin --prune");
|
||||
const fetchAt = deployJob.indexOf('git -C "${LIVE}" fetch origin --prune');
|
||||
expect(reclaimAt).toBeGreaterThan(-1);
|
||||
expect(fetchAt).toBeGreaterThan(reclaimAt);
|
||||
});
|
||||
@@ -48,6 +49,7 @@ describe("production deploy workflow", () => {
|
||||
expect(deployJob).toContain("Rolling back .next to previous artifact");
|
||||
const buildAt = deployJob.indexOf("pnpm build");
|
||||
const stopAt = deployJob.indexOf("sudo systemctl stop atom-nexst.service");
|
||||
const migrateAt = deployJob.indexOf("pnpm db:migrate");
|
||||
const startLabelAt = deployJob.indexOf("Starting systemd service...");
|
||||
const startAt = deployJob.indexOf(
|
||||
"sudo systemctl start atom-nexst.service",
|
||||
@@ -55,7 +57,9 @@ describe("production deploy workflow", () => {
|
||||
);
|
||||
expect(buildAt).toBeGreaterThan(-1);
|
||||
expect(stopAt).toBeGreaterThan(buildAt);
|
||||
expect(startLabelAt).toBeGreaterThan(stopAt);
|
||||
// Migrate runs after stop so the live pool frees DB slots.
|
||||
expect(migrateAt).toBeGreaterThan(stopAt);
|
||||
expect(startLabelAt).toBeGreaterThan(migrateAt);
|
||||
expect(startAt).toBeGreaterThan(startLabelAt);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user