added supabase migration file for youtube stats, added validation schemas#146
Open
GauravOP-03 wants to merge 2 commits intoscriptaiapp:mainfrom
Open
added supabase migration file for youtube stats, added validation schemas#146GauravOP-03 wants to merge 2 commits intoscriptaiapp:mainfrom
GauravOP-03 wants to merge 2 commits intoscriptaiapp:mainfrom
Conversation
…ema to resue on frontend as well as backend
Contributor
|
@GauravOP-03 is attempting to deploy a commit to the afrin127329's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Introduce shared billing and YouTube stats schema between backend and frontend via
@repo/validation, and add Supabase migrations + functions to enforce plan-based usage limits at the database layer. This PR wires up typed models and quota-aware SQL functions so that both the API and web app can consume the same schema for billing, channel analytics, and feature usage.🎯 Type of Change
🧪 Testing
(Describe briefly what you ran, e.g. Supabase migration locally + key flows on dashboard.)
📋 Checklist
📸 Screenshots (if applicable)
Before:
No shared billing/stats schema between backend and frontend; no plan-based quota functions in DB.
After:
Billing and YouTube stats types exported from
@repo/validation; DB now exposesuse_featureandget_feature_usagefor plan-aware limits.(You can add real UI screenshots here if you changed any dashboard pages.)
🔧 Technical Details
Shared schema for billing and usage
BillingTypesandYoutubeStatsTypesto@repo/validationand re-exported them fromsrc/index.tsso both backend and frontend can import the same types.BillingTypesmodelsPlan,SubscriptionInfo, andBillingInfoin a way that matches our Stripe + Supabase billing domain.YoutubeStatsTypesmodels YouTube channel/profile data plus analytics and quota-related fields (e.g.daily_limit,usage_count,remaining,cooldown_minutes,cooldown_remaining,can_use_now), which match what we now persist in Supabase and return from the stats endpoints.Supabase package and CLI usage
@repo/supabasepackage.jsonto be the central place for Supabase tooling:supabase:dev,supabase:init,supabase:link,supabase:pull,supabase:push.Database schema changes (
20260224185424_plans_v2.sql)planstable:daily_limit int NOT NULL DEFAULT 5andcooldown_minutes int NOT NULL DEFAULT 60.youtube_channelstable:top_videos jsonb,recent_videos jsonb,youtube_trained_videos jsonb.last_synced_at timestamptzfor when we last pulled stats from YouTube.last_used_at timestamptz,usage_count int NOT NULL DEFAULT 0,usage_reset_date date NOT NULL DEFAULT CURRENT_DATE.DB functions for feature usage
use_feature(p_user_id uuid) RETURNS jsonsubscriptions→plans(with a fallback to thestarterplan).youtube_channels(usage_count,last_used_at,usage_reset_date).usage_reset_dateis before today.last_used_at<cooldown_minutes, returns JSON withallowed: false,reason: 'cooldown',minutes_remaining, and plan info.usage_count >= daily_limit, returns JSON withallowed: false,reason: 'daily_limit',usage_count,daily_limit,remaining: 0.youtube_channels:usage_count = 1, otherwise increments by 1.usage_reset_date = CURRENT_DATEandlast_used_at = NOW().allowed,plan,usage_count,remaining,daily_limit,cooldown_minutes, and a human-readablemessage.allowedand handle the returnedreason/message.get_feature_usage(p_user_id uuid) RETURNS jsonuse_feature.usage_count,last_used_at,usage_reset_datefromyoutube_channels.usage_reset_dateis null or before today.remaining = max(daily_limit - usage_count, 0).cooldown_remainingin minutes based oncooldown_minutesand time sincelast_used_at.can_use_now = (cooldown_remaining < 0.01) AND (usage_count < daily_limit).plan,usage_count,remaining,daily_limit,cooldown_minutes,cooldown_remaining,can_use_now.get_feature_usageis for reading,use_featureis for consuming quota.Schema reuse across frontend and backend
@repo/validationfor:Plan,SubscriptionInfo,BillingInfo).UserProfile,Script,ChannelStatsVideo,ChannelStats, including quota fields).use_feature,get_feature_usage) and the dashboard components, so changes in the schema are enforced at compile time on both sides.🚀 Deployment Notes
pnpm --filter @repo/supabase supabase:push(or your normal migration pipeline).supabase:linkbefore running migrations.📚 Documentation Updates
@repo/supabasescripts and shared validation types)(You can tick/untick depending on what you actually change.)
🔍 Review Notes
use_featureandget_feature_usagelogic (especially edge cases around day rollovers and multiple plans).📊 Performance Impact
Details:
top_videos,recent_videos,youtube_trained_videos) avoids recomputing heavy stats for every request.🔒 Security Considerations
Details:
SECURITY DEFINERbut operate only on the current user’suser_idrow; they do not expose any new public data.🎉 Additional Notes
plansrows) or localized to the two PL/pgSQL functions.