feat: keep the materials index in sync and add bm:materials-reindex

- the materials admin syncs after create and update and removes after
  delete, once the save transaction commits (UseMaterialIndex, set at Boot)
- POST and PUT /api/v1/bm/materials sync after the transaction, DELETE
  removes the document (its statement has no primary key, so no callback)
- bm:materials-reindex [--fresh] [--if-configured] ensures the index and
  syncs every material; it refuses without an engine and runs nightly
  at 04:15 with --if-configured
- TestMaterialSearchAgainstDatabase (Postgres) is written for the final
  verification phase
This commit is contained in:
Jakub Zych
2026-11-08 19:50:50 +01:00
parent 4ffce6e6ac
commit ffd19342b2
12 changed files with 624 additions and 12 deletions

View File

@@ -136,13 +136,19 @@ func testDatabase(t *testing.T) (*sql.DB, string) {
// migrated activates golem15.user and jz.bm, migrates a fresh database and
// publishes it on the application, as serve does.
func migrated(t *testing.T) (*backpack.App, []party.Plugin, *gorm.DB) {
t.Helper()
return migratedWith(t)
}
// migratedWith is migrated with env added to the application config.
func migratedWith(t *testing.T, env ...string) (*backpack.App, []party.Plugin, *gorm.DB) {
t.Helper()
sqlDB, _ := testDatabase(t)
gdb, err := lagoon.Use(t.Context(), sqlDB)
if err != nil {
t.Fatalf("lagoon.Use: %v", err)
}
app := backpack.New(testConfig(t))
app := backpack.New(testConfig(t, env...))
plugins := activate(t, app)
if err := lagoon.Migrate(gdb, plugins); err != nil {
t.Fatalf("lagoon.Migrate: %v", err)