Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Merge release channels into the account database and rename it instance.db

3047be84e9bce79372051c09854ce9b05f12a9bf · Keenan Nemetz · 17d ago · parent 262e516e

Merge release channels into the account database and rename it instance.db

The instance keeps four SQLite files instead of five. Release channels were in a
file of their own only because they were added beside the derived index; they are
authoritative source state, like the roster, so they belong in the file an
operator restores. Nothing has to be migrated: channels.db never shipped in a
release, so only an instance tracking main can have one.

The account database is now data/instance.db. The package comments already called
it that; only the filename disagreed.

Moving an existing instance is an operator step, by decision: a rename under a
live server can lose the -wal file a hook subprocess still has open. Vole refuses
to start while data/users.db is still in place, and says what to move, rather
than creating an empty database beside it that would look like a successful
upgrade.

The list of databases now lives in Config.Databases, which TightenSecrets, the
hook plumbing, and the admin commands read, so a missed -wal file is no longer a
nine-file change. `vole admin account backup <path>` becomes `vole admin db
backup <dir>` and covers every authoritative database; `db list` and `db check`
answer what to back up and whether it is intact.

forge/instance_test.go +94

@@ -7,8 +7,10 @@ import (
7 7 "path/filepath"
8 8 "strings"
9 9 "testing"
10 "time"
10 11
11 12 "golang.org/x/crypto/ssh"
13 "rodent.software/vole/forge/channel"
12 14 "rodent.software/vole/forge/config"
13 15 )
14 16
@@ -148,3 +150,95 @@ func TestOpenRefusesASymlinkedAuditLog(t *testing.T) {
148 150 t.Fatal("an instance opened with a symlinked audit log")
149 151 }
150 152 }
153
154 // TestChannelsShareTheInstanceDatabase is the merge: a channel is written to
155 // instance.db, survives a restart, and creates no channels.db beside it.
156 func TestChannelsShareTheInstanceDatabase(t *testing.T) {
157 t.Parallel()
158 dir := t.TempDir()
159 root, err := Init(dir)
160 if err != nil {
161 t.Fatalf("init: %v", err)
162 }
163 cfg, err := config.Load(filepath.Join(root, "vole.toml"))
164 if err != nil {
165 t.Fatal(err)
166 }
167 inst, err := Open(cfg, "vole")
168 if err != nil {
169 t.Fatalf("open: %v", err)
170 }
171 ch := channel.Channel{
172 Name: "stable",
173 Release: "v1.0.0",
174 ReleaseObject: strings.Repeat("a", 40),
175 UpdatedBy: "keenan",
176 UpdatedAt: time.Date(2026, 11, 14, 12, 0, 0, 0, time.UTC),
177 }
178 if err := inst.Channels.Set("repo1", ch); err != nil {
179 t.Fatalf("set channel: %v", err)
180 }
181 if err := inst.Close(); err != nil {
182 t.Fatalf("close: %v", err)
183 }
184 if _, err := os.Stat(cfg.LegacyChannelsDB()); err == nil {
185 t.Fatal("channels.db was created; channels belong in instance.db")
186 }
187 again, err := Open(cfg, "vole")
188 if err != nil {
189 t.Fatalf("reopen: %v", err)
190 }
191 defer again.Close()
192 got, ok, err := again.Channels.Get("repo1", "stable")
193 if err != nil || !ok {
194 t.Fatalf("channel after restart = %v, %v", ok, err)
195 }
196 if got.Release != ch.Release || got.ReleaseObject != ch.ReleaseObject {
197 t.Fatalf("channel after restart = %+v", got)
198 }
199 }
200
201 // TestRefusesALegacyDataLayout: the move to instance.db is an operator step, so
202 // the two wrong layouts must fail loudly instead of starting a second roster or
203 // quietly ignoring the channel rows left in channels.db.
204 func TestRefusesALegacyDataLayout(t *testing.T) {
205 t.Parallel()
206 dir := t.TempDir()
207 root, err := Init(dir)
208 if err != nil {
209 t.Fatalf("init: %v", err)
210 }
211 cfg, err := config.Load(filepath.Join(root, "vole.toml"))
212 if err != nil {
213 t.Fatal(err)
214 }
215 if err := os.Rename(cfg.InstanceDB(), cfg.LegacyInstanceDB()); err != nil {
216 t.Fatal(err)
217 }
218 if inst, err := Open(cfg, "vole"); err == nil {
219 inst.Close()
220 t.Fatal("opened an instance whose accounts are still in users.db")
221 } else if !strings.Contains(err.Error(), "instance.db") {
222 t.Fatalf("error does not name the file to move: %v", err)
223 }
224 // init is an upgrade path too, and must not create an empty instance.db
225 // beside the old file.
226 if _, err := InitAt(cfg.Path); err == nil {
227 t.Fatal("init created a second account database")
228 } else if !strings.Contains(err.Error(), "users.db") {
229 t.Fatalf("init error does not name the old file: %v", err)
230 }
231 if err := os.Rename(cfg.LegacyInstanceDB(), cfg.InstanceDB()); err != nil {
232 t.Fatal(err)
233 }
234
235 if err := os.WriteFile(cfg.LegacyChannelsDB(), nil, 0o600); err != nil {
236 t.Fatal(err)
237 }
238 if inst, err := Open(cfg, "vole"); err == nil {
239 inst.Close()
240 t.Fatal("opened an instance with a stray channels.db")
241 } else if !strings.Contains(err.Error(), "channels.db") {
242 t.Fatalf("error does not name the stray file: %v", err)
243 }
244 }