mirror of
https://github.com/StanGirard/quivr.git
synced 2024-11-23 12:26:03 +03:00
feat: add onboarding_a column to onboarding table (#1340)
https://github.com/StanGirard/quivr/issues/1338 <img width="1215" alt="Screenshot 2023-10-05 at 18 05 30" src="https://github.com/StanGirard/quivr/assets/63923024/67562c50-ddc1-4eaa-8b68-d374b2eb4b67">
This commit is contained in:
parent
f13f08c5c5
commit
16cea2c86b
@ -12,14 +12,19 @@ class OnboardingUpdatableProperties(BaseModel):
|
||||
|
||||
"""Properties that can be received on onboarding update"""
|
||||
|
||||
onboarding_a: Optional[bool]
|
||||
onboarding_b1: Optional[bool]
|
||||
onboarding_b2: Optional[bool]
|
||||
onboarding_b3: Optional[bool]
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
class GetOnboardingResponse(BaseModel):
|
||||
|
||||
class OnboardingStates(BaseModel):
|
||||
"""Response when getting onboarding"""
|
||||
|
||||
onboarding_a: bool
|
||||
onboarding_b1: bool
|
||||
onboarding_b2: bool
|
||||
onboarding_b3: bool
|
||||
@ -29,13 +34,18 @@ class Onboarding(Repository):
|
||||
def __init__(self, supabase_client):
|
||||
self.db = supabase_client
|
||||
|
||||
def get_user_onboarding(self, user_id: UUID) -> GetOnboardingResponse | None:
|
||||
def get_user_onboarding(self, user_id: UUID) -> OnboardingStates | None:
|
||||
"""
|
||||
Get user onboarding information by user_id
|
||||
"""
|
||||
onboarding_data = (
|
||||
self.db.from_("onboarding")
|
||||
.select("user_id", "onboarding_b1", "onboarding_b2", "onboarding_b3")
|
||||
self.db.from_("onboardings")
|
||||
.select(
|
||||
"onboarding_a",
|
||||
"onboarding_b1",
|
||||
"onboarding_b2",
|
||||
"onboarding_b3",
|
||||
)
|
||||
.filter("user_id", "eq", user_id)
|
||||
.limit(1)
|
||||
.execute()
|
||||
@ -44,15 +54,19 @@ class Onboarding(Repository):
|
||||
if onboarding_data == []:
|
||||
return None
|
||||
|
||||
return GetOnboardingResponse(**onboarding_data[0])
|
||||
return OnboardingStates(**onboarding_data[0])
|
||||
|
||||
def update_user_onboarding(
|
||||
self, user_id: UUID, onboarding: OnboardingUpdatableProperties
|
||||
) -> GetOnboardingResponse:
|
||||
) -> OnboardingStates:
|
||||
"""Update user onboarding information by user_id"""
|
||||
update_data = {
|
||||
key: value for key, value in onboarding.dict().items() if value is not None
|
||||
}
|
||||
|
||||
response = (
|
||||
self.db.from_("onboarding")
|
||||
.update(onboarding.dict())
|
||||
self.db.from_("onboardings")
|
||||
.update(update_data)
|
||||
.match({"user_id": user_id})
|
||||
.execute()
|
||||
.data
|
||||
@ -61,4 +75,4 @@ class Onboarding(Repository):
|
||||
if not response:
|
||||
raise HTTPException(404, "User onboarding not updated")
|
||||
|
||||
return GetOnboardingResponse(**response[0])
|
||||
return OnboardingStates(**response[0])
|
||||
|
@ -1,10 +0,0 @@
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Onboardings(BaseModel):
|
||||
user_id: UUID
|
||||
onboarding_b1: bool
|
||||
onboarding_b2: bool
|
||||
onboarding_b3: bool
|
@ -1,10 +1,10 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.databases.supabase.onboarding import GetOnboardingResponse
|
||||
from models.databases.supabase.onboarding import OnboardingStates
|
||||
from models.settings import get_supabase_db
|
||||
|
||||
|
||||
def get_user_onboarding(user_id: UUID) -> GetOnboardingResponse | None:
|
||||
def get_user_onboarding(user_id: UUID) -> OnboardingStates | None:
|
||||
"""
|
||||
Get a user's onboarding status
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
from uuid import UUID
|
||||
|
||||
from models.databases.supabase.onboarding import (
|
||||
GetOnboardingResponse,
|
||||
OnboardingStates,
|
||||
OnboardingUpdatableProperties,
|
||||
)
|
||||
from models.settings import get_supabase_db
|
||||
@ -9,7 +9,7 @@ from models.settings import get_supabase_db
|
||||
|
||||
def update_user_onboarding(
|
||||
user_id: UUID, onboarding: OnboardingUpdatableProperties
|
||||
) -> GetOnboardingResponse:
|
||||
) -> OnboardingStates:
|
||||
"""Update user onboarding information by user_id"""
|
||||
|
||||
supabase_db = get_supabase_db()
|
||||
|
@ -4,7 +4,7 @@ from auth import (
|
||||
)
|
||||
from fastapi import APIRouter, Depends
|
||||
from models.databases.supabase.onboarding import (
|
||||
GetOnboardingResponse,
|
||||
OnboardingStates,
|
||||
OnboardingUpdatableProperties,
|
||||
)
|
||||
from models.user_identity import UserIdentity
|
||||
@ -21,7 +21,7 @@ onboarding_router = APIRouter()
|
||||
)
|
||||
async def get_user_onboarding_handler(
|
||||
current_user: UserIdentity = Depends(get_current_user),
|
||||
) -> GetOnboardingResponse | None:
|
||||
) -> OnboardingStates | None:
|
||||
"""
|
||||
Get user onboarding information for the current user
|
||||
"""
|
||||
@ -37,7 +37,7 @@ async def get_user_onboarding_handler(
|
||||
async def update_user_onboarding_handler(
|
||||
onboarding: OnboardingUpdatableProperties,
|
||||
current_user: UserIdentity = Depends(get_current_user),
|
||||
) -> GetOnboardingResponse:
|
||||
) -> OnboardingStates:
|
||||
"""
|
||||
Update user onboarding information for the current user
|
||||
"""
|
||||
|
@ -1,8 +1,8 @@
|
||||
-- Create the onboarding table
|
||||
CREATE TABLE IF NOT EXISTS onboardings (
|
||||
user_id UUID NOT NULL REFERENCES auth.users (id),
|
||||
onboarding_b1 BOOLEAN NOT NULL DEFAULT false,
|
||||
onboarding_b2 BOOLEAN NOT NULL DEFAULT false,
|
||||
onboarding_b3 BOOLEAN NOT NULL DEFAULT false,
|
||||
onboarding_b1 BOOLEAN NOT NULL DEFAULT true,
|
||||
onboarding_b2 BOOLEAN NOT NULL DEFAULT true,
|
||||
onboarding_b3 BOOLEAN NOT NULL DEFAULT true,
|
||||
PRIMARY KEY (user_id)
|
||||
)
|
@ -0,0 +1,17 @@
|
||||
-- Check if onboarding_a column exists
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'onboardings' AND column_name = 'onboarding_a') THEN
|
||||
ALTER TABLE onboardings ADD COLUMN onboarding_a BOOLEAN NOT NULL DEFAULT true;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
COMMIT;
|
||||
|
||||
|
||||
-- Update migrations table
|
||||
INSERT INTO migrations (name)
|
||||
SELECT '20231005170000_add_onboarding_a_to_onboarding_table'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM migrations WHERE name = '20231005170000_add_onboarding_a_to_onboarding_table'
|
||||
);
|
@ -259,9 +259,10 @@ CREATE TABLE IF NOT EXISTS knowledge_vectors (
|
||||
-- Create the onboarding table
|
||||
CREATE TABLE IF NOT EXISTS onboardings (
|
||||
user_id UUID NOT NULL REFERENCES auth.users (id),
|
||||
onboarding_b1 BOOLEAN NOT NULL DEFAULT false,
|
||||
onboarding_b2 BOOLEAN NOT NULL DEFAULT false,
|
||||
onboarding_b3 BOOLEAN NOT NULL DEFAULT false,
|
||||
onboarding_a BOOLEAN NOT NULL DEFAULT true,
|
||||
onboarding_b1 BOOLEAN NOT NULL DEFAULT true,
|
||||
onboarding_b2 BOOLEAN NOT NULL DEFAULT true,
|
||||
onboarding_b3 BOOLEAN NOT NULL DEFAULT true,
|
||||
PRIMARY KEY (user_id)
|
||||
)
|
||||
|
||||
@ -279,9 +280,9 @@ CREATE POLICY "Access Quivr Storage 1jccrwz_2" ON storage.objects FOR UPDATE TO
|
||||
CREATE POLICY "Access Quivr Storage 1jccrwz_3" ON storage.objects FOR DELETE TO anon USING (bucket_id = 'quivr');
|
||||
|
||||
INSERT INTO migrations (name)
|
||||
SELECT '20231004150000_add_onboarding_table'
|
||||
SELECT '20231005170000_add_onboarding_a_to_onboarding_table'
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM migrations WHERE name = '20231004150000_add_onboarding_table'
|
||||
SELECT 1 FROM migrations WHERE name = '20231005170000_add_onboarding_a_to_onboarding_table'
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user