Coder Social home page Coder Social logo

Feature: Add constraints about postgres-meta HOT 8 OPEN

supabase avatar supabase commented on August 26, 2024 14
Feature: Add constraints

from postgres-meta.

Comments (8)

juanzgc avatar juanzgc commented on August 26, 2024 7

Unique constraints seem to have been added in the view when creating a new table but not in the update a column view or create a new column view. Would be very helpful to add this feature in those two views as well.

Note: I've included a few bugs around this as well in the following issue. supabase/supabase#592 (comment)

from postgres-meta.

DocLabyrinth avatar DocLabyrinth commented on August 26, 2024 6

Could it be possible to allow for uniqueness across multiple columns e.g. if you have a table for storing a user's contact details/socials where the columns look something like id (int), user_id (int, foreign key), type (varchar), value (varchar). In that case you'd want to have unique(user_id, type) as a constraint so it wouldn't be possible to add duplicate values for the same type of contact info.

In the UI there's already similar functionality for marking fields as part of the primary key using check boxes. Could it be possible to provide a similar UI for selecting values to be part of a unique constraint? The only downside to that approach would be that it'd only work for one unique constraint per table when I think postgres allows more than one.

from postgres-meta.

suragch avatar suragch commented on August 26, 2024 1

Here is a way to manually add a unique constraint on two columns:

  1. Open the SQL editor
  2. Click "New query"
  3. Add the following:
alter table mytable
add constraint unique_col1_col2 unique (col1, col2);
  1. Click "Run"

If there are any duplicate rows, you'll have to delete those first before the query will take effect.

from postgres-meta.

wasabigeek avatar wasabigeek commented on August 26, 2024

Hi! I was thinking of taking a stab at this for columns, but wasn’t exactly sure what interface would be desirable. I see there's already a few constraint options (like is_unique) in https://github.com/supabase/postgres-meta/blob/develop/src/lib/PostgresMetaColumns.ts, so would this be about allowing a user to specify a generic definition as free text when creating a column?

from postgres-meta.

kiwicopple avatar kiwicopple commented on August 26, 2024

Yeah, in this case we want to start with something as generic as possible, then we can add more specific functionality for anything which isn't covered 👍

would love any contributions!

from postgres-meta.

soedirgo avatar soedirgo commented on August 26, 2024

UI stuff aside: yes, we can make constraints be defined on tables the same way e.g. policies and primary keys are. The idea for this feature is for it to be the solution for all kinds of table constraints, including primary keys and UNIQUEs.

from postgres-meta.

jojomatik avatar jojomatik commented on August 26, 2024

UI stuff aside: yes, we can make constraints be defined on tables the same way e.g. policies and primary keys are. The idea for this feature is for it to be the solution for all kinds of table constraints, including primary keys and UNIQUEs.

I don't quite fully understand, is it planned to add an UI option to add unique constraints across multiple columns?

I'd also like to be able to do what @DocLabyrinth requests :)

from postgres-meta.

soedirgo avatar soedirgo commented on August 26, 2024

This repo is decoupled from the UI - the UI can do ad-hoc queries and thus can support multi-columns constraints, but ideally this would be handled from a dedicated endpoint (e.g. /constraints).

from postgres-meta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.