-
Notifications
You must be signed in to change notification settings - Fork 1
Bugfix/workspace navigation v2 | Refactor metadata flow and simplify workspace logic #598
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
Changes from 21 commits
79a58ef
da775f9
235fe8e
a2f3b80
133cb74
2c5d35f
1598bb3
379cc6b
0a34914
47b7139
264fe8c
559553a
4aee8b7
29b9479
7778cb6
8c81d60
fb84c4a
b8c8043
eabbf5c
ccd6b28
af0f6fe
7fe730e
b9e701c
0dbfa66
7e17ada
518347f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ insert_permissions: | |
| - favorite | ||
| - font_size | ||
| - lang | ||
| - latest_organization | ||
| - preferred_complexity | ||
| - preferred_length | ||
| - preferred_tone | ||
|
|
@@ -38,13 +39,14 @@ insert_permissions: | |
| check: | ||
| user_id: | ||
| _eq: X-Hasura-User-Id | ||
| set: | ||
| user_id: X-Hasura-User-Id | ||
| set: | ||
| user_id: X-Hasura-User-Id | ||
| columns: | ||
| - deep_expertise | ||
| - favorite | ||
| - font_size | ||
| - lang | ||
| - latest_organization | ||
| - preferred_complexity | ||
| - preferred_length | ||
| - preferred_tone | ||
|
|
@@ -56,17 +58,7 @@ select_permissions: | |
| - role: anonymous | ||
| permission: | ||
| columns: | ||
| - deep_expertise | ||
| - favorite | ||
| - font_size | ||
| - lang | ||
| - preference_id | ||
| - preferred_complexity | ||
| - preferred_length | ||
| - preferred_tone | ||
| - preferred_type | ||
| - user_id | ||
| - web_search | ||
| filter: {} | ||
| comment: "" | ||
| - role: moderator | ||
|
|
@@ -76,6 +68,7 @@ select_permissions: | |
| - favorite | ||
| - font_size | ||
| - lang | ||
| - latest_organization | ||
| - preference_id | ||
| - preferred_complexity | ||
| - preferred_length | ||
|
|
@@ -92,14 +85,17 @@ select_permissions: | |
| - favorite | ||
| - font_size | ||
| - lang | ||
| - latest_organization | ||
| - preference_id | ||
| - preferred_complexity | ||
| - preferred_length | ||
| - preferred_tone | ||
| - preferred_type | ||
| - user_id | ||
| - web_search | ||
| filter: {} | ||
| filter: | ||
| user_id: | ||
| _eq: X-Hasura-User-Id | ||
| comment: "" | ||
| update_permissions: | ||
| - role: moderator | ||
|
|
@@ -109,10 +105,12 @@ update_permissions: | |
| - favorite | ||
| - font_size | ||
| - lang | ||
| - latest_organization | ||
| - preferred_complexity | ||
| - preferred_length | ||
| - preferred_tone | ||
| - preferred_type | ||
| - user_id | ||
|
||
| - web_search | ||
| filter: {} | ||
| check: null | ||
|
|
@@ -124,10 +122,12 @@ update_permissions: | |
| - favorite | ||
| - font_size | ||
| - lang | ||
| - latest_organization | ||
| - preferred_complexity | ||
| - preferred_length | ||
| - preferred_tone | ||
| - preferred_type | ||
| - user_id | ||
| - web_search | ||
| filter: | ||
| user_id: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -- Could not auto-generate a down migration. | ||
| -- Please write an appropriate down migration for the SQL below: | ||
| -- alter table "public"."preference" add column "latest_organization" text | ||
| -- null; |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,2 @@ | ||||||||||||
| alter table "public"."preference" add column "latest_organization" text | ||||||||||||
| null; | ||||||||||||
|
Comment on lines
+1
to
+2
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add foreign key constraint to ensure referential integrity. The Apply this diff to add the constraint: alter table "public"."preference" add column "latest_organization" text
- null;
+ null constraint fk_preference_latest_organization
+ references "public"."organization"("name") on delete set null;Note: This assumes 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents🧩 Analysis chain🏁 Script executed: #!/bin/bash
# First, find all migration files to understand the schema
echo "=== Finding migration files ==="
find apps/hasura/migrations/masterbots -type f -name "*.sql" | head -20
echo -e "\n=== Checking organization table definition ==="
# Look for organization table creation
find apps/hasura/migrations/masterbots -type f -name "*.sql" -exec grep -l "create.*table.*organization" -i {} \;
echo -e "\n=== Searching for unique constraints on organization.name ==="
find apps/hasura/migrations/masterbots -type f -name "*.sql" -exec rg -l "unique.*name|unique.*constraint" {} \; | head -10Repository: bitcashorg/masterbots Length of output: 2602 🏁 Script executed: #!/bin/bash
# Search for references to organization in migration files
echo "=== Looking for foreign keys and references to organization ==="
find apps/hasura/migrations/masterbots -type f -name "*.sql" -exec rg -H "organization_id|references.*organization" {} \;
echo -e "\n=== Checking the preference table related migrations ==="
find apps/hasura/migrations/masterbots -type f -name "*preference*" | sortRepository: bitcashorg/masterbots Length of output: 1081 🏁 Script executed: #!/bin/bash
# Examine the migration file in question and surrounding files
echo "=== Migration file content ==="
cat apps/hasura/migrations/masterbots/1765857892283_alter_table_public_preference_add_column_latest_organization/up.sql
echo -e "\n=== Checking down migration ==="
cat apps/hasura/migrations/masterbots/1765857892283_alter_table_public_preference_add_column_latest_organization/down.sql 2>/dev/null || echo "No down migration found"
echo -e "\n=== Looking at preference table definition ==="
find apps/hasura/migrations/masterbots -type f -name "*preference*" | while read f; do echo "File: $f"; cat "$f"; echo "---"; doneRepository: bitcashorg/masterbots Length of output: 450 🏁 Script executed: #!/bin/bash
# Check for unique constraints on organization table specifically
echo "=== Organization table creation ==="
cat apps/hasura/migrations/masterbots/1761768880712_create_table_public_organization/up.sql
echo -e "\n=== Check for any constraints added to organization.name ==="
find apps/hasura/migrations/masterbots -type f -name "*.sql" -exec rg -H "organization.*name|alter.*organization" -A3 -B1 {} \;
echo -e "\n=== Search for all columns named 'organization' to see common patterns ==="
find apps/hasura/migrations/masterbots -type f -name "*.sql" -exec rg -H "\"organization\"" {} \; | head -30
echo -e "\n=== Check if latest_organization is used elsewhere ==="
rg -r "latest_organization" apps/hasura/migrations/masterbotsRepository: bitcashorg/masterbots Length of output: 3134 Use The Refactor to use an ID-based foreign key instead: alter table "public"."preference" add column "latest_organization_id" uuid
null constraint fk_preference_latest_organization
references "public"."organization"("organization_id") on delete set null;🤖 Prompt for AI Agents |
||||||||||||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ import { isProAuthorized } from '@/lib/auth-utils' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { PAGE_SIZE } from '@/lib/constants/hasura' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { generateMetadataFromSEO } from '@/lib/metadata' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { type RoleTypes, isAdminOrModeratorRole } from '@/lib/utils' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getThreads } from '@/services/hasura' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getThreads, getUserPreferences } from '@/services/hasura' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { PageProps } from '@/types' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { isTokenExpired } from 'mb-lib' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { Metadata } from 'next' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -36,10 +36,22 @@ export default async function IndexPage() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| redirect('/auth/signin') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data: userPreferences } = await getUserPreferences( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| session.user.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jwt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const latestOrganization = userPreferences?.latestOrganization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| organizationData: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| organization: userPreferences.latestOrganization, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { threads, count } = await getThreads({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jwt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userId: session?.user.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| limit: PAGE_SIZE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...latestOrganization, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data: userPreferences } = await getUserPreferences( | |
| session.user.id, | |
| jwt, | |
| ) | |
| const latestOrganization = userPreferences?.latestOrganization | |
| ? { | |
| organizationData: { | |
| organization: userPreferences.latestOrganization, | |
| }, | |
| } | |
| : {} | |
| const { threads, count } = await getThreads({ | |
| jwt, | |
| userId: session?.user.id, | |
| limit: PAGE_SIZE, | |
| ...latestOrganization, | |
| const { data: userPreferences, error } = await getUserPreferences( | |
| session.user.id, | |
| jwt, | |
| ) | |
| if (error) { | |
| console.error('Failed to fetch user preferences:', error) | |
| } | |
| const latestOrganization = userPreferences?.latestOrganization | |
| ? { | |
| organizationData: { | |
| organization: userPreferences.latestOrganization, | |
| }, | |
| } | |
| : {} | |
| const { threads, count } = await getThreads({ | |
| jwt, | |
| userId: session?.user.id, | |
| limit: PAGE_SIZE, | |
| ...latestOrganization, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Fragile relationship: references organization by name instead of ID.
This relationship maps
organization.name(text) topreference.latest_organization(text), which is fragile for the same reasons outlined in the migration review:If you refactor the migration to use
latest_organization_idinstead oflatest_organization, update this relationship accordingly:- name: organization_preference using: manual_configuration: column_mapping: - name: latest_organization + organization_id: latest_organization_id insertion_order: null remote_table: name: preference schema: public🤖 Prompt for AI Agents
🧩 Analysis chain
🏁 Script executed:
Repository: bitcashorg/masterbots
Length of output: 2115
🏁 Script executed:
Repository: bitcashorg/masterbots
Length of output: 1729
🏁 Script executed:
Repository: bitcashorg/masterbots
Length of output: 3958
🏁 Script executed:
Repository: bitcashorg/masterbots
Length of output: 47
🏁 Script executed:
rg -n "CREATE TABLE.*preference" --type sqlRepository: bitcashorg/masterbots
Length of output: 261
🏁 Script executed:
sed -n '61,120p' packages/mb-drizzle/src/drizzle/0000_pink_lionheart.sqlRepository: bitcashorg/masterbots
Length of output: 2011
🏁 Script executed:
cat -n apps/hasura/metadata/databases/masterbots/tables/public_organization.yaml | head -20Repository: bitcashorg/masterbots
Length of output: 672
🏁 Script executed:
rg -n "CREATE TABLE.*organization" --type sqlRepository: bitcashorg/masterbots
Length of output: 963
🏁 Script executed:
rg -n "latest_organization" --type sqlRepository: bitcashorg/masterbots
Length of output: 449
🏁 Script executed:
Repository: bitcashorg/masterbots
Length of output: 143
Change
organization_preferencefrom object_relationship to array_relationship.The
latest_organizationcolumn in the preference table has no unique constraint, allowing multiple preference records to share the same organization name. This creates a one-to-many relationship from organization to preferences, which must be modeled as anarray_relationshiprather thanobject_relationship. Anobject_relationshipwill only return the first matching preference, silently omitting others.Apply this change:
🤖 Prompt for AI Agents