volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.66k stars 539 forks source link

Using array of enum values does not generate enum constants for Postgres #739

Open MorpheusXAUT opened 4 years ago

MorpheusXAUT commented 4 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v4.1.1

What is your database and version (eg. Postgresql 10)

PostgreSQL 12.2 (postgres:12.2-alpine Docker Image)

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler psql

If this happened at runtime what code produced the issue? (if not applicable leave blank)

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

using driver: /app/bin/sqlboiler-psql
{"config":{"driver_name":"psql","driver_config":{"blacklist":["migrations"],"dbname":"spec","host":"postgres","pass":"redacted","port":"5432","sslmode":"disable","user":"redacted","whitelist":null},"pkg_name":"models","out_folder":"internal/models","debug":true,"no_hooks":true,"wipe":true,"struct_tag_casing":"snake","relation_tag":"-","imports":{"all":{"Standard":["\"database/sql\"","\"fmt\"","\"reflect\"","\"strconv\"","\"strings\"","\"sync\"","\"time\"","\"context\""],"ThirdParty":["\"github.com/friendsofgo/errors\"","\"github.com/volatiletech/sqlboiler/v4/boil\"","\"github.com/volatiletech/sqlboiler/v4/queries\"","\"github.com/volatiletech/sqlboiler/v4/queries/qm\"","\"github.com/volatiletech/sqlboiler/v4/queries/qmhelper\"","\"github.com/volatiletech/strmangle\""]},"test":{"Standard":["\"bytes\"","\"reflect\"","\"testing\"","\"context\""],"ThirdParty":["\"github.com/volatiletech/randomize\"","\"github.com/volatiletech/sqlboiler/v4/boil\"","\"github.com/volatiletech/sqlboiler/v4/queries\"","\"github.com/volatiletech/strmangle\""]},"singleton":{"boil_queries":{"Standard":null,"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/drivers\"","\"github.com/volatiletech/sqlboiler/v4/queries\"","\"github.com/volatiletech/sqlboiler/v4/queries/qm\""]},"boil_types":{"Standard":["\"strconv\""],"ThirdParty":["\"github.com/friendsofgo/errors\"","\"github.com/volatiletech/sqlboiler/v4/boil\"","\"github.com/volatiletech/strmangle\""]},"psql_upsert":{"Standard":["\"fmt\"","\"strings\""],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/drivers\"","\"github.com/volatiletech/strmangle\""]}},"test_singleton":{"boil_main_test":{"Standard":["\"database/sql\"","\"flag\"","\"fmt\"","\"math/rand\"","\"os\"","\"path/filepath\"","\"strings\"","\"testing\"","\"time\""],"ThirdParty":["\"github.com/spf13/viper\"","\"github.com/volatiletech/sqlboiler/v4/boil\""]},"boil_queries_test":{"Standard":["\"bytes\"","\"fmt\"","\"io\"","\"io/ioutil\"","\"math/rand\"","\"regexp\""],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/boil\""]},"boil_suites_test":{"Standard":["\"testing\""],"ThirdParty":null},"psql_main_test":{"Standard":["\"bytes\"","\"database/sql\"","\"fmt\"","\"io\"","\"io/ioutil\"","\"os\"","\"os/exec\"","\"regexp\"","\"strings\""],"ThirdParty":["\"github.com/friendsofgo/errors\"","\"github.com/kat-co/vala\"","_ \"github.com/lib/pq\"","\"github.com/spf13/viper\"","\"github.com/volatiletech/randomize\"","\"github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql/driver\""]},"psql_suites_test":{"Standard":["\"testing\""],"ThirdParty":[]}},"based_on_type":{"null.Bool":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Bytes":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Float32":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Float64":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int16":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int32":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int64":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int8":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.JSON":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.String":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Time":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint16":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint32":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint64":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint8":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"pgeo.Box":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Circle":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Line":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Lseg":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullBox":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullCircle":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullLine":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullLseg":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullPath":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullPoint":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullPolygon":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Path":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Point":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Polygon":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"time.Time":{"Standard":["\"time\""],"ThirdParty":[]},"types.BoolArray":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.BytesArray":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.Decimal":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.DecimalArray":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.Float64Array":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.HStore":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.Int64Array":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.JSON":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.NullDecimal":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.StringArray":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]}}},"aliases":{"tables":{"users":{"up_plural":"Users","up_singular":"User","down_plural":"users","down_singular":"user","columns":{"created_at":"CreatedAt","id":"ID","is_active":"IsActive","password":"Password","scopes":"Scopes","updated_at":"UpdatedAt","username":"Username"}}}},"version":"4.1.1"},"driver_config":{"blacklist":["migrations"],"dbname":"spec","host":"postgres","pass":"redacted","port":"5432","sslmode":"disable","user":"redacted","whitelist":null},"schema":"public","dialect":{"lq":34,"rq":34,"use_index_placeholders":true,"use_last_insert_id":false,"use_schema":false,"use_default_keyword":true,"use_auto_columns":false,"use_top_clause":false,"use_output_clause":false,"use_case_when_exists_clause":false},"tables":[{"name":"users","schema_name":"","columns":[{"name":"id","type":"string","db_type":"uuid","default":"uuid_generate_v4()","nullable":false,"unique":true,"validated":false,"arr_type":null,"udt_name":"uuid","domain_name":null,"full_db_type":"uuid","auto_generated":false},{"name":"username","type":"null.String","db_type":"character varying","default":"","nullable":true,"unique":true,"validated":false,"arr_type":null,"udt_name":"varchar","domain_name":null,"full_db_type":"character varying(255)","auto_generated":false},{"name":"password","type":"null.String","db_type":"text","default":"","nullable":true,"unique":false,"validated":false,"arr_type":null,"udt_name":"text","domain_name":null,"full_db_type":"text","auto_generated":false},{"name":"is_active","type":"bool","db_type":"boolean","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"bool","domain_name":null,"full_db_type":"bool","auto_generated":false},{"name":"scopes","type":"types.StringArray","db_type":"ARRAYUSER-DEFINED","default":"'{app}'::user_scope[]","nullable":false,"unique":false,"validated":false,"arr_type":"USER-DEFINED","udt_name":"_user_scope","domain_name":null,"full_db_type":"_user_scope","auto_generated":false},{"name":"created_at","type":"time.Time","db_type":"timestamp with time zone","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"timestamptz","domain_name":null,"full_db_type":"timestamptz","auto_generated":false},{"name":"updated_at","type":"time.Time","db_type":"timestamp with time zone","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"timestamptz","domain_name":null,"full_db_type":"timestamptz","auto_generated":false}],"p_key":{"name":"users_pkey","columns":["id"]},"f_keys":null,"is_join_table":false,"to_one_relationships":null,"to_many_relationships":null}],"templates":[{"name":"templates/00_struct.go.tpl","loader":"asset:templates/00_struct.go.tpl"},{"name":"templates/01_types.go.tpl","loader":"asset:templates/01_types.go.tpl"},{"name":"templates/02_hooks.go.tpl","loader":"asset:templates/02_hooks.go.tpl"},{"name":"templates/03_finishers.go.tpl","loader":"asset:templates/03_finishers.go.tpl"},{"name":"templates/04_relationship_to_one.go.tpl","loader":"asset:templates/04_relationship_to_one.go.tpl"},{"name":"templates/05_relationship_one_to_one.go.tpl","loader":"asset:templates/05_relationship_one_to_one.go.tpl"},{"name":"templates/06_relationship_to_many.go.tpl","loader":"asset:templates/06_relationship_to_many.go.tpl"},{"name":"templates/07_relationship_to_one_eager.go.tpl","loader":"asset:templates/07_relationship_to_one_eager.go.tpl"},{"name":"templates/08_relationship_one_to_one_eager.go.tpl","loader":"asset:templates/08_relationship_one_to_one_eager.go.tpl"},{"name":"templates/09_relationship_to_many_eager.go.tpl","loader":"asset:templates/09_relationship_to_many_eager.go.tpl"},{"name":"templates/10_relationship_to_one_setops.go.tpl","loader":"asset:templates/10_relationship_to_one_setops.go.tpl"},{"name":"templates/11_relationship_one_to_one_setops.go.tpl","loader":"asset:templates/11_relationship_one_to_one_setops.go.tpl"},{"name":"templates/12_relationship_to_many_setops.go.tpl","loader":"asset:templates/12_relationship_to_many_setops.go.tpl"},{"name":"templates/13_all.go.tpl","loader":"asset:templates/13_all.go.tpl"},{"name":"templates/14_find.go.tpl","loader":"asset:templates/14_find.go.tpl"},{"name":"templates/15_insert.go.tpl","loader":"asset:templates/15_insert.go.tpl"},{"name":"templates/16_update.go.tpl","loader":"asset:templates/16_update.go.tpl"},{"name":"templates/17_upsert.go.tpl","loader":"base64:(sha256 of content): 397bf4cd7e448a0023fe2ecdf9b1c68065263280eb9b81966dfd356803fadd87"},{"name":"templates/18_delete.go.tpl","loader":"asset:templates/18_delete.go.tpl"},{"name":"templates/19_reload.go.tpl","loader":"asset:templates/19_reload.go.tpl"},{"name":"templates/20_exists.go.tpl","loader":"asset:templates/20_exists.go.tpl"},{"name":"templates/21_auto_timestamps.go.tpl","loader":"asset:templates/21_auto_timestamps.go.tpl"},{"name":"templates/singleton/boil_queries.go.tpl","loader":"asset:templates/singleton/boil_queries.go.tpl"},{"name":"templates/singleton/boil_table_names.go.tpl","loader":"asset:templates/singleton/boil_table_names.go.tpl"},{"name":"templates/singleton/boil_types.go.tpl","loader":"asset:templates/singleton/boil_types.go.tpl"},{"name":"templates/singleton/psql_upsert.go.tpl","loader":"base64:(sha256 of content): cb25b2a17877de034695accfb0a1f5f11437114d5f919062c792efee53cbb25f"},{"name":"templates_test/00_types.go.tpl","loader":"asset:templates_test/00_types.go.tpl"},{"name":"templates_test/all.go.tpl","loader":"asset:templates_test/all.go.tpl"},{"name":"templates_test/delete.go.tpl","loader":"asset:templates_test/delete.go.tpl"},{"name":"templates_test/exists.go.tpl","loader":"asset:templates_test/exists.go.tpl"},{"name":"templates_test/find.go.tpl","loader":"asset:templates_test/find.go.tpl"},{"name":"templates_test/finishers.go.tpl","loader":"asset:templates_test/finishers.go.tpl"},{"name":"templates_test/hooks.go.tpl","loader":"asset:templates_test/hooks.go.tpl"},{"name":"templates_test/insert.go.tpl","loader":"asset:templates_test/insert.go.tpl"},{"name":"templates_test/relationship_one_to_one.go.tpl","loader":"asset:templates_test/relationship_one_to_one.go.tpl"},{"name":"templates_test/relationship_one_to_one_setops.go.tpl","loader":"asset:templates_test/relationship_one_to_one_setops.go.tpl"},{"name":"templates_test/relationship_to_many.go.tpl","loader":"asset:templates_test/relationship_to_many.go.tpl"},{"name":"templates_test/relationship_to_many_setops.go.tpl","loader":"asset:templates_test/relationship_to_many_setops.go.tpl"},{"name":"templates_test/relationship_to_one.go.tpl","loader":"asset:templates_test/relationship_to_one.go.tpl"},{"name":"templates_test/relationship_to_one_setops.go.tpl","loader":"asset:templates_test/relationship_to_one_setops.go.tpl"},{"name":"templates_test/reload.go.tpl","loader":"asset:templates_test/reload.go.tpl"},{"name":"templates_test/select.go.tpl","loader":"asset:templates_test/select.go.tpl"},{"name":"templates_test/singleton/boil_main_test.go.tpl","loader":"asset:templates_test/singleton/boil_main_test.go.tpl"},{"name":"templates_test/singleton/boil_queries_test.go.tpl","loader":"asset:templates_test/singleton/boil_queries_test.go.tpl"},{"name":"templates_test/singleton/boil_suites_test.go.tpl","loader":"asset:templates_test/singleton/boil_suites_test.go.tpl"},{"name":"templates_test/singleton/psql_main_test.go.tpl","loader":"base64:(sha256 of content): d4991685726166a745bb44eae50f43b6e38670cd745624397bdb45d393dd42d1"},{"name":"templates_test/singleton/psql_suites_test.go.tpl","loader":"base64:(sha256 of content): 10c471afd916418b4bfce8bafdfa4d2c01d100e1b078ee7fd065f3a143ba3ce7"},{"name":"templates_test/types.go.tpl","loader":"asset:templates_test/types.go.tpl"},{"name":"templates_test/update.go.tpl","loader":"asset:templates_test/update.go.tpl"},{"name":"templates_test/upsert.go.tpl","loader":"base64:(sha256 of content): fbdedf7ee38269da51adf562f603fb1616cf5ac7975c53268a9181863b2c2258"}]}

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE user_scope AS ENUM (
    'app',
    'cms'
);
CREATE TABLE users (
    id uuid NOT NULL DEFAULT uuid_generate_v4 (),
    username varchar(255),
    "password" text,
    is_active bool NOT NULL,
    scopes user_scope[] NOT NULL DEFAULT '{app}',
    created_at timestamptz NOT NULL,
    updated_at timestamptz NOT NULL,
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT users_username_key UNIQUE (username)
);

Further information. What did you do, what did you expect?

Adding a column with an enum array type currently does not generate the respective constants for enum values in Go. Using the above schema, no values are added to boil_types.go - the enum is completely skipped and treated as string only.

Using above enum directly as a column type (instead of an array) results in the proper constants being generated.

Example adapted users schema:

CREATE TABLE users (
    id uuid NOT NULL DEFAULT uuid_generate_v4 (),
    username varchar(255),
    "password" text,
    is_active bool NOT NULL,
    scope user_scope NOT NULL DEFAULT 'app',
    created_at timestamptz NOT NULL,
    updated_at timestamptz NOT NULL,
    CONSTRAINT users_pkey PRIMARY KEY (id),
    CONSTRAINT users_username_key UNIQUE (username)
);

After generation, boil_types.go contains:

// Enum values for user_scope
const (
    UserScopeApp = "app"
    UserScopeCMS = "cms"
)

Updated output of sqlboiler psql -d:

using driver: /app/bin/sqlboiler-psql
{"config":{"driver_name":"psql","driver_config":{"blacklist":["migrations"],"dbname":"redacted","host":"postgres","pass":"redacted","port":"5432","sslmode":"disable","user":"dbuser","whitelist":null},"pkg_name":"models","out_folder":"internal/models","debug":true,"no_hooks":true,"wipe":true,"struct_tag_casing":"snake","relation_tag":"-","imports":{"all":{"Standard":["\"database/sql\"","\"fmt\"","\"reflect\"","\"strconv\"","\"strings\"","\"sync\"","\"time\"","\"context\""],"ThirdParty":["\"github.com/friendsofgo/errors\"","\"github.com/volatiletech/sqlboiler/v4/boil\"","\"github.com/volatiletech/sqlboiler/v4/queries\"","\"github.com/volatiletech/sqlboiler/v4/queries/qm\"","\"github.com/volatiletech/sqlboiler/v4/queries/qmhelper\"","\"github.com/volatiletech/strmangle\""]},"test":{"Standard":["\"bytes\"","\"reflect\"","\"testing\"","\"context\""],"ThirdParty":["\"github.com/volatiletech/randomize\"","\"github.com/volatiletech/sqlboiler/v4/boil\"","\"github.com/volatiletech/sqlboiler/v4/queries\"","\"github.com/volatiletech/strmangle\""]},"singleton":{"boil_queries":{"Standard":null,"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/drivers\"","\"github.com/volatiletech/sqlboiler/v4/queries\"","\"github.com/volatiletech/sqlboiler/v4/queries/qm\""]},"boil_types":{"Standard":["\"strconv\""],"ThirdParty":["\"github.com/friendsofgo/errors\"","\"github.com/volatiletech/sqlboiler/v4/boil\"","\"github.com/volatiletech/strmangle\""]},"psql_upsert":{"Standard":["\"fmt\"","\"strings\""],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/drivers\"","\"github.com/volatiletech/strmangle\""]}},"test_singleton":{"boil_main_test":{"Standard":["\"database/sql\"","\"flag\"","\"fmt\"","\"math/rand\"","\"os\"","\"path/filepath\"","\"strings\"","\"testing\"","\"time\""],"ThirdParty":["\"github.com/spf13/viper\"","\"github.com/volatiletech/sqlboiler/v4/boil\""]},"boil_queries_test":{"Standard":["\"bytes\"","\"fmt\"","\"io\"","\"io/ioutil\"","\"math/rand\"","\"regexp\""],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/boil\""]},"boil_suites_test":{"Standard":["\"testing\""],"ThirdParty":null},"psql_main_test":{"Standard":["\"bytes\"","\"database/sql\"","\"fmt\"","\"io\"","\"io/ioutil\"","\"os\"","\"os/exec\"","\"regexp\"","\"strings\""],"ThirdParty":["\"github.com/friendsofgo/errors\"","\"github.com/kat-co/vala\"","_ \"github.com/lib/pq\"","\"github.com/spf13/viper\"","\"github.com/volatiletech/randomize\"","\"github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql/driver\""]},"psql_suites_test":{"Standard":["\"testing\""],"ThirdParty":[]}},"based_on_type":{"null.Bool":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Bytes":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Float32":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Float64":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int16":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int32":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int64":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Int8":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.JSON":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.String":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Time":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint16":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint32":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint64":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"null.Uint8":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/null/v8\""]},"pgeo.Box":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Circle":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Line":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Lseg":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullBox":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullCircle":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullLine":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullLseg":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullPath":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullPoint":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.NullPolygon":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Path":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Point":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"pgeo.Polygon":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types/pgeo\""]},"time.Time":{"Standard":["\"time\""],"ThirdParty":[]},"types.BoolArray":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.BytesArray":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.Decimal":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.DecimalArray":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.Float64Array":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.HStore":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.Int64Array":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.JSON":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.NullDecimal":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]},"types.StringArray":{"Standard":[],"ThirdParty":["\"github.com/volatiletech/sqlboiler/v4/types\""]}}},"aliases":{"tables":{"users":{"up_plural":"Users","up_singular":"User","down_plural":"users","down_singular":"user","columns":{"created_at":"CreatedAt","id":"ID","is_active":"IsActive","password":"Password","scope":"Scope","updated_at":"UpdatedAt","username":"Username"}}}},"version":"4.1.1"},"driver_config":{"blacklist":["migrations"],"dbname":"redacted","host":"postgres","pass":"redacted","port":"5432","sslmode":"disable","user":"dbuser","whitelist":null},"schema":"public","dialect":{"lq":34,"rq":34,"use_index_placeholders":true,"use_last_insert_id":false,"use_schema":false,"use_default_keyword":true,"use_auto_columns":false,"use_top_clause":false,"use_output_clause":false,"use_case_when_exists_clause":false},"tables":[{"name":"users","schema_name":"","columns":[{"name":"id","type":"string","db_type":"uuid","default":"uuid_generate_v4()","nullable":false,"unique":true,"validated":false,"arr_type":null,"udt_name":"uuid","domain_name":null,"full_db_type":"uuid","auto_generated":false},{"name":"username","type":"null.String","db_type":"character varying","default":"","nullable":true,"unique":true,"validated":false,"arr_type":null,"udt_name":"varchar","domain_name":null,"full_db_type":"character varying(255)","auto_generated":false},{"name":"password","type":"null.String","db_type":"text","default":"","nullable":true,"unique":false,"validated":false,"arr_type":null,"udt_name":"text","domain_name":null,"full_db_type":"text","auto_generated":false},{"name":"is_active","type":"bool","db_type":"boolean","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"bool","domain_name":null,"full_db_type":"bool","auto_generated":false},{"name":"scope","type":"string","db_type":"enum.user_scope('app','cms')","default":"'app'::user_scope","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"user_scope","domain_name":null,"full_db_type":"user_scope","auto_generated":false},{"name":"created_at","type":"time.Time","db_type":"timestamp with time zone","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"timestamptz","domain_name":null,"full_db_type":"timestamptz","auto_generated":false},{"name":"updated_at","type":"time.Time","db_type":"timestamp with time zone","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"timestamptz","domain_name":null,"full_db_type":"timestamptz","auto_generated":false}],"p_key":{"name":"users_pkey","columns":["id"]},"f_keys":null,"is_join_table":false,"to_one_relationships":null,"to_many_relationships":null}],"templates":[{"name":"templates/00_struct.go.tpl","loader":"asset:templates/00_struct.go.tpl"},{"name":"templates/01_types.go.tpl","loader":"asset:templates/01_types.go.tpl"},{"name":"templates/02_hooks.go.tpl","loader":"asset:templates/02_hooks.go.tpl"},{"name":"templates/03_finishers.go.tpl","loader":"asset:templates/03_finishers.go.tpl"},{"name":"templates/04_relationship_to_one.go.tpl","loader":"asset:templates/04_relationship_to_one.go.tpl"},{"name":"templates/05_relationship_one_to_one.go.tpl","loader":"asset:templates/05_relationship_one_to_one.go.tpl"},{"name":"templates/06_relationship_to_many.go.tpl","loader":"asset:templates/06_relationship_to_many.go.tpl"},{"name":"templates/07_relationship_to_one_eager.go.tpl","loader":"asset:templates/07_relationship_to_one_eager.go.tpl"},{"name":"templates/08_relationship_one_to_one_eager.go.tpl","loader":"asset:templates/08_relationship_one_to_one_eager.go.tpl"},{"name":"templates/09_relationship_to_many_eager.go.tpl","loader":"asset:templates/09_relationship_to_many_eager.go.tpl"},{"name":"templates/10_relationship_to_one_setops.go.tpl","loader":"asset:templates/10_relationship_to_one_setops.go.tpl"},{"name":"templates/11_relationship_one_to_one_setops.go.tpl","loader":"asset:templates/11_relationship_one_to_one_setops.go.tpl"},{"name":"templates/12_relationship_to_many_setops.go.tpl","loader":"asset:templates/12_relationship_to_many_setops.go.tpl"},{"name":"templates/13_all.go.tpl","loader":"asset:templates/13_all.go.tpl"},{"name":"templates/14_find.go.tpl","loader":"asset:templates/14_find.go.tpl"},{"name":"templates/15_insert.go.tpl","loader":"asset:templates/15_insert.go.tpl"},{"name":"templates/16_update.go.tpl","loader":"asset:templates/16_update.go.tpl"},{"name":"templates/17_upsert.go.tpl","loader":"base64:(sha256 of content): 397bf4cd7e448a0023fe2ecdf9b1c68065263280eb9b81966dfd356803fadd87"},{"name":"templates/18_delete.go.tpl","loader":"asset:templates/18_delete.go.tpl"},{"name":"templates/19_reload.go.tpl","loader":"asset:templates/19_reload.go.tpl"},{"name":"templates/20_exists.go.tpl","loader":"asset:templates/20_exists.go.tpl"},{"name":"templates/21_auto_timestamps.go.tpl","loader":"asset:templates/21_auto_timestamps.go.tpl"},{"name":"templates/singleton/boil_queries.go.tpl","loader":"asset:templates/singleton/boil_queries.go.tpl"},{"name":"templates/singleton/boil_table_names.go.tpl","loader":"asset:templates/singleton/boil_table_names.go.tpl"},{"name":"templates/singleton/boil_types.go.tpl","loader":"asset:templates/singleton/boil_types.go.tpl"},{"name":"templates/singleton/psql_upsert.go.tpl","loader":"base64:(sha256 of content): cb25b2a17877de034695accfb0a1f5f11437114d5f919062c792efee53cbb25f"},{"name":"templates_test/00_types.go.tpl","loader":"asset:templates_test/00_types.go.tpl"},{"name":"templates_test/all.go.tpl","loader":"asset:templates_test/all.go.tpl"},{"name":"templates_test/delete.go.tpl","loader":"asset:templates_test/delete.go.tpl"},{"name":"templates_test/exists.go.tpl","loader":"asset:templates_test/exists.go.tpl"},{"name":"templates_test/find.go.tpl","loader":"asset:templates_test/find.go.tpl"},{"name":"templates_test/finishers.go.tpl","loader":"asset:templates_test/finishers.go.tpl"},{"name":"templates_test/hooks.go.tpl","loader":"asset:templates_test/hooks.go.tpl"},{"name":"templates_test/insert.go.tpl","loader":"asset:templates_test/insert.go.tpl"},{"name":"templates_test/relationship_one_to_one.go.tpl","loader":"asset:templates_test/relationship_one_to_one.go.tpl"},{"name":"templates_test/relationship_one_to_one_setops.go.tpl","loader":"asset:templates_test/relationship_one_to_one_setops.go.tpl"},{"name":"templates_test/relationship_to_many.go.tpl","loader":"asset:templates_test/relationship_to_many.go.tpl"},{"name":"templates_test/relationship_to_many_setops.go.tpl","loader":"asset:templates_test/relationship_to_many_setops.go.tpl"},{"name":"templates_test/relationship_to_one.go.tpl","loader":"asset:templates_test/relationship_to_one.go.tpl"},{"name":"templates_test/relationship_to_one_setops.go.tpl","loader":"asset:templates_test/relationship_to_one_setops.go.tpl"},{"name":"templates_test/reload.go.tpl","loader":"asset:templates_test/reload.go.tpl"},{"name":"templates_test/select.go.tpl","loader":"asset:templates_test/select.go.tpl"},{"name":"templates_test/singleton/boil_main_test.go.tpl","loader":"asset:templates_test/singleton/boil_main_test.go.tpl"},{"name":"templates_test/singleton/boil_queries_test.go.tpl","loader":"asset:templates_test/singleton/boil_queries_test.go.tpl"},{"name":"templates_test/singleton/boil_suites_test.go.tpl","loader":"asset:templates_test/singleton/boil_suites_test.go.tpl"},{"name":"templates_test/singleton/psql_main_test.go.tpl","loader":"base64:(sha256 of content): d4991685726166a745bb44eae50f43b6e38670cd745624397bdb45d393dd42d1"},{"name":"templates_test/singleton/psql_suites_test.go.tpl","loader":"base64:(sha256 of content): 10c471afd916418b4bfce8bafdfa4d2c01d100e1b078ee7fd065f3a143ba3ce7"},{"name":"templates_test/types.go.tpl","loader":"asset:templates_test/types.go.tpl"},{"name":"templates_test/update.go.tpl","loader":"asset:templates_test/update.go.tpl"},{"name":"templates_test/upsert.go.tpl","loader":"base64:(sha256 of content): fbdedf7ee38269da51adf562f603fb1616cf5ac7975c53268a9181863b2c2258"}]}

I would expect using an enum array also generates string constants for the referenced enum. Taking a quick peak at how Postgres handles and describes the type of an enum array, I'm not sure this is 100% feasible, but it would be nice to have to ensure proper values are added before DB interaction.

aarondl commented 4 years ago
        {
          "name": "scopes",
          "type": "types.StringArray",
          "db_type": "ARRAYUSER-DEFINED",
          "default": "'{app}'::user_scope[]",
          "nullable": false,
          "unique": false,
          "validated": false,
          "arr_type": "USER-DEFINED",
          "udt_name": "_user_scope",
          "domain_name": null,
          "full_db_type": "_user_scope",
          "auto_generated": false
        },
        {
          "name": "scope",
          "type": "string",
          "db_type": "enum.user_scope('app','cms')",
          "default": "'app'::user_scope",
          "nullable": false,
          "unique": false,
          "validated": false,
          "arr_type": null,
          "udt_name": "user_scope",
          "domain_name": null,
          "full_db_type": "user_scope",
          "auto_generated": false
        },

This is the relevant section of the debug output.

The code that does this is here: https://github.com/volatiletech/sqlboiler/blob/master/templates/singleton/boil_types.go.tpl#L63 which refers to these functions: https://github.com/volatiletech/strmangle/blob/master/strmangle.go#L657-L702

You can see that the mysql/postgres driver is doing some crazy things to db_type to make them work correctly. So it would seem to me we'd need to get the psql driver to be able to do something like: []enum.user_scope('app','cms') if it were an array and have those corresponding functions be able to deal with that in some way or something.

I'd accept a PR for this type of thing. Won't put any time into it myself though. Thanks for bringing up the issue!