You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Ensure the table does not already exist to avoid errorsDROPTABLE IF EXISTS historical_quotas;
-- Create the table for storing historical quotasCREATETABLEIF NOT EXISTS historical_quotas (
id SERIALPRIMARY KEY,
user_id UUID NOT NULL,
quota_type VARCHAR(50) NOT NULL,
usage_value INTEGERNOT NULLCHECK (usage_value >=0),
recorded_at TIMESTAMPTZNOT NULL DEFAULT NOW(),
CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES profiles (id) ON DELETE CASCADE
);
-- Create an index to optimize querying by user_id/recorded_at/typeCREATEINDEXIF NOT EXISTS idx_historical_quotas_recorded_at
ON historical_quotas (recorded_at);
CREATEINDEXIF NOT EXISTS idx_historical_quotas_user_id
ON historical_quotas (user_id);
CREATEINDEXIF NOT EXISTS idx_historical_quotas_quota_type
ON historical_quotas (quota_type);
-- Enable row-level security on the historical_quotas tableALTERTABLE historical_quotas ENABLE ROW LEVEL SECURITY;
-- Policy to allow users to read their own historical quota data
CREATE POLICY "User can read their own historical quota data."ON historical_quotas FOR SELECT
USING ( (SELECTauth.uid()) = user_id );
Originally posted by @ItWasEnder in #88
The text was updated successfully, but these errors were encountered: