You've already forked pocketbase
mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-11-06 09:29:19 +02:00
(no tests) collection indexes scaffoldings
This commit is contained in:
@@ -52,6 +52,7 @@ func init() {
|
||||
[[type]] TEXT DEFAULT "base" NOT NULL,
|
||||
[[name]] TEXT UNIQUE NOT NULL,
|
||||
[[schema]] JSON DEFAULT "[]" NOT NULL,
|
||||
[[indexes]] JSON DEFAULT "[]" NOT NULL,
|
||||
[[listRule]] TEXT DEFAULT NULL,
|
||||
[[viewRule]] TEXT DEFAULT NULL,
|
||||
[[createRule]] TEXT DEFAULT NULL,
|
||||
|
||||
34
migrations/1678470811_add_indexes_column.go
Normal file
34
migrations/1678470811_add_indexes_column.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/dbx"
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
)
|
||||
|
||||
// Adds _collections indexes column (if not already).
|
||||
func init() {
|
||||
AppMigrations.Register(func(db dbx.Builder) error {
|
||||
dao := daos.New(db)
|
||||
|
||||
cols, err := dao.GetTableColumns("_collections")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, col := range cols {
|
||||
if col == "indexes" {
|
||||
return nil // already existing (probably via the init migration)
|
||||
}
|
||||
}
|
||||
|
||||
_, err = db.AddColumn("_collections", "indexes", `JSON DEFAULT "[]" NOT NULL`).Execute()
|
||||
|
||||
// @todo populate existing indexes...
|
||||
|
||||
return err
|
||||
}, func(db dbx.Builder) error {
|
||||
_, err := db.DropColumn("_collections", "indexes").Execute()
|
||||
|
||||
return err
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user