Skip to content

Commit

Permalink
Add API rules and camelCase for tierList
Browse files Browse the repository at this point in the history
  • Loading branch information
YummYume committed Mar 24, 2024
1 parent 1eed24c commit 28de1da
Show file tree
Hide file tree
Showing 37 changed files with 1,033 additions and 75 deletions.
20 changes: 10 additions & 10 deletions docs/FIXTURES.MD
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Here is an example of what a fixture can look like (taken from the `ranks.ts` fi
// Import the necessary types with "import type..."
import type { Fixture, Reference } from '../index';
import type { RanksRecord, RanksResponse } from '../../src/lib/types/pocketbase';
import type { TierlistsDataKeys } from './tierlists';
import type { TierlistsDataKeys } from './tier-lists';

// Export the data that is going to be inserted in a constant to be able to access it from other fixtures
export const DATA = {
Expand Down Expand Up @@ -106,8 +106,8 @@ export const DATA = {
},
// ... other data
// Use the right type to get full type-safety on your export, also makes it easier to add new data
// We omit the "tierlist" field because it is already represented by the key of the object
} as const satisfies Record<TierlistsDataKeys, Reference<Omit<RanksRecord, 'tierlist'>>>;
// We omit the "tierList" field because it is already represented by the key of the object
} as const satisfies Record<TierlistsDataKeys, Reference<Omit<RanksRecord, 'tierList'>>>;

// Export the keys of the data to be able to use them as types
export type RanksDataKeys = keyof typeof DATA;
Expand All @@ -116,17 +116,17 @@ export type RanksDataKeys = keyof typeof DATA;
export default {
// The name of our fixture, usually the name of the file and collection
name: 'ranks',
// The order (ascendant) in which to load this fixture, useful to load this fixture after its dependencies (tierlists)
// The order (ascendant) in which to load this fixture, useful to load this fixture after its dependencies (tierLists)
order: 2,
// Our load function with PocketBase, records of other fixtures and Faker
load: async (pb, references) => {
// Prepare the records we will return
const records: Reference<RanksResponse> = {};
// Because we are loading after the "tierlists" fixture, all the tierlists inserted are available inside "references.tierlists"
const tierlistsReferences = references.tierlists || {};
// Because we are loading after the "tierLists" fixture, all the tier lists inserted are available inside "references.tierLists"
const tierListsReferences = references.tierLists || {};

// We loop over each tierlist
for (const [tierlist, ranks] of Object.entries(DATA)) {
// We loop over each tier list
for (const [tierList, ranks] of Object.entries(DATA)) {
// We use the constant defined earlier to know how many ranks to add
for (const [i, rank] of Object.entries(ranks)) {
// We create a new record with fake data and add it to our "records" object
Expand All @@ -135,8 +135,8 @@ export default {
color: rank.color,
description: rank.description,
position: rank.position,
// We use the "references" object to reference the tierlist we want to link to
tierlist: tierlistsReferences[tierlist].id,
// We use the "references" object to reference the tier list we want to link to
tierList: tierListsReferences[tierList].id,
} as RanksRecord);
}
}
Expand Down
37 changes: 37 additions & 0 deletions pocketbase/migrations/1711214542_updated_tierlists.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package migrations

import (
"encoding/json"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
)

func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78")
if err != nil {
return err
}

json.Unmarshal([]byte(`[
"CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tierlists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)"
]`), &collection.Indexes)

return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78")
if err != nil {
return err
}

json.Unmarshal([]byte(`[]`), &collection.Indexes)

return dao.SaveCollection(collection)
})
}
43 changes: 43 additions & 0 deletions pocketbase/migrations/1711214594_updated_tierlists.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package migrations

import (
"encoding/json"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
)

func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78")
if err != nil {
return err
}

collection.Name = "tier_lists"

json.Unmarshal([]byte(`[
"CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tier_lists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)"
]`), &collection.Indexes)

return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78")
if err != nil {
return err
}

collection.Name = "tierlists"

json.Unmarshal([]byte(`[
"CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tierlists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)"
]`), &collection.Indexes)

return dao.SaveCollection(collection)
})
}
43 changes: 43 additions & 0 deletions pocketbase/migrations/1711215267_updated_tier_lists.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package migrations

import (
"encoding/json"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
)

func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78")
if err != nil {
return err
}

collection.Name = "tierLists"

json.Unmarshal([]byte(`[
"CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tierLists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)"
]`), &collection.Indexes)

return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("0uxolnvwwz0sr78")
if err != nil {
return err
}

collection.Name = "tier_lists"

json.Unmarshal([]byte(`[
"CREATE INDEX ` + "`" + `idx_C79cqRc` + "`" + ` ON ` + "`" + `tier_lists` + "`" + ` (\n ` + "`" + `slug` + "`" + `,\n ` + "`" + `createdBy` + "`" + `\n)"
]`), &collection.Indexes)

return dao.SaveCollection(collection)
})
}
70 changes: 70 additions & 0 deletions pocketbase/migrations/1711215345_updated_ranks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package migrations

import (
"encoding/json"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/models/schema"
)

func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc")
if err != nil {
return err
}

// update
edit_tierList := &schema.SchemaField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "ai8coksm",
"name": "tierList",
"type": "relation",
"required": true,
"unique": false,
"options": {
"collectionId": "0uxolnvwwz0sr78",
"cascadeDelete": true,
"minSelect": null,
"maxSelect": 1,
"displayFields": []
}
}`), edit_tierList)
collection.Schema.AddField(edit_tierList)

return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc")
if err != nil {
return err
}

// update
edit_tierList := &schema.SchemaField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "ai8coksm",
"name": "tierlist",
"type": "relation",
"required": true,
"unique": false,
"options": {
"collectionId": "0uxolnvwwz0sr78",
"cascadeDelete": true,
"minSelect": null,
"maxSelect": 1,
"displayFields": []
}
}`), edit_tierList)
collection.Schema.AddField(edit_tierList)

return dao.SaveCollection(collection)
})
}
37 changes: 37 additions & 0 deletions pocketbase/migrations/1711233247_updated_ranks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package migrations

import (
"encoding/json"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
)

func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc")
if err != nil {
return err
}

json.Unmarshal([]byte(`[
"CREATE INDEX ` + "`" + `idx_p0rclkv` + "`" + ` ON ` + "`" + `ranks` + "`" + ` (\n ` + "`" + `position` + "`" + `,\n ` + "`" + `tierList` + "`" + `\n)"
]`), &collection.Indexes)

return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("sf00q2lme3knpnc")
if err != nil {
return err
}

json.Unmarshal([]byte(`[]`), &collection.Indexes)

return dao.SaveCollection(collection)
})
}
92 changes: 92 additions & 0 deletions pocketbase/migrations/1711270336_updated_items.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package migrations

import (
"encoding/json"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/models/schema"
)

func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl")
if err != nil {
return err
}

// add
new_tierList := &schema.SchemaField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "tupaapcc",
"name": "tierList",
"type": "relation",
"required": true,
"unique": false,
"options": {
"collectionId": "0uxolnvwwz0sr78",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": []
}
}`), new_tierList)
collection.Schema.AddField(new_tierList)

// update
edit_rank := &schema.SchemaField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "jlwvewrl",
"name": "rank",
"type": "relation",
"required": false,
"unique": false,
"options": {
"collectionId": "sf00q2lme3knpnc",
"cascadeDelete": true,
"minSelect": null,
"maxSelect": 1,
"displayFields": []
}
}`), edit_rank)
collection.Schema.AddField(edit_rank)

return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);

collection, err := dao.FindCollectionByNameOrId("bdhlowmnbwukpxl")
if err != nil {
return err
}

// remove
collection.Schema.RemoveField("tupaapcc")

// update
edit_rank := &schema.SchemaField{}
json.Unmarshal([]byte(`{
"system": false,
"id": "jlwvewrl",
"name": "rank",
"type": "relation",
"required": true,
"unique": false,
"options": {
"collectionId": "sf00q2lme3knpnc",
"cascadeDelete": true,
"minSelect": null,
"maxSelect": 1,
"displayFields": []
}
}`), edit_rank)
collection.Schema.AddField(edit_rank)

return dao.SaveCollection(collection)
})
}
Loading

0 comments on commit 28de1da

Please sign in to comment.