-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christian Beutel
committed
Dec 14, 2024
1 parent
e315c4d
commit b0d136c
Showing
27 changed files
with
635 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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" | ||
) | ||
|
||
func init() { | ||
m.Register(func(db dbx.Builder) error { | ||
jsonData := `{ | ||
"id": "8obn1ukumze565i", | ||
"created": "2024-12-14 17:17:00.381Z", | ||
"updated": "2024-12-14 17:17:00.381Z", | ||
"name": "follows", | ||
"type": "base", | ||
"system": false, | ||
"schema": [ | ||
{ | ||
"system": false, | ||
"id": "in1traur", | ||
"name": "follower", | ||
"type": "relation", | ||
"required": false, | ||
"presentable": false, | ||
"unique": false, | ||
"options": { | ||
"collectionId": "_pb_users_auth_", | ||
"cascadeDelete": false, | ||
"minSelect": null, | ||
"maxSelect": 1, | ||
"displayFields": null | ||
} | ||
}, | ||
{ | ||
"system": false, | ||
"id": "wxwomfd5", | ||
"name": "followee", | ||
"type": "relation", | ||
"required": false, | ||
"presentable": false, | ||
"unique": false, | ||
"options": { | ||
"collectionId": "_pb_users_auth_", | ||
"cascadeDelete": false, | ||
"minSelect": null, | ||
"maxSelect": 1, | ||
"displayFields": null | ||
} | ||
} | ||
], | ||
"indexes": [], | ||
"listRule": "@request.auth.id = follower.id || @request.auth.id = followee.id", | ||
"viewRule": "@request.auth.id = follower.id || @request.auth.id = followee.id", | ||
"createRule": "@request.auth.id = follower.id", | ||
"updateRule": "@request.auth.id = follower.id", | ||
"deleteRule": "@request.auth.id = follower.id", | ||
"options": {} | ||
}` | ||
|
||
collection := &models.Collection{} | ||
if err := json.Unmarshal([]byte(jsonData), &collection); err != nil { | ||
return err | ||
} | ||
|
||
return daos.New(db).SaveCollection(collection) | ||
}, func(db dbx.Builder) error { | ||
dao := daos.New(db); | ||
|
||
collection, err := dao.FindCollectionByNameOrId("8obn1ukumze565i") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return dao.DeleteCollection(collection) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
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" | ||
) | ||
|
||
func init() { | ||
m.Register(func(db dbx.Builder) error { | ||
jsonData := `{ | ||
"id": "j6w72f0kb5ivd7x", | ||
"created": "2024-12-14 18:20:18.920Z", | ||
"updated": "2024-12-14 18:20:18.920Z", | ||
"name": "follow_counts", | ||
"type": "view", | ||
"system": false, | ||
"schema": [ | ||
{ | ||
"system": false, | ||
"id": "w81n64il", | ||
"name": "followers", | ||
"type": "json", | ||
"required": false, | ||
"presentable": false, | ||
"unique": false, | ||
"options": { | ||
"maxSize": 1 | ||
} | ||
}, | ||
{ | ||
"system": false, | ||
"id": "rfnejpto", | ||
"name": "following", | ||
"type": "json", | ||
"required": false, | ||
"presentable": false, | ||
"unique": false, | ||
"options": { | ||
"maxSize": 1 | ||
} | ||
} | ||
], | ||
"indexes": [], | ||
"listRule": "", | ||
"viewRule": "", | ||
"createRule": null, | ||
"updateRule": null, | ||
"deleteRule": null, | ||
"options": { | ||
"query": "SELECT \n users.id,\n COALESCE(followers.count, 0) AS followers,\n COALESCE(following.count, 0) AS following\nFROM users\nLEFT JOIN (\n SELECT followee AS user_id, COUNT(*) AS count\n FROM follows\n GROUP BY followee\n) AS followers ON users.id = followers.user_id\nLEFT JOIN (\n SELECT follower AS user_id, COUNT(*) AS count\n FROM follows\n GROUP BY follower\n) AS following ON users.id = following.user_id;" | ||
} | ||
}` | ||
|
||
collection := &models.Collection{} | ||
if err := json.Unmarshal([]byte(jsonData), &collection); err != nil { | ||
return err | ||
} | ||
|
||
return daos.New(db).SaveCollection(collection) | ||
}, func(db dbx.Builder) error { | ||
dao := daos.New(db); | ||
|
||
collection, err := dao.FindCollectionByNameOrId("j6w72f0kb5ivd7x") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return dao.DeleteCollection(collection) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.