Space
Space table
Space table
The Space table represents a collaborative environment where users can manage their assets and share access with other users. Each space is associated with a profile and can have multiple members.
Database schema
create table public.space (
id uuid not null default gen_random_uuid (),
created_at timestamp with time zone not null default now(),
updated_at timestamp with time zone null,
deleted_at timestamp with time zone null,
profile_id uuid null,
preferred_currency text not null,
group_id uuid null
)Key fields
id: Unique identifier for the space (UUID)profile_id: Reference to the profile that owns the spacepreferred_currency: Three-letter currency code (e.g., 'EUR', 'USD')group_id: Reference to the group managing access control
Constraints
space_pkey: Primary key onidspace_group_id_key: Unique constraint ongroup_idspace_currency_check: Ensures currency code is exactly 3 charactersfk_space_group: Foreign key togrouptablespace_profile_id_fkey: Foreign key toprofiletable
Timestamps
created_at: Automatically set on record creationupdated_at: Automatically updated via triggerdeleted_at: Soft deletion timestamp
Database triggers
before_insert_space_create_group: Automatically creates a group for new spaceshandle_updated_at: Updates theupdated_attimestamp on record modification
TypeScript interfaces
Base Space Interface
interface Space extends Entity {
profileId: string;
preferredCurrency: Currency;
groupId: string;
}User space interface
interface UserSpace extends Space {
firstName: string;
lastName: string;
avatar: string;
}Space member interface
interface SpaceMember extends Profile {
role: SpaceMemberRole;
spaceMemberStatus: SpaceMemberStatus;
groupInviteId: string;
}Member management
Roles
enum SpaceMemberRole {
Owner = "owner",
Admin = "admin",
Member = "member",
}Status
enum SpaceMemberStatus {
Active = "active",
Invited = "invited",
Declined = "declined",
}Space member view
The space_member view combines information from:
group_usergroup_inviteprofilespace
It provides a unified view of all members and invitees in a space, including their:
- Membership status
- Role
- Personal information
- Space relationship
Key operations
Queries
getSpaceByProfileId(profileId): Retrieves space by profile IDgetSpaceById(spaceId): Retrieves space by IDgetSpaceMembers(spaceId): Lists all members of a spacegetUserSpaces(): Lists all spaces available to the current user
Mutations
updateSpacePreferredCurrency({spaceId, preferredCurrency}): Updates space currencyremoveSpaceMember(spaceGroupId, userId, spaceOwnerUserId): Removes a member from space
Automatic space creation
When a new profile is created, a space is automatically created with:
- Default currency: 'EUR'
- New group for access control
- Owner role assigned to the profile
Relationships
- Many-to-One with
profilethroughprofile_id - One-to-One with
groupthroughgroup_id - Many-to-Many with users through the
space_memberview