adds db seed command
This commit is contained in:
@@ -13,6 +13,7 @@ COPY *.go ./
|
||||
|
||||
RUN go build -o /pocketbase
|
||||
RUN /pocketbase migrate
|
||||
RUN /pocketbase seed
|
||||
|
||||
ENV MEILI_URL=http://localhost:7700
|
||||
ENV MEILI_MASTER_KEY=
|
||||
|
||||
24
db/main.go
24
db/main.go
@@ -4,12 +4,16 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/meilisearch/meilisearch-go"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/forms"
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
_ "pocketbase/migrations"
|
||||
)
|
||||
@@ -51,6 +55,26 @@ func main() {
|
||||
Automigrate: true,
|
||||
})
|
||||
|
||||
app.RootCmd.AddCommand(&cobra.Command{
|
||||
Use: "seed",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
collection, _ := app.Dao().FindCollectionByNameOrId("categories")
|
||||
|
||||
categories := []string{"Hiking", "Walking", "Climbing", "Skiing", "Canoeing", "Biking"}
|
||||
for _, element := range categories {
|
||||
record := models.NewRecord(collection)
|
||||
form := forms.NewRecordUpsert(app, record)
|
||||
form.LoadData(map[string]any{
|
||||
"name": element,
|
||||
})
|
||||
f, _ := filesystem.NewFileFromPath("migrations/initial_data/" + strings.ToLower(element) + ".jpg")
|
||||
form.AddFiles("img", f)
|
||||
form.Submit()
|
||||
}
|
||||
|
||||
},
|
||||
})
|
||||
|
||||
client := meilisearch.NewClient(meilisearch.ClientConfig{
|
||||
Host: os.Getenv("MEILI_URL"),
|
||||
APIKey: os.Getenv("MEILI_MASTER_KEY"),
|
||||
|
||||
BIN
db/migrations/initial_data/biking.jpg
Normal file
BIN
db/migrations/initial_data/biking.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 573 KiB |
BIN
db/migrations/initial_data/canoeing.jpg
Normal file
BIN
db/migrations/initial_data/canoeing.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
BIN
db/migrations/initial_data/climbing.jpg
Normal file
BIN
db/migrations/initial_data/climbing.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 664 KiB |
BIN
db/migrations/initial_data/hiking.jpg
Normal file
BIN
db/migrations/initial_data/hiking.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 846 KiB |
BIN
db/migrations/initial_data/skiing.jpg
Normal file
BIN
db/migrations/initial_data/skiing.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 453 KiB |
BIN
db/migrations/initial_data/walking.jpg
Normal file
BIN
db/migrations/initial_data/walking.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 432 KiB |
Reference in New Issue
Block a user