dev: keep data and sessions across restarts
Assisted-by: Claude Sonnet 5.5 via Claude Code
change yotxvxuyvnommmvylxvmtroxyxskvszr
commit f0fcec4bcfb8628b466e66d8f65bbca79099dea6
author Alpha Chen <alpha@kejadlen.dev>
date
parent 1a2d4ce3
diff --git a/.gitignore b/.gitignore
index 2e274d9..e85fbf4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1 @@
-db/*.db
+db/*.db*
diff --git a/AGENTS.md b/AGENTS.md
index 79a3488..18758de 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -62,7 +62,7 @@ fly.toml           — Fly config for the main demo and PR previews
 | Type check and test | `bundle exec rake` |
 | Run tests | `bundle exec rake test` |
 | Type check | `bundle exec rake steep` |
-| Run dev server | `bundle exec rake dev` (uses `fd \| entr -r rackup demo.ru`) |
+| Run dev server | `bundle exec rake dev` (uses `fd \| entr -r rackup demo.ru`, keeping data in `db/dev.db` and a fixed `SESSION_SECRET`; delete the file to reset) |
 | Refresh Gloss | `bundle exec rake gloss:vendor GLOSS=/path/to/gloss` |
 | Start server | `bundle exec rackup` (behind the proxy) or `bundle exec rackup demo.ru` (stub login) |
 
diff --git a/Rakefile b/Rakefile
index c3cfe1b..25d7e6e 100644
--- a/Rakefile
+++ b/Rakefile
@@ -8,7 +8,14 @@ Minitest::TestTask.create
 
 desc "Start dev server with auto-restart"
 task :dev do
-  sh "fd | entr -r rackup -o localhost demo.ru"
+  # :memory: and a per-process session secret both reset on restart, so
+  # use a file and a fixed secret (64+ bytes, Roda's minimum). db/*.db is
+  # gitignored, so fd skips the file too.
+  env = {
+    "DATABASE_URL" => ENV.fetch("DATABASE_URL", "db/dev.db"),
+    "SESSION_SECRET" => ENV.fetch("SESSION_SECRET", "dev-only-secret-" + "x" * 64),
+  }
+  sh(env, "fd | entr -r rackup -o localhost demo.ru")
 end
 
 desc "Type check lib against the RBS comments in it"