Closed rickylabs closed 6 months ago
Thank you for considering my feature request. To complement the request and provide further context, I'd like to detail the steps I took in the process of integrating Twenty with my Supabase instance, leading up to the workspace creation form. The purpose is to underscores the necessity for the proposed enhancements and demonstrates the potential for successful integration with some (small) adjustments.
Initial Database Connection:
docker-compose.yml
. My Supabase instance uses a different setup.docker-compose.yml
to connect to my external Supabase-managed PostgreSQL database, including updating environment variables to reflect my database credentials and removing the db
service.Database Migration Scripts:
truncate-db.ts
script risked dropping existing schemas in my Supabase database, potentially affecting other integrated applications.Schema and Extensions Setup:
setup-db.ts
script attempts to create new schemas and requires extensions that were not in the expected "public" schema but in the "extensions" schema of Supabase.Workspace Creation:
Extension Usage in Workspace Schema Creation:
uuid_generate_v4()
. The error message was driverError: error: function public.uuid_generate_v4() does not exist
. This issue arose because Twenty expects these functions to be in the "public" schema, whereas my Supabase instance has them installed in "extensions" schema, leading to a halt in the process as Twenty couldn't create tables in the new workspace schema.While I managed to navigate these issues to a certain extent, the process showcase the broader need for flexibility in Twenty's database configuration options, specifically around schema management, extension usage, and storage integration. A comprehensive "How-To" guide in Twenty's documentation for integrating with Supabase would be immensely beneficial, providing step-by-step instructions and highlighting customizable settings for a smoother integration process.
Thanks a lot for providing all this. This is a well documented and very clear issue, would be great if they were all like this š
Also a big fan of Supabase and would love to collaborate with them at some point, but I wonder what's your use-case exactly? It feels like there'd be overlap and I'm not what would be the long-term vision to support swapping the DB here. We're not really prepared for the fact that things could happen at the DB layer so I'm not sure it would always play well with a supabase setup in parallel (e.g. if you modify an object through supabase api then our application layer wouldn't catch those events because unlike them we don't get them from Postgres - only from our application layer)
We plan to support Foreign data wrappers soon with the remote objects feature (e.g. ongoing PRs https://github.com/twentyhq/twenty/pulls?q=remote+objects+is%3Apr+is%3Aclosed) I wonder if that could be a better direction for your use-case. You would be able to plug the supabase DB within a wraper and create crm objects for each table
Thank you, @FelixMalfait, for your open and constructive feedback. It's great to hear about your interest in Supabase and the ongoing efforts to enhance Twenty's capabilities. Let me address the points you raised and add further context to our use-case and needs:
Advantages of Using a DB Provider Like Supabase: Utilizing a service like Supabase offers significant benefits, including managed backups, simplified local development, and branch-specific environments. These features streamline development workflows and ensure data integrity across different stages of the development lifecycle.
Separation of the DB Layer: From a security and governance standpoint, separating the database layer from application logic is crucial. This separation also addresses regulatory and compliance requirements, particularly concerning data sovereignty and location-specific regulations.
Supabaseās Enhanced Functionality: While Supabase provides a robust set of features beyond basic database hosting, such as Functions, Realtime, and Row-Level Security policies, our focus here is not to leverage these functionalities directly. Instead, we aim to utilize Supabase as a reliable and scalable PostgreSQL provider that aligns with Twenty's database needs.
Foreign Data Wrappers and Remote Objects: I've reviewed the ongoing PRs regarding remote objects and appreciate the direction Twenty is taking. This approach aligns with our understanding that there's shared ground in terms of database configuration flexibility between Twenty and Supabase. It reinforces our belief in the feasibility of our integration objectives.
Our Specific Use-Case: In Switzerland, where our servers are hosted, we manage not only CRM data but also financial and other sensitive information within our self-hosted Supabase instance. Compliance with local regulations necessitates that this data remain within our control, on-premises. Thus, solutions like foreign data wrappers, which might imply external data management, do not align with our regulatory requirements.
Cross-Tool Workflows with Directus: Our setup includes Directus, which acts as a central data layer across different schemas. This allows us to link various tools, creating workflows and gathering insights through unified dashboards and analytics. It highlights the need for a database configuration that's versatile enough to handle complex setups involving multiple schemas.
While some of our needs may be unique to our company, the core requirement to choose our database hosting solutionābe it Supabase, Neon Postgres, or any other PostgreSQL providerāis critical. Supabase aligns closely with Twenty's database setup in terms of extensions and functionalities, making it a fitting choice for our environment.
A few crucial modifications are needed for seamless integration: enabling configuration for extension schema locations, facilitating connections to external databases complete with configuration guidance and necessary SQL permissions without requiring superuser status, and providing the ability to skip database truncation. Additionally, integrating Supabase (or more generally any S3 compatible) storage support for secure connections to private buckets is vital. Implementing these updates would enhance Twenty's compatibility with current databases and storage systems, significantly boosting its flexibility.
Your ORM and data management practices are commendable, and I'm convinced that with these small yet impactful enhancements, Twenty can become even more versatile and powerful.
Looking forward to your thoughts and happy to assist in any way I can.
Scope & Context
We aim to integrate Twenty into an existing ecosystem utilizing a Supabase instance that already supports various applications like Medusa, Strapi, and Directus. The integration requires customization of Twenty's database configurations to ensure compatibility with Supabase's infrastructure, including schemas, user permissions, extensions location, and storage options.
Current Behavior and Process
Adjustments in the database setup and Docker configuration were necessary to align Twenty with our self-hosted Supabase instance. The process highlighted the potential for compatibility with some codebase adjustments:
Database Migration Adjustments: Created a restricted Twenty user to avoid dropping existing schemas. Manually set up required schemas and utilized pre-installed extensions in Supabase, indicating a need for customizable schema and extension locations.
Docker Compose Modifications: Updated the
docker-compose.yml
to connect Twenty to the external PostgreSQL managed by Supabase, including network and storage configuration adjustments. Removed the built-indb
service and tailored environment variables to fit our specific requirements.Supabase Integration Points:
Expected Behavior
For full compatibility with ecosystems utilizing Supabase, we propose several enhancements:
Customizable Database Configurations: Enabling detailed customization in Twenty for database schemas, user permissions, and the location of database extensions. Users should be able to define target schemas and extension locations to align with their Supabase setup.
Bypass Option for Database Reset: Introducing an option to bypass or customize the behavior of the
truncate-db.ts
script to safeguard shared database instances.Supabase Storage Integration: Support for using Supabase's S3-compatible storage as the default option, including configurations for connecting to private buckets using access keys and secrets.
Enhanced Docker Configuration Support: Guidance on customizing
docker-compose.yml
for external service integration, covering network settings, storage options, and environmental variable adjustments.Technical Inputs
Implement a configuration system in Twenty for adjustable database and storage setups required for Supabase integration, including specifying schema and extension locations.
Develop storage configuration options for Supabase's S3-compatible storage, adding necessary fields for a complete and secure connection.
Revise and expand the official documentation to cover these integration scenarios comprehensively, providing step-by-step guidance for Docker and database setup modifications for Supabase compatibility.
By addressing these issues and enabling these adjustments, Twenty can significantly broaden its applicability and value for businesses and developers seeking flexible CRM solutions within a Supabase-powered ecosystem.