1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-02-11 04:46:31 +02:00

Merge branch 'master' into develop

This commit is contained in:
Gani Georgiev 2023-05-25 21:00:45 +03:00
commit 3be5875ea9
2 changed files with 26 additions and 5 deletions

View File

@ -13,7 +13,7 @@ func initPragmas(db *dbx.DB) error {
PRAGMA journal_mode = WAL; PRAGMA journal_mode = WAL;
PRAGMA journal_size_limit = 200000000; PRAGMA journal_size_limit = 200000000;
PRAGMA synchronous = NORMAL; PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = TRUE; PRAGMA foreign_keys = ON;
`).Execute() `).Execute()
return err return err

View File

@ -6,6 +6,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos" "github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/models" "github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/models/schema" "github.com/pocketbase/pocketbase/models/schema"
@ -166,9 +167,9 @@ func TestDeleteCollection(t *testing.T) {
app, _ := tests.NewTestApp() app, _ := tests.NewTestApp()
defer app.Cleanup() defer app.Cleanup()
colEmpty := &models.Collection{} colUnsaved := &models.Collection{}
colAuth, err := app.Dao().FindCollectionByNameOrId("clients") colAuth, err := app.Dao().FindCollectionByNameOrId("users")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -187,6 +188,11 @@ func TestDeleteCollection(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
colBase, err := app.Dao().FindCollectionByNameOrId("demo1")
if err != nil {
t.Fatal(err)
}
colView1, err := app.Dao().FindCollectionByNameOrId("view1") colView1, err := app.Dao().FindCollectionByNameOrId("view1")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -201,12 +207,14 @@ func TestDeleteCollection(t *testing.T) {
model *models.Collection model *models.Collection
expectError bool expectError bool
}{ }{
{colEmpty, true}, {colUnsaved, true},
{colAuth, false},
{colReferenced, true}, {colReferenced, true},
{colSystem, true}, {colSystem, true},
{colView1, true}, // view2 depend on it {colView1, true}, // view2 depend on it
{colView2, false}, {colView2, false},
{colView1, false}, // no longer has dependent collections
{colBase, false},
{colAuth, false}, // should delete also its related external auths
} }
for i, s := range scenarios { for i, s := range scenarios {
@ -225,6 +233,19 @@ func TestDeleteCollection(t *testing.T) {
if app.Dao().HasTable(s.model.Name) { if app.Dao().HasTable(s.model.Name) {
t.Errorf("[%d] Expected table/view %s to be deleted", i, s.model.Name) t.Errorf("[%d] Expected table/view %s to be deleted", i, s.model.Name)
} }
// check if the external auths were deleted
if s.model.IsAuth() {
var total int
err := app.Dao().ExternalAuthQuery().
Select("count(*)").
AndWhere(dbx.HashExp{"collectionId": s.model.Id}).
Row(&total)
if err != nil || total > 0 {
t.Fatalf("[%d] Expected external auths to be deleted, got %v (%v)", i, total, err)
}
}
} }
} }