From b37b6bac7ccb29792e7d52bf82d29c02bd0c1c2d Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Thu, 15 Feb 2024 15:15:16 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20CreateFi?= =?UTF-8?q?lesUpdateEveryColumn()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/grpc/server_grpc/server_grpc_test.go_ | 2 +- .../pkg/db/crud/crud_tables_rapira_test.go_ | 14 ++++----- .../pkg/db/crud/crud_tables_test.go_ | 14 ++++----- .../grpc_client/grpc_client_table_test.go_ | 2 +- internal/create_files/create_files.go | 29 +++++++++++++++++-- internal/create_files/create_files_columns.go | 7 ++++- .../db_crud_tables/db_crud_tables.go | 19 +++++++----- .../grpc_client_tables/grpc_client_tables.go | 2 +- .../grpc_server_tables/grpc_server_tables.go | 2 +- 9 files changed, 62 insertions(+), 29 deletions(-) diff --git a/bin/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ index 0f113b7..b936877 100644 --- a/bin/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ +++ b/bin/templates/internal/app/grpc/server_grpc/server_grpc_test.go_ @@ -10,7 +10,7 @@ import ( ) // LawsuitStatusType_ID_Test - ID таблицы для тестирования -const LawsuitStatusType_ID_Test = 1 +const LawsuitStatusType_ID_Test = 0 func Test_server_LawsuitStatusType_Read(t *testing.T) { config_main.LoadEnv() diff --git a/bin/templates/pkg/db/crud/crud_tables_rapira_test.go_ b/bin/templates/pkg/db/crud/crud_tables_rapira_test.go_ index f64d909..757e4bb 100644 --- a/bin/templates/pkg/db/crud/crud_tables_rapira_test.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_rapira_test.go_ @@ -7,7 +7,7 @@ import ( "testing" ) -const Postgres_ID_Test = 1 +const Postgres_ID_Test = 0 func TestRead(t *testing.T) { config_main.LoadEnv() @@ -23,8 +23,8 @@ func TestRead(t *testing.T) { t.Error("TestRead() error: ", err) } - if Otvet.ID == 0 { - t.Error(TableName + "_test.TestRead() error ID=0 ") + if Otvet.ID != Postgres_ID_Test { + t.Error(TableName + "_test.TestRead() error ID != ", Postgres_ID_Test) } else { t.Log(TableName+"_test.TestRead() Otvet: ", Otvet.ID) } @@ -44,8 +44,8 @@ func TestSave(t *testing.T) { t.Error("TestSave() error: ", err) } - if Otvet.ID == 0 { - t.Error(TableName + "_test.TestSave() error ID=0 ") + if Otvet.ID != Postgres_ID_Test { + t.Error(TableName + "_test.TestSave() error ID != ", Postgres_ID_Test) } err = crud.Save(&Otvet) @@ -117,7 +117,7 @@ func TestFind_ByExtID(t *testing.T) { t.Error("TestFind_ByExtID() error: ", err) } - if Otvet.ID == 0 { - t.Error("TestFind_ByExtID() error: ID =0") + if Otvet.ID != Postgres_ID_Test { + t.Error("TestFind_ByExtID() error: ID != ", Postgres_ID_Test) } } diff --git a/bin/templates/pkg/db/crud/crud_tables_test.go_ b/bin/templates/pkg/db/crud/crud_tables_test.go_ index a62c7ae..a722815 100644 --- a/bin/templates/pkg/db/crud/crud_tables_test.go_ +++ b/bin/templates/pkg/db/crud/crud_tables_test.go_ @@ -7,7 +7,7 @@ import ( "testing" ) -const Postgres_ID_Test = 1 +const Postgres_ID_Test = 0 func TestRead(t *testing.T) { config_main.LoadEnv() @@ -23,8 +23,8 @@ func TestRead(t *testing.T) { t.Error("TestRead() error: ", err) } - if Otvet.ID == 0 { - t.Error(TableName + "_test.TestRead() error ID=0 ") + if Otvet.ID != Postgres_ID_Test { + t.Error(TableName + "_test.TestRead() error ID != ", Postgres_ID_Test) } else { t.Log(TableName+"_test.TestRead() Otvet: ", Otvet.ID) } @@ -44,8 +44,8 @@ func TestSave(t *testing.T) { t.Error("TestSave() error: ", err) } - if Otvet.ID == 0 { - t.Error(TableName + "_test.TestSave() error ID=0 ") + if Otvet.ID != Postgres_ID_Test { + t.Error(TableName + "_test.TestSave() error ID != ", Postgres_ID_Test) } err = crud.Save(&Otvet) @@ -94,8 +94,8 @@ func TestFind_ByExtID(t *testing.T) { t.Error("TestFind_ByExtID() error: ", err) } - if Otvet.ID == 0 { - t.Error("TestFind_ByExtID() error: ID =0") + if Otvet.ID != Postgres_ID_Test { + t.Error("TestFind_ByExtID() error: ID != ", Postgres_ID_Test) } } diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ index 23e74bd..74d5ed4 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table_test.go_ @@ -8,7 +8,7 @@ import ( ) // Postgres_ID_Test - ID таблицы для тестирования -const Postgres_ID_Test = 1 +const Postgres_ID_Test = 0 func TestGetVersionModel(t *testing.T) { diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 4dd09d2..fe32d8e 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -1224,11 +1224,36 @@ func FindTextEqualEmpty(Column1 *types.Column, VariableName string) string { Otvet := "" DefaultValue := FindTextDefaultValue(Column1.TypeGo) - Otvet = VariableName + "." + Column1.NameGo + " == " + DefaultValue + Otvet = VariableName + " == " + DefaultValue if DefaultValue == "time.Time{}" { - Otvet = VariableName + "." + Column1.NameGo + ".IsZero() == true" + Otvet = VariableName + ".IsZero() == true" } return Otvet } + +//// AddSkipNowEveryFunc - добавляет функцию SkipNow() для каждой тестовой функции +//func AddSkipNowEveryFunc(Text string) string { +// Otvet := "" +// +// sFind := "\nfunc " +// Mass := make([]string, 0) +// Mass = strings.Split(Text, sFind) +// for _, v := range Mass { +// pos1 := strings.Index(v, sFind) +// if pos1 < 0 { +// continue +// } +// +// s2 := Text[pos1:] +// pos2 := strings.Index(s2, "\n") +// if pos2 < 0 { +// continue +// } +// v = v[:pos1+pos2] + "\n\tt.SkipNow() //нет строк в БД \n" + v[pos1+pos2:] +// Otvet = Otvet + v +// } +// +// return Otvet +//} diff --git a/internal/create_files/create_files_columns.go b/internal/create_files/create_files_columns.go index 03fa332..8f108d7 100644 --- a/internal/create_files/create_files_columns.go +++ b/internal/create_files/create_files_columns.go @@ -4,6 +4,7 @@ import ( "github.com/ManyakRus/crud_generator/internal/types" "github.com/ManyakRus/crud_generator/pkg/dbmeta" "github.com/ManyakRus/starter/log" + "strings" ) // Has_Column_ExtID_ConnectionID - возвращает true если есть поля ExtId и ConnectionID @@ -316,11 +317,15 @@ func Is_Common_Сolumn(Column1 *types.Column) bool { return Otvet } -// Is_NotNeedUpdate_Сolumn - возвращает true если это общая колонка: table_name_id, table_row_id, is_group, parent_id, ext_id, created_at, modified_at, deleted_at, id +// Is_NotNeedUpdate_Сolumn - возвращает true если не нужна функция UpdateColumnNAme(), например если это общая колонка: table_name_id, table_row_id, is_group, parent_id, ext_id, created_at, modified_at, deleted_at, id func Is_NotNeedUpdate_Сolumn(Column1 *types.Column) bool { Otvet := false Otvet = Is_Column_CommonStruct(Column1) || Is_Column_GroupsStruct(Column1) || Is_Column_ExtLinksStruct(Column1) + if strings.HasPrefix(Column1.Name, "DELETED_") == true { + Otvet = true + } + return Otvet } diff --git a/internal/create_files/db_crud_tables/db_crud_tables.go b/internal/create_files/db_crud_tables/db_crud_tables.go index 4d8e45b..690a7f5 100644 --- a/internal/create_files/db_crud_tables/db_crud_tables.go +++ b/internal/create_files/db_crud_tables/db_crud_tables.go @@ -208,13 +208,13 @@ func CreateTestFiles(Table1 *types.Table) error { //Postgres_ID_Test = ID Minimum if Table1.IDMinimum != "" { TextFind := "const Postgres_ID_Test = " - TextDB = strings.ReplaceAll(TextDB, TextFind+"1", TextFind+Table1.IDMinimum) + TextDB = strings.ReplaceAll(TextDB, TextFind+"0", TextFind+Table1.IDMinimum) } - //SkipNow() + //SkipNow() если нет строк в БД TextDB = create_files.AddSkipNow(TextDB, Table1) - // замена ID на PrimaryKey + //замена ID на PrimaryKey TextDB = create_files.ReplacePrimaryKeyID(TextDB, Table1) //замена импортов на новые URL @@ -588,10 +588,10 @@ func FindTextUpdateEveryColumn1(TextCrudUpdateFunc string, Table1 *types.Table, //Otvet = strings.ReplaceAll(Otvet, "m.ID", "m."+ColumnName) //внешние ключи заменяем 0 на null - if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time{}") { - Otvet = strings.ReplaceAll(Otvet, "0==1", "1==1") - TextEqualEmpty := create_files.FindTextEqualEmpty(Column1, "Value") - Otvet = strings.ReplaceAll(Otvet, "Value == 0", TextEqualEmpty) + TextEqualEmpty := create_files.FindTextEqualEmpty(Column1, "Value") + Otvet = strings.ReplaceAll(Otvet, "Value == 0", TextEqualEmpty) + if Column1.IsNullable == true && (Column1.TableKey != "" || Column1.TypeGo == "time.Time") { + Otvet = strings.ReplaceAll(Otvet, "0==1 && ", "") } return Otvet @@ -637,7 +637,7 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { ModelTableURL := create_files.FindModelTableURL(TableName) TextCrud = create_files.AddImport(TextCrud, ModelTableURL) - TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1) + //TextCrud = create_files.ConvertIdToAlias(TextCrud, Table1) //} //создание текста @@ -653,6 +653,9 @@ func CreateTestFilesUpdateEveryColumn(Table1 *types.Table) error { TextCrud = config.Settings.TEXT_MODULE_GENERATED + TextCrud + //SkipNow() если нет строк в БД + TextCrud = create_files.AddSkipNow(TextCrud, Table1) + //удаление пустого импорта TextCrud = create_files.DeleteEmptyImport(TextCrud) TextCrud = create_files.DeleteEmptyLines(TextCrud) diff --git a/internal/create_files/grpc_client_tables/grpc_client_tables.go b/internal/create_files/grpc_client_tables/grpc_client_tables.go index cb876c3..f26babc 100644 --- a/internal/create_files/grpc_client_tables/grpc_client_tables.go +++ b/internal/create_files/grpc_client_tables/grpc_client_tables.go @@ -216,7 +216,7 @@ func CreateTestFiles(Table1 *types.Table) error { //Postgres_ID_Test = ID Minimum if Table1.IDMinimum != "" { TextFind := "const Postgres_ID_Test = " - TextGRPCClient = strings.ReplaceAll(TextGRPCClient, TextFind+"1", TextFind+Table1.IDMinimum) + TextGRPCClient = strings.ReplaceAll(TextGRPCClient, TextFind+"0", TextFind+Table1.IDMinimum) } // замена ID на PrimaryKey diff --git a/internal/create_files/grpc_server_tables/grpc_server_tables.go b/internal/create_files/grpc_server_tables/grpc_server_tables.go index 535fe54..c425f58 100644 --- a/internal/create_files/grpc_server_tables/grpc_server_tables.go +++ b/internal/create_files/grpc_server_tables/grpc_server_tables.go @@ -195,7 +195,7 @@ func CreateTestFiles(Table1 *types.Table) error { //Postgres_ID_Test = ID Minimum if Table1.IDMinimum != "" { TextFind := "const " + ModelName + "_ID_Test = " - TextGRPCServer = strings.ReplaceAll(TextGRPCServer, TextFind+"1", TextFind+Table1.IDMinimum) + TextGRPCServer = strings.ReplaceAll(TextGRPCServer, TextFind+"0", TextFind+Table1.IDMinimum) } // замена ID на PrimaryKey