From 42a37c09d0741acac7ad4239e95cb24531fbdab3 Mon Sep 17 00:00:00 2001 From: Samir Faci Date: Wed, 18 Sep 2024 12:09:43 -0400 Subject: [PATCH 1/4] Adding support for enum model AllValues Fixes #368 ChangeLog: - Updating test mysql version as it no longer exists. - Add a simple validation test --- .circleci/config.yml | 4 ++-- generator/template/file_templates.go | 6 ++++++ tests/docker-compose.yaml | 2 +- tests/postgres/generator_template_test.go | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e21f00a4..e6348585 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ jobs: POSTGRES_DB: jetdb PGPORT: 50901 - - image: circleci/mysql:8.0.27 + - image: circleci/mysql:8.0 command: [ --default-authentication-plugin=mysql_native_password ] environment: MYSQL_ROOT_PASSWORD: jet @@ -163,4 +163,4 @@ workflows: version: 2 build_and_test: jobs: - - build_and_tests \ No newline at end of file + - build_and_tests diff --git a/generator/template/file_templates.go b/generator/template/file_templates.go index 731b1afa..fa168648 100644 --- a/generator/template/file_templates.go +++ b/generator/template/file_templates.go @@ -156,6 +156,12 @@ const ( {{- end}} ) +var {{$enumTemplate.TypeName}}_AllValues = []{{$enumTemplate.TypeName}} { +{{- range $_, $value := .Values}} + {{valueName $value}}, +{{- end}} +} + func (e *{{$enumTemplate.TypeName}}) Scan(value interface{}) error { var enumValue string switch val := value.(type) { diff --git a/tests/docker-compose.yaml b/tests/docker-compose.yaml index 9b3af507..09ce9d70 100644 --- a/tests/docker-compose.yaml +++ b/tests/docker-compose.yaml @@ -13,7 +13,7 @@ services: - ./testdata/init/postgres:/docker-entrypoint-initdb.d mysql: - image: mysql:8.0.27 + image: mysql:8.0 command: ['--default-authentication-plugin=mysql_native_password', '--log_bin_trust_function_creators=1'] restart: always environment: diff --git a/tests/postgres/generator_template_test.go b/tests/postgres/generator_template_test.go index 4d87295d..a9a244b6 100644 --- a/tests/postgres/generator_template_test.go +++ b/tests/postgres/generator_template_test.go @@ -171,6 +171,7 @@ func TestGeneratorTemplate_Model_RenameFilesAndTypes(t *testing.T) { mpaaRating := file2.Exists(t, defaultModelPath, "mpaa_rating_enum.go") require.Contains(t, mpaaRating, "type MpaaRatingEnum string") + require.Contains(t, mpaaRating, "MpaaRatingEnum_AllValues") } func TestGeneratorTemplate_Model_SkipTableAndEnum(t *testing.T) { From eb57b8003f76b2e76f0edb2f9094d0cb85382872 Mon Sep 17 00:00:00 2001 From: Samir Faci Date: Wed, 18 Sep 2024 12:20:08 -0400 Subject: [PATCH 2/4] Migrating circleci images from legacy to update cimg namespace --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e6348585..0fb458f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ jobs: POSTGRES_DB: jetdb PGPORT: 50901 - - image: circleci/mysql:8.0 + - image: cimg/mysql:8.0 command: [ --default-authentication-plugin=mysql_native_password ] environment: MYSQL_ROOT_PASSWORD: jet @@ -25,7 +25,7 @@ jobs: MYSQL_PASSWORD: jet MYSQL_TCP_PORT: 50902 - - image: circleci/mariadb:10.3 + - image: cimg/mariadb:10.3 command: [ '--default-authentication-plugin=mysql_native_password', '--port=50903' ] environment: MYSQL_ROOT_PASSWORD: jet From 4f80e0d36bb0d902a8b7927b1212e9b0b7bfaa70 Mon Sep 17 00:00:00 2001 From: Samir Faci Date: Sun, 22 Sep 2024 09:44:13 -0400 Subject: [PATCH 3/4] Addressing Code review comments --- generator/template/file_templates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/template/file_templates.go b/generator/template/file_templates.go index fa168648..f3aa5053 100644 --- a/generator/template/file_templates.go +++ b/generator/template/file_templates.go @@ -156,7 +156,7 @@ const ( {{- end}} ) -var {{$enumTemplate.TypeName}}_AllValues = []{{$enumTemplate.TypeName}} { +var {{$enumTemplate.TypeName}}AllValues = []{{$enumTemplate.TypeName}} { {{- range $_, $value := .Values}} {{valueName $value}}, {{- end}} From d3ce39f27582c8c20567451841f852847b0fd7a8 Mon Sep 17 00:00:00 2001 From: Samir Faci Date: Sun, 22 Sep 2024 16:04:11 -0400 Subject: [PATCH 4/4] Reverting circleci docker-compose --- .circleci/config.yml | 6 +++--- tests/docker-compose.yaml | 2 +- tests/postgres/generator_template_test.go | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0fb458f7..e21f00a4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ jobs: POSTGRES_DB: jetdb PGPORT: 50901 - - image: cimg/mysql:8.0 + - image: circleci/mysql:8.0.27 command: [ --default-authentication-plugin=mysql_native_password ] environment: MYSQL_ROOT_PASSWORD: jet @@ -25,7 +25,7 @@ jobs: MYSQL_PASSWORD: jet MYSQL_TCP_PORT: 50902 - - image: cimg/mariadb:10.3 + - image: circleci/mariadb:10.3 command: [ '--default-authentication-plugin=mysql_native_password', '--port=50903' ] environment: MYSQL_ROOT_PASSWORD: jet @@ -163,4 +163,4 @@ workflows: version: 2 build_and_test: jobs: - - build_and_tests + - build_and_tests \ No newline at end of file diff --git a/tests/docker-compose.yaml b/tests/docker-compose.yaml index 09ce9d70..9b3af507 100644 --- a/tests/docker-compose.yaml +++ b/tests/docker-compose.yaml @@ -13,7 +13,7 @@ services: - ./testdata/init/postgres:/docker-entrypoint-initdb.d mysql: - image: mysql:8.0 + image: mysql:8.0.27 command: ['--default-authentication-plugin=mysql_native_password', '--log_bin_trust_function_creators=1'] restart: always environment: diff --git a/tests/postgres/generator_template_test.go b/tests/postgres/generator_template_test.go index a9a244b6..65603cd7 100644 --- a/tests/postgres/generator_template_test.go +++ b/tests/postgres/generator_template_test.go @@ -171,7 +171,7 @@ func TestGeneratorTemplate_Model_RenameFilesAndTypes(t *testing.T) { mpaaRating := file2.Exists(t, defaultModelPath, "mpaa_rating_enum.go") require.Contains(t, mpaaRating, "type MpaaRatingEnum string") - require.Contains(t, mpaaRating, "MpaaRatingEnum_AllValues") + require.Contains(t, mpaaRating, "MpaaRatingEnumAllValues") } func TestGeneratorTemplate_Model_SkipTableAndEnum(t *testing.T) { @@ -269,7 +269,6 @@ func UseSchema(schema string) { FilmList = FilmList.FromSchema(schema) } `) - } func TestGeneratorTemplate_SQLBuilder_ChangeTypeAndFileName(t *testing.T) { @@ -367,7 +366,6 @@ func TestGeneratorTemplate_SQLBuilder_DefaultAlias(t *testing.T) { } func TestGeneratorTemplate_Model_AddTags(t *testing.T) { - err := postgres.Generate( tempTestDir, dbConnection,