diff --git a/migrations/1738936647_entries.go b/migrations/1738936647_entries.go index abd5f87..2e8f6d1 100644 --- a/migrations/1738936647_entries.go +++ b/migrations/1738936647_entries.go @@ -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) diff --git a/migrations/1738936791_r_entries_agents.go b/migrations/1738936791_r_entries_agents.go deleted file mode 100644 index d3e794f..0000000 --- a/migrations/1738936791_r_entries_agents.go +++ /dev/null @@ -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 - }) -} diff --git a/migrations/1738936829_r_entries_series.go b/migrations/1738936829_r_entries_series.go index d3e794f..785cf7a 100644 --- a/migrations/1738936829_r_entries_series.go +++ b/migrations/1738936829_r_entries_series.go @@ -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) }) } diff --git a/migrations/1738942133_items.go b/migrations/1738942133_partials.go similarity index 85% rename from migrations/1738942133_items.go rename to migrations/1738942133_partials.go index 7516adf..53704eb 100644 --- a/migrations/1738942133_items.go +++ b/migrations/1738942133_partials.go @@ -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) diff --git a/migrations/1738942155_r_items_agents.go b/migrations/1738942155_r_items_agents.go deleted file mode 100644 index d3e794f..0000000 --- a/migrations/1738942155_r_items_agents.go +++ /dev/null @@ -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 - }) -} diff --git a/migrations/1738951458_r_partials_agents.go b/migrations/1738951458_r_partials_agents.go new file mode 100644 index 0000000..c45cfd9 --- /dev/null +++ b/migrations/1738951458_r_partials_agents.go @@ -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) + }) +} diff --git a/migrations/1738952826_r_entries_agents.go b/migrations/1738952826_r_entries_agents.go new file mode 100644 index 0000000..34a98b0 --- /dev/null +++ b/migrations/1738952826_r_entries_agents.go @@ -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) + }) +} diff --git a/migrations/common.go b/migrations/common.go index bc04eaf..18b3993 100644 --- a/migrations/common.go +++ b/migrations/common.go @@ -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 } diff --git a/models/dbdata.go b/models/dbdata.go index 5ca707b..b1843bc 100644 --- a/models/dbdata.go +++ b/models/dbdata.go @@ -376,12 +376,31 @@ var MUSENALM_MIME_TYPES = []string{ "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 ( - PLACES_TABLE = "places" - AGENTS_TABLE = "agents" - SERIES_TABLE = "series" - ENTRIES_TABLE = "entries" - ITEMS_TABLE = "items" + PLACES_TABLE = "places" + AGENTS_TABLE = "agents" + SERIES_TABLE = "series" + ENTRIES_TABLE = "entries" + PARTIALS_TABLE = "partials" ANNOTATION_FIELD = "annotation" diff --git a/musenalm.go b/musenalm.go index 69316b5..b399664 100644 --- a/musenalm.go +++ b/musenalm.go @@ -8,7 +8,8 @@ import ( "github.com/pocketbase/pocketbase/apis" "github.com/pocketbase/pocketbase/core" "github.com/pocketbase/pocketbase/plugins/migratecmd" - // _ "musenalm/migrations" + + _ "github.com/Theodor-Springmann-Stiftung/musenalm/migrations" ) func main() {