Skip to content
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

feat: Create escrow_contracts table for escrow contract tracking #143

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

Jagadeeshftw
Copy link
Collaborator

@Jagadeeshftw Jagadeeshftw commented Feb 9, 2025

This MR introduces a new SQL migration that creates the escrow_contracts table along with the escrow_state enum.

The new table is intended to store escrow contract details for the off-chain track of project contributions and time status management

Closes #91

Summary by CodeRabbit

  • New Features
    • Introduced enhanced escrow management capabilities that improve transaction tracking with clearly defined status transitions for a more reliable platform experience.
    • Added a new table for managing escrow contracts, including a state enumeration for better status handling.

Copy link

vercel bot commented Feb 9, 2025

@Jagadeeshftw is attempting to deploy a commit to the kindfi Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Feb 9, 2025

Walkthrough

A new SQL migration file is introduced that creates an ENUM type, escrow_state, and a corresponding escrow_contracts table. The table includes various fields such as id, engagement_id, contract_id, foreign keys for project_id and contribution_id, numeric amount with precision and a check constraint, current_state, timestamps, and metadata. This migration file supports sequential deployments in the Supabase local environment and applies standard constraints as per the defined configuration.

Changes

File Change Summary
services/supabase/…/20250209100653_create_escrow_contract_table.sql Added SQL migration to create the escrow_contracts table and escrow_state ENUM. Includes primary keys, unique constraints, foreign keys, amount validation, default timestamp values, and a metadata JSONB field.

Assessment against linked issues

Objective Addressed Explanation
Create Escrow Contract Table, support sequential migrations, and apply basic table configuration (#91)
Update EscrowContract TypeScript definitions across the webapp (#91) TypeScript definitions are not updated in this PR.

Possibly related PRs

  • feat: Implement Escrow Initialization API Endpoint #48 #86: The changes in the main PR, which create a new table escrow_contracts and define an enumeration type escrow_state, are directly related to the retrieved PR, as it also defines an EscrowState type and utilizes the escrow_contracts table structure in its API for initializing escrow contracts.

Suggested reviewers

  • AndlerRL

Poem

In the realm of code where tables align,
A new migration comes to shine.
ENUMs and constraints take their place,
Guiding data with style and grace.
Cheers to progress and structured design 🎉!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83d49e4 and 5241fc2.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • services/supabase/migrations/20250209100653_create_escrow_contract_table.sql (1 hunks)
🔇 Additional comments (1)
services/supabase/migrations/20250209100653_create_escrow_contract_table.sql (1)

1-2: Well-defined ENUM creation for escrow_state
You’ve clearly defined a custom ENUM type for escrow_state with the essential states. Consider adding a brief comment (or documentation) to explain the purpose of each status (i.e., when to use 'NEW', 'ACTIVE', and 'CANCELLED') for future clarity.

@Jagadeeshftw
Copy link
Collaborator Author

@AndlerRL Where I need to update EscrowContract TypeScript definitions

can you add more info?

@AndlerRL
Copy link
Member

@AndlerRL Where I need to update EscrowContract TypeScript definitions

can you add more info?

@Jagadeeshftw there is already indications in the README.md file within the supabase service folder. These TS ensures that table and permissions has been done successfully.

PD: Did you add the RLS policies? I don't see them in the changes. Additionally, I see that your commits are not signed, please sign them to adhere to our How to contribute policies. Thanks 🙏

package-lock.json Outdated Show resolved Hide resolved
@coderabbitai coderabbitai bot added documentation Improvements or additions to documentation enhancement New feature improvement or request webapp web app related labels Feb 10, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5241fc2 and 0d97fdc.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • services/supabase/migrations/20250209100653_create_escrow_contract_table.sql (1 hunks)
🔇 Additional comments (6)
services/supabase/migrations/20250209100653_create_escrow_contract_table.sql (6)

1-2: Enum Creation is Clean.
The escrow_state enum is defined clearly with the expected values. Consider adding a brief inline comment about its purpose to help future maintainers understand when and how to extend it if needed.


5-6: Unique Identifiers Defined.
The engagement_id and contract_id fields are properly set as UNIQUE and NOT NULL, which helps enforce the uniqueness of these domain-specific identifiers.


7-8: Foreign Keys and Referential Integrity.
The project_id and contribution_id columns correctly reference their respective tables. It’s a good idea to double-check that the referenced columns in the projects and contributions tables use UUIDs to ensure type consistency.


11-12: Amount and State Configuration.
The amount field is defined with sufficient precision and is later validated by the check constraint (ensuring it is positive). The current_state column leverages the escrow_state enum with a default of 'NEW', aligning well with expected behavior.


17-17: Metadata Field Implementation.
The metadata field, defined as JSONB with a default of an empty JSON object, is a good choice for future extensibility and flexible data storage.


18-18: Amount Check Constraint.
The check constraint on amount (ensuring it is greater than 0) effectively reinforces data integrity for escrow amounts.

CREATE TYPE IF NOT EXISTS escrow_state AS ENUM ('NEW','ACTIVE','CANCELLED');

CREATE TABLE IF NOT EXISTS escrow_contracts (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

UUID Generation Dependency.
The primary key uses uuid_generate_v4(), which is great for ensuring unique identifiers. However, please ensure that the PostgreSQL extension (typically uuid-ossp) is enabled in your database setup or a prior migration to avoid runtime issues.

Comment on lines +9 to +10
payer_address TEXT NOT NULL,
receiver_address TEXT NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Address Fields Verification.
The payer_address and receiver_address fields are defined as TEXT and are mandated as NOT NULL. If there are business rules regarding the format or maximum length of these addresses, consider implementing those validations at the application layer or via an additional check constraint.

receiver_address TEXT NOT NULL,
amount NUMERIC(20,7) NOT NULL,
current_state escrow_state NOT NULL DEFAULT 'NEW',
platform_fee NUMERIC(5,2) NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Platform Fee Constraint Suggestion.
The platform_fee column is defined with a fixed precision, which is appropriate; however, it currently lacks a check constraint to ensure a non-negative value (or to enforce any business-specific upper bounds). Consider adding a constraint if such validations are required.

Comment on lines +14 to +15
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Timestamp Columns Reminder.
Both the created_at and updated_at fields default to CURRENT_TIMESTAMP, which is useful for record creation. Do note that the updated_at column will not automatically update on record modifications. If automatic timestamp updates upon changes are desired, consider implementing a trigger or handling this update within the application logic.

Comment on lines 3 to 19
CREATE TABLE IF NOT EXISTS escrow_contracts (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
engagement_id TEXT UNIQUE NOT NULL,
contract_id TEXT UNIQUE NOT NULL,
project_id UUID NOT NULL REFERENCES projects(id),
contribution_id UUID NOT NULL REFERENCES contributions(id),
payer_address TEXT NOT NULL,
receiver_address TEXT NOT NULL,
amount NUMERIC(20,7) NOT NULL,
current_state escrow_state NOT NULL DEFAULT 'NEW',
platform_fee NUMERIC(5,2) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
completed_at TIMESTAMP WITH TIME ZONE,
metadata JSONB DEFAULT '{}'::jsonb,
CONSTRAINT valid_escrow_amount CHECK (amount > 0)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Row Level Security (RLS) Policies Missing.
It appears that no Row Level Security (RLS) policies are applied to the escrow_contracts table. If this table contains sensitive contract details, consider adding RLS policies in this migration or in a subsequent one to enforce fine-grained access control.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
services/supabase/migrations/20250209100653_create_escrow_contract_table.sql (1)

3-20: Table Schema and Field Constraints Review.
The escrow_contracts table is structured with thoughtful constraints and data types:

  • The primary key on id uses uuid_generate_v4(); as mentioned in previous reviews, please ensure that the necessary PostgreSQL extension (uuid-ossp) is enabled.
  • Unique constraints on engagement_id and contract_id help maintain data integrity; if the business logic prescribes a specific format for these identifiers, consider adding application-level validations.
  • Foreign key references on project_id and contribution_id are correctly defined; review whether cascading actions (e.g., ON DELETE CASCADE) are desired based on relational consistency rules.
  • The address fields (payer_address and receiver_address) are marked as NOT NULL. Similar to past feedback, if there are specific format or length requirements, adding a check constraint or handling these validations at the application layer might be beneficial.
  • Numeric fields such as amount and platform_fee include check constraints (ensuring amount > 0 and platform_fee >= 0), which is excellent for data integrity.
  • Timestamp fields use CURRENT_TIMESTAMP as default; note that while created_at is auto-populated at creation, updated_at will not update on subsequent modifications unless managed by a trigger or application logic. Consider implementing an automatic update mechanism if that behavior is desired.
    Overall, the table design aligns well with the migration objectives.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d97fdc and 7936d9e.

📒 Files selected for processing (1)
  • services/supabase/migrations/20250209100653_create_escrow_contract_table.sql (1 hunks)

Comment on lines +22 to +29
-- Enable Row Level Security (RLS) on the table
ALTER TABLE escrow_contracts ENABLE ROW LEVEL SECURITY;

-- RLS Policy: allow read access to all
CREATE POLICY public_select_escrow_contracts
ON escrow_contracts
FOR SELECT
USING (true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Row Level Security (RLS) and Policy Configuration.
Enabling RLS on the escrow_contracts table and defining a public SELECT policy is a strong move towards enhancing the security posture of the data. Consider reviewing future needs to determine if additional policies—for INSERT, UPDATE, or DELETE operations—are required as the business logic evolves.

@Jagadeeshftw
Copy link
Collaborator Author

@AndlerRL Could you please review the PR when you get a chance? Let me know if any changes are needed. Thanks!

Copy link

vercel bot commented Feb 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kindfi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 11, 2025 7:57am

Copy link
Member

@AndlerRL AndlerRL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for signing your commits 🙏 I see the SQL looks good, I noticed that supabase CI/CD did not triggered (was sleeping) so I am not marking them as resolved the coderabbitai observations yet until it triggers, and also because I found that there are no new TS definitions within the services/supabase folder. Make sure to follow step 3 from the related readme. After that and triggering successfull the supabase CI/CD (when changes has been made within the folder), we are good to go!

@AndlerRL
Copy link
Member

AndlerRL commented Feb 13, 2025

Hey @Jagadeeshftw checking the PR I noticed this is a fork merge. According to our How to Contribute guide from our development guides, we have to create a branch based on the develop branch. Also I double-check your access, you should have a new invitation now. We will need to close this PR and open a new one with the updated branch. I will keep this one open so you have it as reference but close it once you finish.

Also remember the rest of the observations. Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature improvement or request webapp web app related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Escrow Contract Table
2 participants