Skip to content

Commit 399ed31

Browse files
committed
hotfix
1 parent d354ecd commit 399ed31

File tree

4 files changed

+160
-149
lines changed

4 files changed

+160
-149
lines changed

deploy/dev/wrangler.jsonc

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,60 @@
11
{
2-
"name": "unitn-oj-dev",
3-
"compatibility_date": "2025-09-06",
4-
"compatibility_flags": ["nodejs_compat"],
2+
"name": "unitn-oj-dev",
3+
"compatibility_date": "2025-09-06",
4+
"compatibility_flags": ["nodejs_compat"],
55

6-
"pages_build_output_dir": "../../frontend/.svelte-kit/cloudflare",
6+
"pages_build_output_dir": "../../frontend/.svelte-kit/cloudflare",
77

8-
"env": {
9-
"preview": {
10-
"d1_databases": [
11-
{
12-
"binding": "DB",
13-
"database_name": "unitn-oj-dev",
14-
"database_id": "84a77c0f-9983-43da-bd6c-35982cb191bb",
15-
"migrations_dir": "../../frontend/d1/migrations"
16-
}
17-
],
18-
"queues": {
19-
"producers": [
20-
{ "queue": "unitn-oj-submissions-dev", "binding": "QUEUE_SUBMISSIONS" }
21-
]
22-
},
23-
"vars": {
24-
"APP_ENV": "env",
25-
"AUTH_ALLOWED_DOMAIN": "studenti.unitn.it",
26-
"AUTH_TOKEN_TTL_SECONDS": "300",
27-
"AUTH_SESSION_TTL_SECONDS": "604800",
28-
"AUTH_SESSION_SECRET": "remote-dev-secret"
29-
}
30-
},
31-
"production": {
32-
"d1_databases": [
33-
{
34-
"binding": "DB",
35-
"database_name": "unitn-oj-dev",
36-
"database_id": "84a77c0f-9983-43da-bd6c-35982cb191bb",
37-
"migrations_dir": "../../frontend/d1/migrations"
38-
}
39-
],
40-
"queues": {
41-
"producers": [
42-
{ "queue": "unitn-oj-submissions-dev", "binding": "QUEUE_SUBMISSIONS" }
43-
]
44-
},
45-
"vars": {
46-
"APP_ENV": "env",
47-
"AUTH_ALLOWED_DOMAIN": "studenti.unitn.it",
48-
"AUTH_TOKEN_TTL_SECONDS": "300",
49-
"AUTH_SESSION_TTL_SECONDS": "604800",
50-
"AUTH_SESSION_SECRET": "remote-dev-secret"
51-
}
52-
}
53-
}
8+
"env": {
9+
"preview": {
10+
"d1_databases": [
11+
{
12+
"binding": "DB",
13+
"database_name": "unitn-oj-dev",
14+
"database_id": "84a77c0f-9983-43da-bd6c-35982cb191bb",
15+
"migrations_dir": "../../frontend/d1/migrations"
16+
}
17+
],
18+
"queues": {
19+
"producers": [
20+
{
21+
"queue": "unitn-oj-submissions-dev",
22+
"binding": "QUEUE_SUBMISSIONS"
23+
}
24+
]
25+
},
26+
"vars": {
27+
"APP_ENV": "env",
28+
"AUTH_ALLOWED_DOMAIN": "studenti.unitn.it",
29+
"AUTH_TOKEN_TTL_SECONDS": "300",
30+
"AUTH_SESSION_TTL_SECONDS": "604800",
31+
"AUTH_SESSION_SECRET": "remote-dev-secret"
32+
}
33+
},
34+
"production": {
35+
"d1_databases": [
36+
{
37+
"binding": "DB",
38+
"database_name": "unitn-oj-dev",
39+
"database_id": "84a77c0f-9983-43da-bd6c-35982cb191bb",
40+
"migrations_dir": "../../frontend/d1/migrations"
41+
}
42+
],
43+
"queues": {
44+
"producers": [
45+
{
46+
"queue": "unitn-oj-submissions-dev",
47+
"binding": "QUEUE_SUBMISSIONS"
48+
}
49+
]
50+
},
51+
"vars": {
52+
"APP_ENV": "env",
53+
"AUTH_ALLOWED_DOMAIN": "studenti.unitn.it",
54+
"AUTH_TOKEN_TTL_SECONDS": "300",
55+
"AUTH_SESSION_TTL_SECONDS": "604800",
56+
"AUTH_SESSION_SECRET": "remote-dev-secret"
57+
}
58+
}
59+
}
5460
}

deploy/prod/wrangler.jsonc

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
{
2-
"name": "unitn-oj",
3-
"compatibility_date": "2025-09-06",
4-
"compatibility_flags": ["nodejs_compat"],
5-
"pages_build_output_dir": "../../frontend/.svelte-kit/cloudflare",
6-
"env": {
7-
"preview": {
8-
"d1_databases": [
9-
{
10-
"binding": "DB",
11-
"database_name": "unitn-oj",
12-
"database_id": "<PROD_D1_UUID>",
13-
"migrations_dir": "../../frontend/d1/migrations"
14-
}
15-
],
16-
"queues": {
17-
"producers": [
18-
{ "queue": "unitn-oj-submissions", "binding": "QUEUE_SUBMISSIONS" }
19-
]
20-
},
21-
"vars": {
22-
"APP_ENV": "prod"
23-
}
24-
},
25-
"production": {
26-
"d1_databases": [
27-
{
28-
"binding": "DB",
29-
"database_name": "unitn-oj",
30-
"database_id": "<PROD_D1_UUID>",
31-
"migrations_dir": "../../frontend/d1/migrations"
32-
}
33-
],
34-
"queues": {
35-
"producers": [
36-
{ "queue": "unitn-oj-submissions", "binding": "QUEUE_SUBMISSIONS" }
37-
]
38-
},
39-
"vars": {
40-
"APP_ENV": "prod"
41-
}
42-
}
43-
}
2+
"name": "unitn-oj",
3+
"compatibility_date": "2025-09-06",
4+
"compatibility_flags": ["nodejs_compat"],
5+
"pages_build_output_dir": "../../frontend/.svelte-kit/cloudflare",
6+
"env": {
7+
"preview": {
8+
"d1_databases": [
9+
{
10+
"binding": "DB",
11+
"database_name": "unitn-oj",
12+
"database_id": "<PROD_D1_UUID>",
13+
"migrations_dir": "../../frontend/d1/migrations"
14+
}
15+
],
16+
"queues": {
17+
"producers": [
18+
{ "queue": "unitn-oj-submissions", "binding": "QUEUE_SUBMISSIONS" }
19+
]
20+
},
21+
"vars": {
22+
"APP_ENV": "prod"
23+
}
24+
},
25+
"production": {
26+
"d1_databases": [
27+
{
28+
"binding": "DB",
29+
"database_name": "unitn-oj",
30+
"database_id": "<PROD_D1_UUID>",
31+
"migrations_dir": "../../frontend/d1/migrations"
32+
}
33+
],
34+
"queues": {
35+
"producers": [
36+
{ "queue": "unitn-oj-submissions", "binding": "QUEUE_SUBMISSIONS" }
37+
]
38+
},
39+
"vars": {
40+
"APP_ENV": "prod"
41+
}
42+
}
43+
}
4444
}

frontend/wrangler.jsonc

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
{
2-
"name": "unitn-oj-frontend-local",
3-
"compatibility_date": "2025-09-06",
4-
"compatibility_flags": ["nodejs_compat"],
5-
"pages_build_output_dir": ".svelte-kit/cloudflare",
2+
"name": "unitn-oj-frontend-local",
3+
"compatibility_date": "2025-09-06",
4+
"compatibility_flags": ["nodejs_compat"],
5+
"pages_build_output_dir": ".svelte-kit/cloudflare",
66

7-
"dev": {
8-
"ip": "0.0.0.0",
9-
"port": 8080,
10-
"local_protocol": "http"
11-
},
7+
"dev": {
8+
"ip": "0.0.0.0",
9+
"port": 8080,
10+
"local_protocol": "http"
11+
},
1212

13-
"d1_databases": [
14-
{
15-
"binding": "DB",
16-
"database_name": "unitn_oj_local",
17-
"database_id": "LOCAL",
18-
"migrations_dir": "d1/migrations"
19-
}
20-
],
13+
"d1_databases": [
14+
{
15+
"binding": "DB",
16+
"database_name": "unitn_oj_local",
17+
"database_id": "LOCAL",
18+
"migrations_dir": "d1/migrations"
19+
}
20+
],
2121

22-
"queues": {
23-
"producers": [
24-
{
25-
"queue": "unitn-oj-submissions-dev",
26-
"binding": "QUEUE_SUBMISSIONS"
27-
}
28-
]
29-
}
22+
"queues": {
23+
"producers": [
24+
{
25+
"queue": "unitn-oj-submissions-dev",
26+
"binding": "QUEUE_SUBMISSIONS"
27+
}
28+
]
29+
}
3030
}

scripts/update-d1-id.mjs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
1-
import { execSync } from 'node:child_process';
2-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
3-
import { resolve, join } from 'node:path';
4-
import { tmpdir } from 'node:os';
1+
import { execSync } from "node:child_process";
2+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3+
import { tmpdir } from "node:os";
4+
import { join, resolve } from "node:path";
55

66
const ENV = process.argv[2];
7-
if (!ENV || !['dev', 'prod'].includes(ENV)) {
8-
console.error('Usage: node scripts/update-d1-id.mjs <dev|prod>');
9-
process.exit(1);
7+
if (!ENV || !["dev", "prod"].includes(ENV)) {
8+
console.error("Usage: node scripts/update-d1-id.mjs <dev|prod>");
9+
process.exit(1);
1010
}
1111

12-
const TF_DIR = resolve('infra/terraform');
12+
const TF_DIR = resolve("infra/terraform");
1313
const WRANGLER_PATH = resolve(`deploy/${ENV}/wrangler.jsonc`);
1414

1515
function sh(cmd, opts = {}) {
16-
return execSync(cmd, { stdio: ['pipe', 'pipe', 'inherit'], ...opts }).toString().trim();
16+
return execSync(cmd, { stdio: ["pipe", "pipe", "inherit"], ...opts })
17+
.toString()
18+
.trim();
1719
}
1820

1921
try {
20-
sh(`terraform -chdir=${TF_DIR} workspace select ${ENV}`);
21-
22-
const d1Id = sh(`terraform -chdir=${TF_DIR} output -raw d1_db_id`);
23-
if (!d1Id || !/^[0-9a-f-]{36}$/i.test(d1Id)) {
24-
throw new Error(`Invalid d1_db_id: "${d1Id}"`);
25-
}
26-
27-
const src = readFileSync(WRANGLER_PATH, 'utf8');
28-
const updated = src.replace(/("database_id"\s*:\s*")[^"]*(")/g, `$1${d1Id}$2`);
29-
30-
const ts = new Date().toISOString().replace(/[:.]/g, '-');
31-
const backupDir = join(tmpdir(), 'unitn-oj', ENV);
32-
if (!existsSync(backupDir)) mkdirSync(backupDir, { recursive: true });
33-
const backupPath = join(backupDir, `wrangler.jsonc.bak.${ts}`);
34-
35-
writeFileSync(backupPath, src, 'utf8');
36-
writeFileSync(WRANGLER_PATH, updated, 'utf8');
37-
38-
console.log(`[ok] Updated D1 database_id in ${WRANGLER_PATH}`);
39-
console.log(`[ok] Current d1_db_id: ${d1Id}`);
40-
console.log(`[bak] Backup at: ${backupPath}`);
22+
sh(`terraform -chdir=${TF_DIR} workspace select ${ENV}`);
23+
24+
const d1Id = sh(`terraform -chdir=${TF_DIR} output -raw d1_db_id`);
25+
if (!d1Id || !/^[0-9a-f-]{36}$/i.test(d1Id)) {
26+
throw new Error(`Invalid d1_db_id: "${d1Id}"`);
27+
}
28+
29+
const src = readFileSync(WRANGLER_PATH, "utf8");
30+
const updated = src.replace(
31+
/("database_id"\s*:\s*")[^"]*(")/g,
32+
`$1${d1Id}$2`,
33+
);
34+
35+
const ts = new Date().toISOString().replace(/[:.]/g, "-");
36+
const backupDir = join(tmpdir(), "unitn-oj", ENV);
37+
if (!existsSync(backupDir)) mkdirSync(backupDir, { recursive: true });
38+
const backupPath = join(backupDir, `wrangler.jsonc.bak.${ts}`);
39+
40+
writeFileSync(backupPath, src, "utf8");
41+
writeFileSync(WRANGLER_PATH, updated, "utf8");
42+
43+
console.log(`[ok] Updated D1 database_id in ${WRANGLER_PATH}`);
44+
console.log(`[ok] Current d1_db_id: ${d1Id}`);
45+
console.log(`[bak] Backup at: ${backupPath}`);
4146
} catch (e) {
42-
console.error(`[fail] ${e.message}`);
43-
process.exit(1);
47+
console.error(`[fail] ${e.message}`);
48+
process.exit(1);
4449
}

0 commit comments

Comments
 (0)