Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix(platform): align D1 binding with DB configuration

HoshinoSuzumiBot1a3fe04e4f9f
diff --git a/.github/workflows/deploy-saas.yml b/.github/workflows/deploy-saas.yml
index 12ad5b0a..dbea1ca3 100644
--- a/.github/workflows/deploy-saas.yml
+++ b/.github/workflows/deploy-saas.yml
@@ -155,7 +155,7 @@ jobs:
const databaseId = process.env.PLATFORM_D1_DATABASE_ID
if (databaseId) {
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(databaseId)) throw new Error('Invalid platform D1 database ID')
- const binding = { binding: 'PLATFORM_DB', database_name: `chronoframe-platform-${process.env.DEPLOY_ENVIRONMENT}`, database_id: databaseId }
+ const binding = { binding: 'DB', database_name: 'chronoframe-saas', database_id: databaseId }
if (process.env.DEPLOY_ENVIRONMENT === 'staging') {
config.previews.d1_databases = [binding]
delete config.d1_databases
diff --git a/apps/cloud/.env.example b/apps/cloud/.env.example
index 0883cdc8..09811880 100644
--- a/apps/cloud/.env.example
+++ b/apps/cloud/.env.example
@@ -6,6 +6,6 @@
# NUXT_PLATFORM_SECRET=use-an-independent-random-secret-of-at-least-32-bytes
# EMAIL is a Cloudflare Email Sending send_email binding, not an API key.
-# PLATFORM_DB is a D1 binding, not a string environment variable.
+# DB is a D1 binding, not a string environment variable.
# The deploy workflow reads PLATFORM_EMAIL_FROM and PLATFORM_D1_DATABASE_ID
# from the selected GitHub Environment variables. No mail provider key is needed.
diff --git a/apps/cloud/server/api/auth/status.get.ts b/apps/cloud/server/api/auth/status.get.ts
index 003b0d6e..245072f7 100644
--- a/apps/cloud/server/api/auth/status.get.ts
+++ b/apps/cloud/server/api/auth/status.get.ts
@@ -13,7 +13,7 @@ export default defineEventHandler(async (event) => {
config.emailFrom,
) &&
config.secret.length >= 32 &&
- !!event.context.cloudflare?.env?.PLATFORM_DB
+ !!event.context.cloudflare?.env?.DB
if (!configured) return { enabled: false }
try {
await platformDatabase(event)
diff --git a/apps/platform.runtime.ts b/apps/platform.runtime.ts
index b85f41ee..c93adf85 100644
--- a/apps/platform.runtime.ts
+++ b/apps/platform.runtime.ts
@@ -19,9 +19,7 @@ import { createEmailCodeCrypto } from './platform-crypto'
export const PLATFORM_COOKIE = '__Host-chronoframe-session'
export function platformDatabase(event: H3Event): PlatformD1 {
- const db = event.context.cloudflare?.env?.PLATFORM_DB as
- | PlatformD1
- | undefined
+ const db = event.context.cloudflare?.env?.DB as PlatformD1 | undefined
if (!db?.prepare || !db.batch)
throw createError({
statusCode: 503,
diff --git a/packages/platform/README.md b/packages/platform/README.md
index 64c3388e..559e8156 100644
--- a/packages/platform/README.md
+++ b/packages/platform/README.md
@@ -12,7 +12,7 @@ Do not run these migrations on the Self-hosted database.
Set the GitHub Environment variable `PLATFORM_D1_DATABASE_ID` in `saas-staging`
and `saas-production` to their respective database IDs. The deployment workflow
-binds `PLATFORM_DB` at the top level for production and under `previews` for
+binds `DB` at the top level for production and under `previews` for
staging. The two IDs must identify separate databases. No D1 database or remote
migration is automatically created/applied by this change. The deployment token
needs D1 access once the binding is enabled.
diff --git a/tests/platform-email-d1.test.ts b/tests/platform-email-d1.test.ts
index 73d50f39..6ebc6e6a 100644
--- a/tests/platform-email-d1.test.ts
+++ b/tests/platform-email-d1.test.ts
@@ -245,11 +245,11 @@ test('actual workerd D1 serializes reservations and one-time verification', asyn
modules: true,
script: 'export default { fetch() { return new Response("ok") } }',
compatibilityDate: '2026-10-22',
- d1Databases: { PLATFORM_DB: 'platform-test' },
+ d1Databases: { DB: 'platform-test' },
}),
)
try {
- const db: PlatformD1 = await mf.getD1Database('PLATFORM_DB')
+ const db: PlatformD1 = await mf.getD1Database('DB')
const migration = await readFile(
new URL(
'../packages/platform/migrations/0001_platform.sql',