mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 17:25: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) {
|
func entriesIndexes(collection *core.Collection) {
|
||||||
addMusenalmIDIndex(collection)
|
addMusenalmIDIndex(collection)
|
||||||
addIndex(collection, "preferredtitle", false)
|
addIndex(collection, "preferredtitle", false)
|
||||||
addIndex(collection, "varianttile", false)
|
addIndex(collection, "varianttitle", false)
|
||||||
addIndex(collection, "paralleltitle", false)
|
addIndex(collection, "paralleltitle", false)
|
||||||
addIndex(collection, "title_statement", false)
|
addIndex(collection, "title_statement", false)
|
||||||
addIndex(collection, "subtitle_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
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/musenalm/models"
|
||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
m "github.com/pocketbase/pocketbase/migrations"
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
m.Register(func(app core.App) error {
|
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 {
|
}, 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() {
|
func init() {
|
||||||
m.Register(func(app core.App) error {
|
m.Register(func(app core.App) error {
|
||||||
items := itemsTable()
|
partials := partialsTable()
|
||||||
fields := itemsFields(items, app)
|
fields := partialsFields(app)
|
||||||
if fields == nil {
|
if fields == nil {
|
||||||
return errors.New("Could not find places collection")
|
return errors.New("Could not find places collection")
|
||||||
}
|
}
|
||||||
|
|
||||||
items.Fields = *fields
|
partials.Fields = *fields
|
||||||
itemsIndexes(items)
|
partialsIndexes(partials)
|
||||||
|
|
||||||
return app.Save(items)
|
return app.Save(partials)
|
||||||
}, func(app core.App) error {
|
}, func(app core.App) error {
|
||||||
items, err := app.FindCollectionByNameOrId(models.ITEMS_TABLE)
|
partials, err := app.FindCollectionByNameOrId(models.PARTIALS_TABLE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return app.Delete(items)
|
return app.Delete(partials)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func itemsTable() *core.Collection {
|
func partialsTable() *core.Collection {
|
||||||
collection := core.NewBaseCollection(models.ITEMS_TABLE)
|
collection := core.NewBaseCollection(models.PARTIALS_TABLE)
|
||||||
setBasicPublicRules(collection)
|
setBasicPublicRules(collection)
|
||||||
return 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)
|
entries, err := app.FindCollectionByNameOrId(models.ENTRIES_TABLE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -74,10 +74,10 @@ func itemsFields(collection *core.Collection, app core.App) *core.FieldsList {
|
|||||||
// Musenalm specific data
|
// Musenalm specific data
|
||||||
&core.SelectField{Name: "musenalm_type", Required: false, Values: models.MUSENALM_TYPE_VALUES, MaxSelect: len(models.MUSENALM_TYPE_VALUES)},
|
&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.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:
|
// 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},
|
&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
|
return &fields
|
||||||
}
|
}
|
||||||
|
|
||||||
func itemsIndexes(collection *core.Collection) {
|
func partialsIndexes(collection *core.Collection) {
|
||||||
addMusenalmIDIndex(collection)
|
addMusenalmIDIndex(collection)
|
||||||
addIndex(collection, "preferredtitle", false)
|
addIndex(collection, "preferredtitle", false)
|
||||||
addIndex(collection, "varianttile", false)
|
addIndex(collection, "varianttitle", false)
|
||||||
addIndex(collection, "paralleltitle", false)
|
addIndex(collection, "paralleltitle", false)
|
||||||
addIndex(collection, "title_statement", false)
|
addIndex(collection, "title_statement", false)
|
||||||
addIndex(collection, "subtitle_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) {
|
func setBasicPublicRules(collection *core.Collection) {
|
||||||
collection.ViewRule = types.Pointer("@request.auth.id != ''")
|
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) {
|
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, "")
|
collection.AddIndex("idx_"+name+"_"+field, unique, field, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func createAgentRelationsTable(app core.App, sourcetablename, targettablename, tablename string) error {
|
func basicRelationCollection(app core.App, sourcetablename, targettablename string, relations []string) (*core.Collection, error) {
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func basicRelationFields(app core.App, sourcetablename, targettablename string, relations []string) (core.FieldsList, error) {
|
|
||||||
stable, err := app.FindCollectionByNameOrId(sourcetablename)
|
stable, err := app.FindCollectionByNameOrId(sourcetablename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -53,11 +43,27 @@ func basicRelationFields(app core.App, sourcetablename, targettablename string,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collection := core.NewBaseCollection(relationTableName(stable.Name, ttable.Name))
|
||||||
|
setBasicPublicRules(collection)
|
||||||
|
|
||||||
fields := core.NewFieldsList(
|
fields := core.NewFieldsList(
|
||||||
&core.RelationField{Name: stable.Name, Required: true, CollectionId: stable.Id},
|
&core.RelationField{Name: stable.Name, Required: true, CollectionId: stable.Id, MinSelect: 1, MaxSelect: 1},
|
||||||
&core.RelationField{Name: ttable.Name, Required: true, CollectionId: ttable.Id},
|
&core.RelationField{Name: ttable.Name, Required: true, CollectionId: ttable.Id, MinSelect: 1, MaxSelect: 1},
|
||||||
&core.TextField{Name: "relation_type", Required: true},
|
&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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,12 +376,31 @@ var MUSENALM_MIME_TYPES = []string{
|
|||||||
"image/svg+xml",
|
"image/svg+xml",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var AGENT_RELATIONS = []string{
|
||||||
|
"Autor:in",
|
||||||
|
"Herausgeber:in",
|
||||||
|
"Verlag",
|
||||||
|
"Druck",
|
||||||
|
"Vertrieb",
|
||||||
|
"Stecher:in",
|
||||||
|
"Zeichner:in",
|
||||||
|
"Übersetzer:in",
|
||||||
|
}
|
||||||
|
|
||||||
|
var SERIES_RELATIONS = []string{
|
||||||
|
"Bevorzugter Reihentitel",
|
||||||
|
"Alternativer Reihentitel",
|
||||||
|
"Späterer Reihentitel",
|
||||||
|
"Früherer Reihentitel",
|
||||||
|
"In anderer Sprache",
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PLACES_TABLE = "places"
|
PLACES_TABLE = "places"
|
||||||
AGENTS_TABLE = "agents"
|
AGENTS_TABLE = "agents"
|
||||||
SERIES_TABLE = "series"
|
SERIES_TABLE = "series"
|
||||||
ENTRIES_TABLE = "entries"
|
ENTRIES_TABLE = "entries"
|
||||||
ITEMS_TABLE = "items"
|
PARTIALS_TABLE = "partials"
|
||||||
|
|
||||||
ANNOTATION_FIELD = "annotation"
|
ANNOTATION_FIELD = "annotation"
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import (
|
|||||||
"github.com/pocketbase/pocketbase/apis"
|
"github.com/pocketbase/pocketbase/apis"
|
||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
"github.com/pocketbase/pocketbase/plugins/migratecmd"
|
||||||
// _ "musenalm/migrations"
|
|
||||||
|
_ "github.com/Theodor-Springmann-Stiftung/musenalm/migrations"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user