-
Notifications
You must be signed in to change notification settings - Fork 3
ENG-420-create-space-and-anonymous-account #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughThis change introduces anonymous user support for spaces by updating database schemas, API endpoints, and utility functions. It adds an 'anonymous' agent type, new SQL functions and triggers for managing anonymous users, and modifies the API and Supabase context logic to handle anonymous user creation, authentication, and cleanup when spaces are deleted. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API (route.ts)
participant Supabase DB
participant Auth Service
Client->>API (route.ts): POST /api/supabase/space { space, account_id, password }
API (route.ts)->>Supabase DB: Create or retrieve Space
API (route.ts)->>Auth Service: Sign in anonymous user (email, password)
alt Anonymous user does not exist
API (route.ts)->>Auth Service: Create anonymous user (email, password)
end
API (route.ts)->>Supabase DB: Create/retrieve PlatformAccount for anon user
API (route.ts)->>Supabase DB: Grant SpaceAccess (editor) to anon account and account_id
API (route.ts)-->>Client: Return space record or error
Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 8
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
apps/roam/src/utils/supabaseContext.ts(3 hunks)apps/website/app/api/supabase/space/route.ts(3 hunks)packages/database/supabase/migrations/20250627172412_upsert_space.sql(1 hunks)packages/database/supabase/schemas/account.sql(1 hunks)packages/database/supabase/schemas/space.sql(1 hunks)packages/database/types.gen.ts(3 hunks)packages/ui/src/lib/supabase/client.ts(1 hunks)packages/ui/src/lib/utils.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/schemas/account.sql:0-0
Timestamp: 2025-06-09T16:55:48.941Z
Learning: Security work including RLS policies and permission restrictions is currently postponed in the discourse-graph project as communicated by maparent.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:123-136
Timestamp: 2025-06-04T11:41:08.589Z
Learning: Currently, there are no Obsidian spaces in the database - all existing spaces are Roam spaces. This means database migrations targeting space platform assignments only need to handle Roam for now.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: apps/website/app/api/supabase/agent_identifier/route.ts:0-0
Timestamp: 2025-06-09T16:54:29.659Z
Learning: In the AgentIdentifier API route (apps/website/app/api/supabase/agent_identifier/route.ts), the trusted field is intentionally optional and should accept undefined values. The validation logic `if (trusted !== undefined && ...)` is designed to allow undefined as expected behavior.
packages/ui/src/lib/supabase/client.ts (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.648Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/types.gen.ts:336-371
Timestamp: 2025-06-04T11:54:37.239Z
Learning: The team prefers not to manually edit generated files (like Supabase TypeScript types) even when they contain inaccuracies, as manual changes would be overwritten during regeneration. They treat generated files as read-only artifacts.
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-06-23T13:20:12.846Z
Learning: In TypeScript codebases, prefer 'type' aliases over 'interface' declarations for defining types, unless an interface is specifically required.
packages/database/supabase/schemas/account.sql (1)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/schema.yaml:0-0
Timestamp: 2025-06-09T16:53:13.253Z
Learning: In LinkML schema files, enum default values should use the enum constructor syntax like `ifabsent: AgentType(person)` rather than literal string values like `ifabsent: 'person'`. This is the correct syntax that passes LinkML linting.
packages/database/supabase/migrations/20250627172412_upsert_space.sql (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/schemas/extensions.sql:1-11
Timestamp: 2025-05-20T03:02:36.027Z
Learning: The necessary schemas for Supabase extensions (like 'extensions', 'graphql', and 'vault') are automatically created by Supabase before extensions are installed, so they don't need to be explicitly created in SQL migration files.
packages/database/types.gen.ts (3)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/schema.yaml:0-0
Timestamp: 2025-06-09T16:53:13.253Z
Learning: In LinkML schema files, enum default values should use the enum constructor syntax like `ifabsent: AgentType(person)` rather than literal string values like `ifabsent: 'person'`. This is the correct syntax that passes LinkML linting.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: apps/website/app/api/supabase/agent_identifier/route.ts:0-0
Timestamp: 2025-06-09T16:54:29.659Z
Learning: In the AgentIdentifier API route (apps/website/app/api/supabase/agent_identifier/route.ts), the trusted field is intentionally optional and should accept undefined values. The validation logic `if (trusted !== undefined && ...)` is designed to allow undefined as expected behavior.
apps/roam/src/utils/supabaseContext.ts (8)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#189
File: packages/database/supabase/migrations/20250603144146_account_centric.sql:123-136
Timestamp: 2025-06-04T11:41:08.589Z
Learning: Currently, there are no Obsidian spaces in the database - all existing spaces are Roam spaces. This means database migrations targeting space platform assignments only need to handle Roam for now.
Learnt from: sid597
PR: DiscourseGraphs/discourse-graph#232
File: apps/roam/src/utils/getAllDiscourseNodesSince.ts:18-31
Timestamp: 2025-06-22T10:40:52.752Z
Learning: In apps/roam/src/utils/getAllDiscourseNodesSince.ts, the user confirmed that querying for `?title` with `:node/title` and mapping it to the `text` field in the DiscourseGraphContent type is the correct implementation for retrieving discourse node content from Roam Research, despite it appearing to query page titles rather than block text content.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-06-25T22:56:17.467Z
Learning: In the Roam discourse-graph system, the existence of the configuration page (identified by DISCOURSE_CONFIG_PAGE_TITLE) and its corresponding UID is a system invariant. The code can safely assume this page will always exist, so defensive null checks are not needed when using `getPageUidByPageTitle(DISCOURSE_CONFIG_PAGE_TITLE)`.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#220
File: apps/roam/src/utils/conceptConversion.ts:42-56
Timestamp: 2025-06-17T23:37:45.289Z
Learning: In the DiscourseNode interface from apps/roam/src/utils/getDiscourseNodes.ts, the field `type` serves as the unique identifier field, not a type classification field. The interface has no `uid` or `id` field, making `node.type` the correct field to use for UID-related operations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#220
File: apps/roam/src/utils/conceptConversion.ts:42-56
Timestamp: 2025-06-17T23:37:45.289Z
Learning: In the DiscourseNode interface from apps/roam/src/utils/getDiscourseNodes.ts, the field `node.type` serves as the UID field rather than having a conventional `node.uid` field. This is an unusual naming convention where the type field actually contains the unique identifier.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.648Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
apps/website/app/api/supabase/space/route.ts (4)
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/api/supabase/rpc/search-content/route.ts:53-56
Timestamp: 2025-05-30T14:37:30.215Z
Learning: The search-content route (apps/website/app/api/supabase/rpc/search-content/route.ts) is intentionally designed to be platform-agnostic rather than Roam-specific. The generic "Platform" terminology (like subsetPlatformIds) is used because the route will support multiple platforms in the near future, not just Roam.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: apps/website/app/api/supabase/agent_identifier/route.ts:0-0
Timestamp: 2025-06-09T16:54:29.659Z
Learning: In the AgentIdentifier API route (apps/website/app/api/supabase/agent_identifier/route.ts), the trusted field is intentionally optional and should accept undefined values. The validation logic `if (trusted !== undefined && ...)` is designed to allow undefined as expected behavior.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.648Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.
🧬 Code Graph Analysis (1)
packages/ui/src/lib/supabase/client.ts (2)
packages/database/types.gen.ts (1)
Database(9-821)apps/website/app/utils/supabase/client.ts (1)
createClient(6-14)
🔇 Additional comments (8)
packages/database/supabase/schemas/account.sql (1)
4-5: LGTM! Clean enum extension for anonymous agent support.The addition of the 'anonymous' value to the AgentType enum follows the existing pattern and supports the new anonymous user functionality.
packages/ui/src/lib/supabase/client.ts (2)
1-4: LGTM! Improved imports and type safety.The explicit import of
SupabaseClienttype and renaming of the import function enhances code clarity.
9-13: LGTM! Excellent type safety improvement.The
DGSupabaseClienttype alias provides strong typing for the Supabase client with proper database schema constraints.packages/database/supabase/schemas/space.sql (2)
31-33: LGTM! Clean email generation function.The
get_space_anonymous_emailfunction is correctly marked as IMMUTABLE and generates a consistent email format for anonymous users.
47-47: LGTM! Proper trigger setup for cleanup.The trigger is correctly configured to execute the cleanup function after each DELETE operation on the Space table.
packages/database/types.gen.ts (3)
615-621: LGTM! Correct function type definition.The
get_space_anonymous_emailfunction type correctly reflects the SQL function signature with proper parameter and return types.
706-706: LGTM! AgentType enum updated correctly.The enum type definition properly includes the new "anonymous" value, maintaining consistency with the database schema.
932-932: LGTM! Constants array updated consistently.The Constants array correctly includes "anonymous" in the AgentType values, ensuring runtime consistency with the type definitions.
612cbb3 to
c6c7048
Compare
204857f to
cfe7380
Compare
mdroidian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nits
cfe7380 to
3acac2d
Compare
Upon space creation, create an anonymous supabase user for the space.
Ensure it is written in as a space "participant" (for future RLS function)
Trigger to delete it when the space is deleted.
All this machinery is tied to getContext.
Auxiliary function to get a supabase client logged in with that anonymous user.
Summary by CodeRabbit
New Features
Improvements
Bug Fixes