feat: add reactions (#1074)

This commit is contained in:
Jonas Plum
2024-07-20 06:39:02 +02:00
committed by GitHub
parent 82ad50d228
commit e2c8f1d223
78 changed files with 3270 additions and 257 deletions

View File

@@ -11,15 +11,15 @@ import (
)
const (
TimelineCollectionName = "timeline"
CommentCollectionName = "comments"
fileCollectionName = "files"
FeatureCollectionName = "features"
LinkCollectionName = "links"
TaskCollectionName = "tasks"
TicketCollectionName = "tickets"
TimelineCollectionName = "timeline"
TypeCollectionName = "types"
WebhookCollectionName = "webhooks"
FeatureCollectionName = "features"
fileCollectionName = "files"
UserCollectionName = "_pb_users_auth_"
)
@@ -138,14 +138,14 @@ func internalCollection(c *models.Collection) *models.Collection {
func collectionsDown(db dbx.Builder) error {
collections := []string{
TicketCollectionName,
TypeCollectionName,
fileCollectionName,
LinkCollectionName,
TaskCollectionName,
CommentCollectionName,
TimelineCollectionName,
FeatureCollectionName,
TicketCollectionName,
TypeCollectionName,
}
dao := daos.New(db)

40
migrations/5_reactions.go Normal file
View File

@@ -0,0 +1,40 @@
package migrations
import (
"fmt"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/models/schema"
)
const ReactionCollectionName = "reactions"
func reactionsUp(db dbx.Builder) error {
triggers := []string{"webhook", "hook"}
reactions := []string{"python", "webhook"}
return daos.New(db).SaveCollection(internalCollection(&models.Collection{
Name: ReactionCollectionName,
Type: models.CollectionTypeBase,
Schema: schema.NewSchema(
&schema.SchemaField{Name: "name", Type: schema.FieldTypeText, Required: true},
&schema.SchemaField{Name: "trigger", Type: schema.FieldTypeSelect, Required: true, Options: &schema.SelectOptions{MaxSelect: 1, Values: triggers}},
&schema.SchemaField{Name: "triggerdata", Type: schema.FieldTypeJson, Required: true},
&schema.SchemaField{Name: "action", Type: schema.FieldTypeSelect, Required: true, Options: &schema.SelectOptions{MaxSelect: 1, Values: reactions}},
&schema.SchemaField{Name: "actiondata", Type: schema.FieldTypeJson, Required: true},
),
}))
}
func reactionsDown(db dbx.Builder) error {
dao := daos.New(db)
id, err := dao.FindCollectionByNameOrId(ReactionCollectionName)
if err != nil {
return fmt.Errorf("failed to find collection %s: %w", ReactionCollectionName, err)
}
return dao.DeleteCollection(id)
}

View File

@@ -9,4 +9,5 @@ func Register() {
migrations.Register(collectionsUp, collectionsDown, "1700000001_collections.go")
migrations.Register(defaultDataUp, nil, "1700000003_defaultdata.go")
migrations.Register(viewsUp, viewsDown, "1700000004_views.go")
migrations.Register(reactionsUp, reactionsDown, "1700000005_reactions.go")
}