Merge pull request #321 from goteo/feat/d1-db-setup

[feat] D1 db Setup for local using fake SQLite db
This commit is contained in:
2026-06-26 17:11:03 +02:00
committed by GitHub
7 changed files with 1769 additions and 1539 deletions
+4
View File
@@ -32,6 +32,10 @@ PUBLIC_FACEBOOK_APP_ID=""
# https://developers.cloudflare.com/workers/configuration/environment-variables/
CLOUDFLARE_INCLUDE_PROCESS_ENV="true"
# D1 local database
# Force Miniflare to use a local SQLite file for D1 instead of connecting to remote
CLOUDFLARE_D1_URLS='{"goteo-db": "file:./.wrangler/d1/goteo-db.sqlite"}'
# HTTP Basic auth
# Set this to "true" in order to add a Basic auth layer on top of the application
# This is not a replacement for OAuth
+15
View File
@@ -0,0 +1,15 @@
-- Persistent sessions table for auth
CREATE TABLE IF NOT EXISTS sessions (
id TEXT PRIMARY KEY,
token_type TEXT NOT NULL DEFAULT 'Bearer',
scope TEXT,
expires_at INTEGER NOT NULL,
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch()),
user_id TEXT,
user_email TEXT,
user_name TEXT
);
CREATE INDEX IF NOT EXISTS idx_sessions_expires_at ON sessions(expires_at);
CREATE INDEX IF NOT EXISTS idx_sessions_user_id ON sessions(user_id);
+2
View File
@@ -0,0 +1,2 @@
-- Seed data for local development
-- Apply with: 'npx wrangler d1 execute goteo-db --local --file=./db/seed.sql' or just 'pnpm db:seed'
Vendored
+9
View File
@@ -1,4 +1,5 @@
/// <reference types="astro/client" />
/// <reference types="@cloudflare/workers-types" />
declare namespace App {
interface Locals {
@@ -23,5 +24,13 @@ declare namespace App {
* The detected session.
*/
session: import("./src/auth/types").Session | undefined;
/**
* Cloudflare runtime bindings, including D1.
* Available in server mode thanks to `@astrojs/cloudflare`.
*/
runtime: import("@astrojs/cloudflare").AdvancedRuntime<{
DB: D1Database;
}>;
}
}
+3
View File
@@ -10,6 +10,8 @@
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"cypress:verify": "cypress verify",
"db:migrate": "wrangler d1 migrations apply goteo-db --local",
"db:seed": "wrangler d1 execute goteo-db --local --file=./db/seed.sql",
"dev": "astro dev",
"dev:worker": "npx astro build && npx wrangler dev --port 4321 --ip 0.0.0.0",
"format": "eslint --fix . && prettier --write .",
@@ -60,6 +62,7 @@
"zod": "^4.4.3"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20260615.1",
"@eslint/js": "^9.39.4",
"@hey-api/openapi-ts": "^0.69.2",
"@storybook/addon-a11y": "^10.4.1",
+1730 -1539
View File
File diff suppressed because it is too large Load Diff
+6
View File
@@ -5,6 +5,12 @@ compatibility_flags = ["nodejs_compat"]
workers_dev = false
keep_vars = true
[[d1_databases]]
binding = "DB"
database_name = "goteo-db"
database_id = "00000000-0000-0000-0000-000000000000"
migrations_dir = "db/migrations"
[assets]
binding = "ASSETS"
directory = "./dist"