beam icon indicating copy to clipboard operation
beam copied to clipboard

Composite column constraints

Open dciug opened this issue 4 years ago • 1 comments

Is there any way to add constraints to column composites? For example, I'd like to impose a uniqueness constraint to a pair of columns directly in Beam. Should I just delegate this to raw SQL commands?

CREATE TABLE someTable  (
    id serial PRIMARY KEY,
    col1 int NOT NULL,
    col2 int NOT NULL,
    UNIQUE (col1, col2)
)

I can get around it for now by making it a composite primary key, but I really don't want to do that.

Thanks

dciug avatar Feb 15 '21 20:02 dciug

Beam exists at a higher level than most constraint systems. Beam-core is ultimately a system for managing the queries issued to a database. The constraints the database follows are a secondary interest item. The primary key system exists mainly as a convenience.

You should use proper SQL change management tooling to manage your DDLs. Beam-migrate has some support for this, but is not totally complete. Beam-migrate does not support arbitrary constraints yet.

Beam will respect UNIQUE constraints in the sense that attempting to insert duplicates into a table with UNIQUE constraints will result in a DB exception, which beam should correctly propagate.

Does that make sense?

tathougies avatar Mar 08 '21 21:03 tathougies