Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

Remove Postgres VARCHAR in favor of TEXT with check constraint #149

Closed Jaymon closed 1 year ago

Jaymon commented 1 year ago

So instead of VARCHAR(256) I would do:

<COLNAME> TEXT NOT NULL CHECK (length(<COLNAME>) <= 256)

You can also easily modify the checks:

ALTER TABLE <TABLE NAME> ADD CONSTRAINT <CONSTRAINT-NAME> CHECK (length(<COLNAME>) <= 128)

This should work in both SQLite and Postgres. CHECK constraints can also be more involved like regexes and stuff

Links

Search