Skip to content

Add domain support #434

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

Open
kyleconroy opened this issue Apr 5, 2020 · 2 comments
Open

Add domain support #434

kyleconroy opened this issue Apr 5, 2020 · 2 comments
Labels
📚 postgresql enhancement New feature or request

Comments

@kyleconroy
Copy link
Collaborator

A domain is "essentially a data type with optional constraints". You can think of them as type aliases. By using a domain, you can easily create custom types. For example, here's how you could create a KSUID type.

CREATE DOMAIN ksuid AS VARCHAR(27) NOT NULL;

CREATE TABLE foo (
    id ksuid PRIMARY KEY,
    created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE bar (
    id ksuid PRIMARY KEY,
    created_at TIMESTAMP DEFAULT NOW(),
    foo_id ksuid REFERENCES foo(id),
    name text NOT NULL,
    slug text NOT NULL UNIQUE
);

The advantage to using a domain is that you'd only need one entry in overrides

overrides:
  - db_type: "ksuid"
    go_type: "github.com/segmentio/ksuid.KSUID"

Replaces #418

@stepan-romankov
Copy link

This looks to be supported, except schema scoped domain types like
CREATE DOMAIN public.name TEXT NOT NULL;

@hectorj-thetreep
Copy link

except schema scoped domain

It seems to work too, you just have to include the scope in the db_type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 postgresql enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants