mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 01:05:32 +00:00
Basic collection setup
This commit is contained in:
@@ -93,7 +93,7 @@ func entriesFields(collection *core.Collection, app core.App) *core.FieldsList {
|
||||
func entriesIndexes(collection *core.Collection) {
|
||||
addMusenalmIDIndex(collection)
|
||||
addIndex(collection, "preferredtitle", false)
|
||||
addIndex(collection, "varianttile", false)
|
||||
addIndex(collection, "varianttitle", false)
|
||||
addIndex(collection, "paralleltitle", false)
|
||||
addIndex(collection, "title_statement", false)
|
||||
addIndex(collection, "subtitle_statement", false)
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
// add up queries...
|
||||
|
||||
return nil
|
||||
}, func(app core.App) error {
|
||||
// add down queries...
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -1,18 +1,27 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/models"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
// add up queries...
|
||||
collection, err := basicRelationCollection(app, models.ENTRIES_TABLE, models.SERIES_TABLE, models.SERIES_RELATIONS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
collection.Fields.Add(&core.TextField{Name: "numbering", Required: false, Presentable: true})
|
||||
|
||||
return app.Save(collection)
|
||||
}, func(app core.App) error {
|
||||
// add down queries...
|
||||
collection, err := app.FindCollectionByNameOrId(relationTableName(models.ENTRIES_TABLE, models.SERIES_TABLE))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
return app.Delete(collection)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -10,33 +10,33 @@ import (
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
items := itemsTable()
|
||||
fields := itemsFields(items, app)
|
||||
partials := partialsTable()
|
||||
fields := partialsFields(app)
|
||||
if fields == nil {
|
||||
return errors.New("Could not find places collection")
|
||||
}
|
||||
|
||||
items.Fields = *fields
|
||||
itemsIndexes(items)
|
||||
partials.Fields = *fields
|
||||
partialsIndexes(partials)
|
||||
|
||||
return app.Save(items)
|
||||
return app.Save(partials)
|
||||
}, func(app core.App) error {
|
||||
items, err := app.FindCollectionByNameOrId(models.ITEMS_TABLE)
|
||||
partials, err := app.FindCollectionByNameOrId(models.PARTIALS_TABLE)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return app.Delete(items)
|
||||
return app.Delete(partials)
|
||||
})
|
||||
}
|
||||
|
||||
func itemsTable() *core.Collection {
|
||||
collection := core.NewBaseCollection(models.ITEMS_TABLE)
|
||||
func partialsTable() *core.Collection {
|
||||
collection := core.NewBaseCollection(models.PARTIALS_TABLE)
|
||||
setBasicPublicRules(collection)
|
||||
return collection
|
||||
}
|
||||
|
||||
func itemsFields(collection *core.Collection, app core.App) *core.FieldsList {
|
||||
func partialsFields(app core.App) *core.FieldsList {
|
||||
entries, err := app.FindCollectionByNameOrId(models.ENTRIES_TABLE)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -74,10 +74,10 @@ func itemsFields(collection *core.Collection, app core.App) *core.FieldsList {
|
||||
// Musenalm specific data
|
||||
&core.SelectField{Name: "musenalm_type", Required: false, Values: models.MUSENALM_TYPE_VALUES, MaxSelect: len(models.MUSENALM_TYPE_VALUES)},
|
||||
&core.SelectField{Name: "pagination", Required: false, Values: models.MUSENALM_PAGINATION_VALUES, MaxSelect: len(models.MUSENALM_PAGINATION_VALUES)},
|
||||
&core.FileField{Name: "scans", Required: false, MaxSize: 100 * 1024 * 1024, MaxSelect: 100, MimeTypes: models.MUSENALM_MIME_TYPES, Thumbs: []string{"0x300", "0x500", "0x1000", "300x0", "500x0", "1000x0"}}, // 100 MB
|
||||
&core.FileField{Name: "scans", Required: false, MaxSize: 100 * 1024 * 1024, MaxSelect: 100, MimeTypes: models.MUSENALM_MIME_TYPES, Thumbs: []string{"0x300", "0x500", "0x1000", "300x0", "500x0", "1000x0"}}, // 100 MB a file
|
||||
|
||||
// Band:
|
||||
&core.NumberField{Name: "running_number", Required: false},
|
||||
&core.NumberField{Name: "numbering", Required: false},
|
||||
&core.RelationField{Name: "entries", Required: true, CollectionId: entries.Id, CascadeDelete: false, MaxSelect: 1, MinSelect: 1},
|
||||
)
|
||||
|
||||
@@ -88,10 +88,10 @@ func itemsFields(collection *core.Collection, app core.App) *core.FieldsList {
|
||||
return &fields
|
||||
}
|
||||
|
||||
func itemsIndexes(collection *core.Collection) {
|
||||
func partialsIndexes(collection *core.Collection) {
|
||||
addMusenalmIDIndex(collection)
|
||||
addIndex(collection, "preferredtitle", false)
|
||||
addIndex(collection, "varianttile", false)
|
||||
addIndex(collection, "varianttitle", false)
|
||||
addIndex(collection, "paralleltitle", false)
|
||||
addIndex(collection, "title_statement", false)
|
||||
addIndex(collection, "subtitle_statement", false)
|
||||
@@ -1,18 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
// add up queries...
|
||||
|
||||
return nil
|
||||
}, func(app core.App) error {
|
||||
// add down queries...
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
25
migrations/1738951458_r_partials_agents.go
Normal file
25
migrations/1738951458_r_partials_agents.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/models"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collections, err := basicRelationCollection(app, models.PARTIALS_TABLE, models.AGENTS_TABLE, models.AGENT_RELATIONS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collections)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId(relationTableName(models.PARTIALS_TABLE, models.AGENTS_TABLE))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return app.Delete(collection)
|
||||
})
|
||||
}
|
||||
25
migrations/1738952826_r_entries_agents.go
Normal file
25
migrations/1738952826_r_entries_agents.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/models"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
m "github.com/pocketbase/pocketbase/migrations"
|
||||
)
|
||||
|
||||
func init() {
|
||||
m.Register(func(app core.App) error {
|
||||
collections, err := basicRelationCollection(app, models.ENTRIES_TABLE, models.AGENTS_TABLE, models.AGENT_RELATIONS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Save(collections)
|
||||
}, func(app core.App) error {
|
||||
collection, err := app.FindCollectionByNameOrId(relationTableName(models.ENTRIES_TABLE, models.AGENTS_TABLE))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return app.Delete(collection)
|
||||
})
|
||||
}
|
||||
@@ -8,12 +8,6 @@ import (
|
||||
|
||||
func setBasicPublicRules(collection *core.Collection) {
|
||||
collection.ViewRule = types.Pointer("@request.auth.id != ''")
|
||||
collection.CreateRule = types.Pointer("@request.auth.id != '' && @request.body.user = @request.auth.id")
|
||||
collection.UpdateRule = types.Pointer(`
|
||||
@request.auth.id != '' &&
|
||||
user = @request.auth.id &&
|
||||
(@request.body.user:isset = false || @request.body.user = @request.auth.id)
|
||||
`)
|
||||
}
|
||||
|
||||
func setMusenalmIDField(fieldlist *core.FieldsList) {
|
||||
@@ -38,11 +32,7 @@ func addIndex(collection *core.Collection, field string, unique bool) {
|
||||
collection.AddIndex("idx_"+name+"_"+field, unique, field, "")
|
||||
}
|
||||
|
||||
func createAgentRelationsTable(app core.App, sourcetablename, targettablename, tablename string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func basicRelationFields(app core.App, sourcetablename, targettablename string, relations []string) (core.FieldsList, error) {
|
||||
func basicRelationCollection(app core.App, sourcetablename, targettablename string, relations []string) (*core.Collection, error) {
|
||||
stable, err := app.FindCollectionByNameOrId(sourcetablename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -53,11 +43,27 @@ func basicRelationFields(app core.App, sourcetablename, targettablename string,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
collection := core.NewBaseCollection(relationTableName(stable.Name, ttable.Name))
|
||||
setBasicPublicRules(collection)
|
||||
|
||||
fields := core.NewFieldsList(
|
||||
&core.RelationField{Name: stable.Name, Required: true, CollectionId: stable.Id},
|
||||
&core.RelationField{Name: ttable.Name, Required: true, CollectionId: ttable.Id},
|
||||
&core.TextField{Name: "relation_type", Required: true},
|
||||
&core.RelationField{Name: stable.Name, Required: true, CollectionId: stable.Id, MinSelect: 1, MaxSelect: 1},
|
||||
&core.RelationField{Name: ttable.Name, Required: true, CollectionId: ttable.Id, MinSelect: 1, MaxSelect: 1},
|
||||
&core.SelectField{Name: "relation_type", Required: true, Values: relations, MaxSelect: 1},
|
||||
&core.BoolField{Name: "conjecture", Required: false},
|
||||
&core.BoolField{Name: "uncertain", Required: false},
|
||||
)
|
||||
|
||||
return fields, nil
|
||||
setNotesAndAnnotationsField(&fields)
|
||||
|
||||
collection.Fields = fields
|
||||
addIndex(collection, stable.Name, false)
|
||||
addIndex(collection, ttable.Name, false)
|
||||
addIndex(collection, "relation_type", false)
|
||||
|
||||
return collection, nil
|
||||
}
|
||||
|
||||
func relationTableName(collection1, collection2 string) string {
|
||||
return "R_" + collection1 + "_" + collection2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user