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 |
@@ -43,9 +43,10 @@ services:
|
||||
web:
|
||||
build: ./web
|
||||
environment:
|
||||
PUBLIC_MEILISEARCH_URL: http://localhost:7700
|
||||
PUBLIC_MEILISEARCH_API_TOKEN:
|
||||
PUBLIC_POCKETBASE_URL: http://127.0.0.1:8090
|
||||
ORIGIN: http://localhost:8080
|
||||
PUBLIC_MEILISEARCH_URL: http://search:7700
|
||||
PUBLIC_MEILISEARCH_API_TOKEN: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcGlLZXlVaWQiOiIyMjk3NDg3Yy0zMjFlLTQ5MmEtYmRiNS1iZmYwZGYzZjc2NTYiLCJzZWFyY2hSdWxlcyI6eyJ0cmFpbHMiOnsiZmlsdGVyIjoicHVibGljPXRydWUifSwiY2l0aWVzNTAwIjp7fX0sImV4cCI6bnVsbH0.CuIlkiWAec8TGyZI5X37JTjQvcnvFAFZAuA4xpbXJ8o
|
||||
PUBLIC_POCKETBASE_URL: http://db:8090
|
||||
ports:
|
||||
- "8080:3000"
|
||||
networks:
|
||||
|
||||
Reference in New Issue
Block a user