diff --git a/internal/create_files/create_files.go b/internal/create_files/create_files.go index 3aef4e8..83ac0c1 100644 --- a/internal/create_files/create_files.go +++ b/internal/create_files/create_files.go @@ -287,7 +287,7 @@ func IsGoodTable(Table1 *types.Table) error { // err = errors.New(TextError) //} - err = IsGoodTablePrefix(Table1) + err = IsGoodTableNamePrefix(Table1) if err != nil { return err } @@ -312,8 +312,8 @@ func IsGoodPrimaryKeyColumnsCount(Table1 *types.Table) error { return err } -// IsGoodTablePrefix - возвращает ошибку если префикс таблицы = "DELETED_" -func IsGoodTablePrefix(Table1 *types.Table) error { +// IsGoodTableNamePrefix - возвращает ошибку если префикс таблицы = "DELETED_" +func IsGoodTableNamePrefix(Table1 *types.Table) error { var err error TableName := Table1.Name @@ -1778,16 +1778,18 @@ func Replace_Postgres_ID_Test(Text string, Table1 *types.Table) string { Otvet := Text TextFind := "const Postgres_ID_Test = 0" - ColumnPrimary := FindPrimaryKeyColumn(Table1) - if ColumnPrimary == nil { + PrimaryKeyColumn := FindPrimaryKeyColumn(Table1) + if PrimaryKeyColumn == nil { return Otvet } IDMinimum := Table1.IDMinimum + if IDMinimum == "" { + IDMinimum = FindTextDefaultValue(PrimaryKeyColumn.TypeGo) + } - if ColumnPrimary.TypeGo == "uuid.UUID" { + if PrimaryKeyColumn.TypeGo == "uuid.UUID" { if Table1.IDMinimum == "" { - IDMinimum = FindTextDefaultValue(ColumnPrimary.TypeGo) Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test = `+IDMinimum+``) } else { Otvet = strings.ReplaceAll(Otvet, TextFind, `var Postgres_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`) @@ -1812,15 +1814,18 @@ func Replace_Model_ID_Test(Text string, Table1 *types.Table) string { } IDMinimum := Table1.IDMinimum + if IDMinimum == "" { + IDMinimum = FindTextDefaultValue(PrimaryKeyColumn.TypeGo) + } if PrimaryKeyColumn.TypeGo == "uuid.UUID" { if Table1.IDMinimum == "" { - Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = ""`) + Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = `+IDMinimum+``) } else { - Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = "`+IDMinimum+`"`) + Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test, _ = uuid.Parse("`+IDMinimum+`")`) } } else { - Otvet = strings.ReplaceAll(Otvet, TextFind, `var `+ModelName+`_ID_Test = `+IDMinimum) + Otvet = strings.ReplaceAll(Otvet, TextFind, `const `+ModelName+`_ID_Test = `+IDMinimum) } return Otvet diff --git a/internal/create_files/entities_tables/entities_tables.go b/internal/create_files/entities_tables/entities_tables.go index 4870eb1..723e397 100644 --- a/internal/create_files/entities_tables/entities_tables.go +++ b/internal/create_files/entities_tables/entities_tables.go @@ -19,17 +19,25 @@ func CreateAllFiles(MapAll map[string]*types.Table) error { var err error //для каждой таблицы - for _, table1 := range MapAll { - err = CreateFiles(table1) + for _, Table1 := range MapAll { + //проверка имени таблицы "DELETED_" + err1 := create_files.IsGoodTableNamePrefix(Table1) + if err1 != nil { + log.Warn("CreateFiles() table: ", Table1.Name, " warning: ", err) + continue + } + + //создание файлов + err = CreateFiles(Table1) if err != nil { - log.Error("CreateFiles() table: ", table1.Name, " error: ", err) + log.Error("CreateFiles() table: ", Table1.Name, " error: ", err) return err } if config.Settings.NEED_CREATE_UPDATE_EVERY_COLUMN == true { - err = CreateFilesUpdateEveryColumn(table1) + err = CreateFilesUpdateEveryColumn(Table1) if err != nil { - log.Error("CreateFiles() table: ", table1.Name, " error: ", err) + log.Error("CreateFiles() table: ", Table1.Name, " error: ", err) return err } } diff --git a/internal/create_files/tables_tables/tables_tables.go b/internal/create_files/tables_tables/tables_tables.go index f6c5ad7..d3b4221 100644 --- a/internal/create_files/tables_tables/tables_tables.go +++ b/internal/create_files/tables_tables/tables_tables.go @@ -18,10 +18,18 @@ import ( func CreateAllFiles(MapAll map[string]*types.Table) error { var err error - for _, table1 := range MapAll { - err = CreateFiles(table1) + for _, Table1 := range MapAll { + //проверка имени таблицы "DELETED_" + err1 := create_files.IsGoodTableNamePrefix(Table1) + if err1 != nil { + log.Warn("CreateFiles() table: ", Table1.Name, " warning: ", err) + continue + } + + // + err = CreateFiles(Table1) if err != nil { - log.Error("CreateFiles() table: ", table1.Name, " error: ", err) + log.Error("CreateFiles() table: ", Table1.Name, " error: ", err) return err } } diff --git a/internal/postgres/postgres.go b/internal/postgres/postgres.go index d41127a..7c914b8 100644 --- a/internal/postgres/postgres.go +++ b/internal/postgres/postgres.go @@ -278,6 +278,7 @@ order by OrderNumberTable++ } + //новая таблица //найдём имя модели golang TableName := v.TableName ModelName := create_files.FindSingularName(TableName) @@ -287,6 +288,7 @@ order by TableComment := v.TableComment TableComment = strings.ReplaceAll(TableComment, "\n", "") TableComment = strings.ReplaceAll(TableComment, "\r", "") + Table1 = CreateTable() Table1.Name = TableName Table1.OrderNumber = OrderNumberTable @@ -333,9 +335,10 @@ order by TableName0 = v.TableName } - // + //последнюю таблицу заполним тут if Table1.Name != "" { Table1.MapColumns = MapColumns + Table1.PrimaryKeyColumnsCount = PrimaryKeyColumnsCount MapTable[TableName0] = Table1 }