mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-12 08:45:38 +02:00
🐜 fix(zero): Remove team and members schemas (#289)
## Description <!-- Briefly describe the purpose and scope of your changes --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new database schema with tables for games, users, Steam accounts, categories, friends lists, images, and game libraries. - Added new enumerated types for compatibility, controller support, category type, image type, and Steam status. - **Refactor** - Removed all team and membership-related features, including tables, relationships, and access permissions. - Simplified the primary key structure of the images table. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type { Size, Links} from "@nestri/core/src/base-game/base-game.sql";
|
|
||||||
import type { Limitations } from "@nestri/core/src/steam/steam.sql";
|
import type { Limitations } from "@nestri/core/src/steam/steam.sql";
|
||||||
|
import type { Size, Links } from "@nestri/core/src/base-game/base-game.sql";
|
||||||
import type { ImageColor, ImageDimensions } from "@nestri/core/src/images/images.sql";
|
import type { ImageColor, ImageDimensions } from "@nestri/core/src/images/images.sql";
|
||||||
import {
|
import {
|
||||||
json,
|
json,
|
||||||
@@ -47,27 +47,6 @@ const steam_accounts = table("steam_accounts")
|
|||||||
})
|
})
|
||||||
.primaryKey("id");
|
.primaryKey("id");
|
||||||
|
|
||||||
const teams = table("teams")
|
|
||||||
.columns({
|
|
||||||
id: string(),
|
|
||||||
name: string(),
|
|
||||||
invite_code: string(),
|
|
||||||
max_members: number(),
|
|
||||||
owner_steam_id: string(),
|
|
||||||
...timestamps,
|
|
||||||
})
|
|
||||||
.primaryKey("id");
|
|
||||||
|
|
||||||
const members = table("members")
|
|
||||||
.columns({
|
|
||||||
role: string(),
|
|
||||||
team_id: string(),
|
|
||||||
steam_id: string(),
|
|
||||||
user_id: string().optional(),
|
|
||||||
...timestamps,
|
|
||||||
})
|
|
||||||
.primaryKey("team_id", "steam_id");
|
|
||||||
|
|
||||||
const friends_list = table("friends_list")
|
const friends_list = table("friends_list")
|
||||||
.columns({
|
.columns({
|
||||||
steam_id: string(),
|
steam_id: string(),
|
||||||
@@ -130,11 +109,11 @@ const images = table("images")
|
|||||||
dimensions: json<ImageDimensions>(),
|
dimensions: json<ImageDimensions>(),
|
||||||
extracted_color: json<ImageColor>(),
|
extracted_color: json<ImageColor>(),
|
||||||
...timestamps
|
...timestamps
|
||||||
}).primaryKey("image_hash", "type", "base_game_id", "position")
|
}).primaryKey("image_hash")
|
||||||
|
|
||||||
// Schema and Relationships
|
// Schema and Relationships
|
||||||
export const schema = createSchema({
|
export const schema = createSchema({
|
||||||
tables: [users, steam_accounts, teams, members, friends_list, categories, base_games, games, game_libraries, images],
|
tables: [users, steam_accounts, friends_list, categories, base_games, games, game_libraries, images],
|
||||||
relationships: [
|
relationships: [
|
||||||
relationships(steam_accounts, (r) => ({
|
relationships(steam_accounts, (r) => ({
|
||||||
user: r.one({
|
user: r.one({
|
||||||
@@ -142,16 +121,6 @@ export const schema = createSchema({
|
|||||||
destSchema: users,
|
destSchema: users,
|
||||||
destField: ["id"],
|
destField: ["id"],
|
||||||
}),
|
}),
|
||||||
memberEntries: r.many({
|
|
||||||
sourceField: ["id"],
|
|
||||||
destSchema: members,
|
|
||||||
destField: ["steam_id"],
|
|
||||||
}),
|
|
||||||
teams: r.many({
|
|
||||||
sourceField: ["id"],
|
|
||||||
destSchema: teams,
|
|
||||||
destField: ["owner_steam_id"],
|
|
||||||
}),
|
|
||||||
friends: r.many(
|
friends: r.many(
|
||||||
{
|
{
|
||||||
sourceField: ["id"],
|
sourceField: ["id"],
|
||||||
@@ -178,46 +147,12 @@ export const schema = createSchema({
|
|||||||
),
|
),
|
||||||
})),
|
})),
|
||||||
relationships(users, (r) => ({
|
relationships(users, (r) => ({
|
||||||
members: r.many({
|
|
||||||
sourceField: ["id"],
|
|
||||||
destSchema: members,
|
|
||||||
destField: ["user_id"],
|
|
||||||
}),
|
|
||||||
steamAccounts: r.many({
|
steamAccounts: r.many({
|
||||||
sourceField: ["id"],
|
sourceField: ["id"],
|
||||||
destSchema: steam_accounts,
|
destSchema: steam_accounts,
|
||||||
destField: ["user_id"]
|
destField: ["user_id"]
|
||||||
})
|
})
|
||||||
})),
|
})),
|
||||||
relationships(teams, (r) => ({
|
|
||||||
owner: r.one({
|
|
||||||
sourceField: ["owner_steam_id"],
|
|
||||||
destSchema: steam_accounts,
|
|
||||||
destField: ["id"],
|
|
||||||
}),
|
|
||||||
members: r.many({
|
|
||||||
sourceField: ["id"],
|
|
||||||
destSchema: members,
|
|
||||||
destField: ["team_id"],
|
|
||||||
}),
|
|
||||||
})),
|
|
||||||
relationships(members, (r) => ({
|
|
||||||
team: r.one({
|
|
||||||
sourceField: ["team_id"],
|
|
||||||
destSchema: teams,
|
|
||||||
destField: ["id"],
|
|
||||||
}),
|
|
||||||
user: r.one({
|
|
||||||
sourceField: ["user_id"],
|
|
||||||
destSchema: users,
|
|
||||||
destField: ["id"],
|
|
||||||
}),
|
|
||||||
steamAccount: r.one({
|
|
||||||
sourceField: ["steam_id"],
|
|
||||||
destSchema: steam_accounts,
|
|
||||||
destField: ["id"],
|
|
||||||
}),
|
|
||||||
})),
|
|
||||||
relationships(base_games, (r) => ({
|
relationships(base_games, (r) => ({
|
||||||
libraryOwners: r.many(
|
libraryOwners: r.many(
|
||||||
{
|
{
|
||||||
@@ -324,30 +259,12 @@ type Auth = {
|
|||||||
|
|
||||||
export const permissions = definePermissions<Auth, Schema>(schema, () => {
|
export const permissions = definePermissions<Auth, Schema>(schema, () => {
|
||||||
return {
|
return {
|
||||||
members: {
|
|
||||||
row: {
|
|
||||||
select: [
|
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'members'>) => q.exists("user", (u) => u.where("id", auth.sub)),
|
|
||||||
//allow other team members to view other members
|
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'members'>) => q.exists("team", (u) => u.related("members", (m) => m.where("user_id", auth.sub))),
|
|
||||||
]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
teams: {
|
|
||||||
row: {
|
|
||||||
select: [
|
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'teams'>) => q.exists("members", (u) => u.where("user_id", auth.sub)),
|
|
||||||
]
|
|
||||||
},
|
|
||||||
},
|
|
||||||
steam_accounts: {
|
steam_accounts: {
|
||||||
row: {
|
row: {
|
||||||
select: [
|
select: [
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'steam_accounts'>) => q.exists("user", (u) => u.where("id", auth.sub)),
|
(auth: Auth, q: ExpressionBuilder<Schema, 'steam_accounts'>) => q.exists("user", (u) => u.where("id", auth.sub)),
|
||||||
//Allow friends to view friends steam accounts
|
//Allow friends to view friends steam accounts
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'steam_accounts'>) => q.exists("friends", (u) => u.where("user_id", auth.sub)),
|
(auth: Auth, q: ExpressionBuilder<Schema, 'steam_accounts'>) => q.exists("friends", (u) => u.where("user_id", auth.sub)),
|
||||||
//allow other team members to see a user's steam account
|
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'steam_accounts'>) => q.exists("memberEntries", (u) => u.related("team", (t) => t.related("members", (m) => m.where("user_id", auth.sub)))),
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -370,8 +287,6 @@ export const permissions = definePermissions<Auth, Schema>(schema, () => {
|
|||||||
row: {
|
row: {
|
||||||
select: [
|
select: [
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'game_libraries'>) => q.exists("owner", (u) => u.where("user_id", auth.sub)),
|
(auth: Auth, q: ExpressionBuilder<Schema, 'game_libraries'>) => q.exists("owner", (u) => u.where("user_id", auth.sub)),
|
||||||
//allow team members to see the other members' libraries
|
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'game_libraries'>) => q.exists("owner", (u) => u.related("memberEntries", (f) => f.where("user_id", auth.sub))),
|
|
||||||
//allow friends to see their friends libraries
|
//allow friends to see their friends libraries
|
||||||
(auth: Auth, q: ExpressionBuilder<Schema, 'game_libraries'>) => q.exists("owner", (u) => u.related("friends", (f) => f.where("user_id", auth.sub))),
|
(auth: Auth, q: ExpressionBuilder<Schema, 'game_libraries'>) => q.exists("owner", (u) => u.related("friends", (f) => f.where("user_id", auth.sub))),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user