Skip to content

Add domain support #434

Open
Open

Description

@kyleconroy

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

Activity

  1. stepan-romankov commented on Jul 12, 2023

    @stepan-romankov

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

  2. hectorj-thetreep commented on Dec 8, 2023

    @hectorj-thetreep

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions