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

Fix table editor unable to update PK after renaming table #21285

Conversation

joshenlim
Copy link
Member

Resolves #19341

@joshenlim joshenlim requested a review from a team as a code owner February 15, 2024 08:58
Copy link

vercel bot commented Feb 15, 2024

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

Name Status Preview Comments Updated (UTC)
studio-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2024 6:21am
6 Ignored Deployments
Name Status Preview Comments Updated (UTC)
database-new ⬜️ Ignored (Inspect) Feb 26, 2024 6:21am
docs ⬜️ Ignored (Inspect) Visit Preview Feb 26, 2024 6:21am
studio ⬜️ Ignored (Inspect) Visit Preview Feb 26, 2024 6:21am
studio-self-hosted ⬜️ Ignored (Inspect) Visit Preview Feb 26, 2024 6:21am
ui-storybook ⬜️ Ignored (Inspect) Feb 26, 2024 6:21am
zone-www-dot-com ⬜️ Ignored (Inspect) Visit Preview Feb 26, 2024 6:21am

Copy link

supabase bot commented Feb 15, 2024

Updates to Preview Branch (chore/fix-table-editor-unable-to-update-PK-after-renaming-table) ↗︎

Deployments Status Updated
Database Mon, 26 Feb 2024 06:18:52 GMT
Services Mon, 26 Feb 2024 06:18:52 GMT
APIs Mon, 26 Feb 2024 06:18:52 GMT

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Migrations Mon, 26 Feb 2024 06:18:52 GMT
Seeding Mon, 26 Feb 2024 06:18:52 GMT

⚠️ Warning — Preview branch version (15.1.1.16) does not match production database version (15.1.0.33).


Connecting to this Preview Branch
URL
Database https://supabase.com/dashboard/project/pzvkfbvzvdywzlpfirvp/settings/database ↗︎
REST https://pzvkfbvzvdywzlpfirvp.supabase.co/rest/v1
GraphQL https://pzvkfbvzvdywzlpfirvp.supabase.co/graphql/v1

Branching Preview Branches by Supabase.
Learn more about Supabase for Git ↗︎

}: {
projectRef: string
connectionString: string | undefined
payload: CreateColumnPayload
selectedTable: PostgresTable
primaryKey?: Constraint
Copy link
Member

Choose a reason for hiding this comment

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

Why pass in the primary key when it's available on selectedTable.primary_keys?

Copy link
Member Author

Choose a reason for hiding this comment

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

selectedTable.primary_keys from Postgrest is not in the format we need unfortunately
image

its missing the PK constraint name

image

and also doesnt deal with composite keys very well

hence why we've got a separate parameter to handle that

Copy link
Member

@alaister alaister left a comment

Choose a reason for hiding this comment

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

LGTM!

{
enabled: typeof schema !== 'undefined' && typeof table !== 'undefined',
select(data) {
return ((data as any)?.result ?? []).map((constraint: Constraint) => constraint)
Copy link
Member

Choose a reason for hiding this comment

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

Does this do the same thing? The map isn't doing anything apart from adding types

Suggested change
return ((data as any)?.result ?? []).map((constraint: Constraint) => constraint)
return ((data as any)?.result ?? []) as Constraint[]

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure why but TS is complaining 😕

image

Copy link
Member

Choose a reason for hiding this comment

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

hmm maybe the whole map can just be removed entirely then?

Copy link
Member Author

@joshenlim joshenlim Feb 26, 2024

Choose a reason for hiding this comment

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

unless we rewrite it like this?

export const useTableConstraintsQuery = (
  { projectRef, connectionString, schema, table }: TableConstraintsVariables,
  options: UseQueryOptions<ExecuteSqlData, TableConstraintsError, Constraint[]> = {}
) => {
  return useExecuteSqlQuery(
    {
      projectRef,
      connectionString,
      sql: getTableConstraints({ schema, table }),
      queryKey: ['table-constraints'],
    },
    {
      enabled: typeof schema !== 'undefined' && typeof table !== 'undefined',
      select(data) {
        return ((data as any)?.result ?? []) as Constraint[]
      },
      ...options,
    }
  )
}

Copy link
Member Author

@joshenlim joshenlim Feb 26, 2024

Choose a reason for hiding this comment

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

hmm maybe the whole map can just be removed entirely then?

oh 🤦 that worked hahaha sorry not sure why i was overcomplicating things haha

@joshenlim joshenlim enabled auto-merge (squash) February 26, 2024 06:16
@joshenlim joshenlim merged commit dcdc3cd into master Feb 26, 2024
15 of 16 checks passed
@joshenlim joshenlim deleted the chore/fix-table-editor-unable-to-update-PK-after-renaming-table branch February 26, 2024 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to update table PK via dashboard after renaming table
3 participants