From 1965956ffa043ad1a8367afaea0dae1180d9a8b8 Mon Sep 17 00:00:00 2001
From: Nikitin Aleksandr <nikitinav@atomsbt.ru>
Date: Tue, 9 Jan 2024 13:48:10 +0300
Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20./crud?=
 =?UTF-8?q?=5Ffunctions=5Frename.json?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 bin/templates/Makefile_                       |  4 +-
 bin/templates/configs_/convert_id.json        | 11 ++++
 .../configs_/crud_functions_rename.json       |  8 +++
 .../configs_/crud_functions_rename_test.json  |  8 +++
 .../configs_/model_crud_delete_functions.json |  1 +
 bin/templates/configs_/name_replace.json      | 17 ++++++
 bin/templates/configs_/nullable.json          |  2 +
 bin/templates/configs_/readme.txt             | 14 +++++
 bin/templates/configs_/settings.txt           |  8 +--
 .../app/grpc/server_grpc/server_grpc_test.go_ |  3 +-
 bin/templates/pkg/db/crud/crud.go_            | 56 ++++++++++++++++---
 .../grpc_client/grpc_client_table_test.go_    | 42 ++++++++++++--
 .../nrpc_client/nrpc_client_table_test.go_    | 41 ++++++++++++--
 .../configs_/crud_functions_rename.json       |  2 +
 .../default/templates/configs_/readme.txt     | 14 +++++
 .../configs_/crud_functions_rename.json       |  8 +++
 .../configs_/model_crud_delete_functions.json |  2 +-
 examples/rapira/templates/configs_/readme.txt | 14 +++++
 .../db_crud_tables/db_crud_tables.go          | 19 +++++++
 internal/load_configs/load_configs.go         | 24 ++++++++
 internal/load_configs/load_configs_test.go    | 54 ++++++++++++++++++
 internal/types/types.go                       | 12 ++++
 22 files changed, 339 insertions(+), 25 deletions(-)
 create mode 100644 bin/templates/configs_/crud_functions_rename.json
 create mode 100644 bin/templates/configs_/crud_functions_rename_test.json
 create mode 100644 examples/default/templates/configs_/crud_functions_rename.json
 create mode 100644 examples/rapira/templates/configs_/crud_functions_rename.json

diff --git a/bin/templates/Makefile_ b/bin/templates/Makefile_
index b8896c4..a7db086 100644
--- a/bin/templates/Makefile_
+++ b/bin/templates/Makefile_
@@ -5,7 +5,8 @@ FILEMAIN=./cmd/$(SERVICENAME)/main.go
 FILEAPP=./bin/$(SERVICENAME)
 
 NEW_REPO=$(SERVICENAME)
-GENERATION_PROTO=cd ./api && ./generation_code.sh
+CD_GENERATION_PROTO=cd ./api
+GENERATION_PROTO=generation_code.sh
 
 
 run:
@@ -53,6 +54,7 @@ conn:
 init:
 	clear
 	go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service
+	$(CD_GENERATION_PROTO)
 	$(GENERATION_PROTO)
 	go mod tidy
 	go mod vendor
\ No newline at end of file
diff --git a/bin/templates/configs_/convert_id.json b/bin/templates/configs_/convert_id.json
index bfd870e..e12763f 100644
--- a/bin/templates/configs_/convert_id.json
+++ b/bin/templates/configs_/convert_id.json
@@ -1,3 +1,14 @@
 {
+  "lawsuit_payments.id": "alias.PaymentId",
+  "lawsuit_payments.invoice_id": "alias.InvoiceId",
+  "lawsuit_payments.lawsuit_id": "alias.LawsuitId",
+  "lawsuit_payments.id": "alias.PaymentId",
+  "invoice_debt_type_stats.invoice_id": "alias.InvoiceId",
+  "invoice_debt_type_stats.lawsuit_id": "alias.LawsuitId",
+  "contract_black_items.contract_number": "alias.ContractNumber",
+  "contract_white_items.contract_number": "alias.ContractNumber",
+  "lawsuits.number_claim": "alias.ClaimNumber",
+  "lawsuits.number": "alias.LawsuitNumber",
+  "contracts.number": "alias.ContractNumber"
 }
 
diff --git a/bin/templates/configs_/crud_functions_rename.json b/bin/templates/configs_/crud_functions_rename.json
new file mode 100644
index 0000000..10c97af
--- /dev/null
+++ b/bin/templates/configs_/crud_functions_rename.json
@@ -0,0 +1,8 @@
+{
+  "lawsuits": [
+    {
+      "old": "create_update_ctx",
+      "new": "create_update_ctx_original"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/bin/templates/configs_/crud_functions_rename_test.json b/bin/templates/configs_/crud_functions_rename_test.json
new file mode 100644
index 0000000..10c97af
--- /dev/null
+++ b/bin/templates/configs_/crud_functions_rename_test.json
@@ -0,0 +1,8 @@
+{
+  "lawsuits": [
+    {
+      "old": "create_update_ctx",
+      "new": "create_update_ctx_original"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/bin/templates/configs_/model_crud_delete_functions.json b/bin/templates/configs_/model_crud_delete_functions.json
index 2c63c08..d8c0ee0 100644
--- a/bin/templates/configs_/model_crud_delete_functions.json
+++ b/bin/templates/configs_/model_crud_delete_functions.json
@@ -1,2 +1,3 @@
 {
+      "lawsuits": "NewLawsuit,AsLawsuit,create_update_ctx"
 }
diff --git a/bin/templates/configs_/name_replace.json b/bin/templates/configs_/name_replace.json
index 7a73a41..cab0526 100644
--- a/bin/templates/configs_/name_replace.json
+++ b/bin/templates/configs_/name_replace.json
@@ -1,2 +1,19 @@
 {
+  "inn": "INN",
+  "kpp": "KPP",
+  "okpo": "OKPO",
+  "ogrn": "OGRN",
+  "okato": "OKATO",
+  "nsi_flat": "NSIFlat",
+  "nsi_flat_id": "NSIFlatID",
+  "nsi_id": "NSIID",
+  "www": "WWW",
+  "bik": "BIK",
+  "city_name": "City",
+  "edms_link": "EDMSLink",
+  "code_nsi": "CodeNSI",
+  "json_updated_at": "JSONUpdatedAt",
+  "pdf_updated_at": "PDFUpdatedAt",
+  "pdf_file_id": "PDFFileID",
+  "json_file_id": "JSONFileID"
 }
\ No newline at end of file
diff --git a/bin/templates/configs_/nullable.json b/bin/templates/configs_/nullable.json
index 2c63c08..3f0a502 100644
--- a/bin/templates/configs_/nullable.json
+++ b/bin/templates/configs_/nullable.json
@@ -1,2 +1,4 @@
 {
+      "ext_id": true,
+      "created_at": false
 }
diff --git a/bin/templates/configs_/readme.txt b/bin/templates/configs_/readme.txt
index 1c44590..d3ef068 100644
--- a/bin/templates/configs_/readme.txt
+++ b/bin/templates/configs_/readme.txt
@@ -45,3 +45,17 @@ example:
 {
       "lawsuits": "NewLawsuit,AsLawsuit"
 }
+
+
+
+crud_functions_rename.json 
+TableName:{old:"",new:""}
+example:
+{
+      "functions": [
+	{
+	"old": "create_update_ctx",
+	"new":"create_update_ctx_original"
+	}
+	]
+}
diff --git a/bin/templates/configs_/settings.txt b/bin/templates/configs_/settings.txt
index 667ff6b..6647da1 100644
--- a/bin/templates/configs_/settings.txt
+++ b/bin/templates/configs_/settings.txt
@@ -21,15 +21,15 @@ DB_PASSWORD=
 INCLUDE_TABLES=""
 
 #INCLUDE_TABLES - table name ignore filter. Regular expression
-EXCLUDE_TABLES=
+EXCLUDE_TABLES="ext_"
 
 #---------------------Template settings---------------------
 
 #SERVICE_REPOSITORY_URL - URL of your new service repository (Github, gitlab, etc.)
-SERVICE_REPOSITORY_URL="gitlab.aescorp.ru/dsp_dev/claim/crud_service"
+SERVICE_REPOSITORY_URL="gitlab.aescorp.ru/dsp_dev/claim/sync_service"
 
 #SERVICE_NAME - service name for your new service
-SERVICE_NAME=crud_service
+SERVICE_NAME=sync_service
 
 #TEMPLATE_SERVICE_NAME - service name in your template files
 TEMPLATE_SERVICE_NAME=sync_service
@@ -96,7 +96,7 @@ TEXT_TEMPLATE_TABLENAME="lawsuit_status_types"
 USE_DEFAULT_TEMPLATE=true
 
 #HAS_IS_DELETED - fill "true" if you have "is_deleted" column, and want Delete() Restore() functions.
-HAS_IS_DELETED=false
+HAS_IS_DELETED=true
 
 #---------------------Create files settings---------------------
 
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 5ad483a..3457d7b 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_
@@ -7,7 +7,6 @@ import (
 	"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
 	"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
 	"testing"
-	"math"
 )
 
 // LawsuitStatusType_ID_Test - ID таблицы для тестирования
@@ -38,7 +37,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
 
 	ctx := context.Background()
 	Request := grpc_proto.RequestId{}
-	Request.Id = math.MinInt64
+	Request.Id = LawsuitStatusType_ID_Test
 	Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
 
 	server1 := &ServerGRPC{}
diff --git a/bin/templates/pkg/db/crud/crud.go_ b/bin/templates/pkg/db/crud/crud.go_
index 73bda68..303b13e 100644
--- a/bin/templates/pkg/db/crud/crud.go_
+++ b/bin/templates/pkg/db/crud/crud.go_
@@ -146,14 +146,12 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ
 	if is_create == true {
 		if int64(m.ID) != 0 {
 			TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0")
-			// log.Panic(sError)
 			err = errors.New(TextError)
 			return err
 		}
 	} else if int64(m.ID) == 0 {
 		TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0")
 		err = errors.New(TextError)
-		// log.Panic(sError)
 		return err
 	}
 
@@ -210,7 +208,7 @@ func (crud Crud_DB) Delete(m *lawsuit_status_types.LawsuitStatusType) error {
 	return err
 }
 
-// Delete_ctx - удаляет запись в БД
+// Delete_ctx - записывает is_deleted = true
 func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
 	var err error
 
@@ -219,11 +217,53 @@ func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.Laws
 		return err
 	}
 
-	db := postgres_gorm.GetConnection()
-	db.WithContext(ctx)
+	m2 := lawsuit_status_types.LawsuitStatusType{}
+	m2.ID = m.ID
+	err = crud.Read_ctx(ctx, &m2)
+	if err != nil {
+		return err
+	}
 
-	tx := db.Delete(m)
-	err = tx.Error
+	m2.IsDeleted = true
+	m.IsDeleted = true
+
+	err = crud.Save_ctx(ctx, &m2)
+
+	return err
+}
+
+// Restore - записывает is_deleted = true
+func (crud Crud_DB) Restore(m *lawsuit_status_types.LawsuitStatusType) error {
+	var err error
+
+	ctxMain := contextmain.GetContext()
+	ctx, ctxCancelFunc := context.WithTimeout(ctxMain, time.Second*time.Duration(constants.TIMEOUT_DB_SECONDS))
+	defer ctxCancelFunc()
+
+	err = crud.Restore_ctx(ctx, m)
+	return err
+}
+
+// Restore_ctx - записывает is_deleted = true
+func (crud Crud_DB) Restore_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
+	var err error
+
+	if micro.ContextDone(ctx) == true {
+		err = context.Canceled
+		return err
+	}
+
+	m2 := lawsuit_status_types.LawsuitStatusType{}
+	m2.ID = m.ID
+	err = crud.Read_ctx(ctx, &m2)
+	if err != nil {
+		return err
+	}
+
+	m2.IsDeleted = false
+	m.IsDeleted = false
+
+	err = crud.Save_ctx(ctx, &m2)
 
 	return err
 }
@@ -264,7 +304,7 @@ func (crud Crud_DB) Find_ByExtID_ctx(ctx context.Context, m *lawsuit_status_type
 	db := postgres_gorm.GetConnection()
 	db.WithContext(ctx)
 
-	tx := db.Where("ext_id = ?", m.ExtID).Where("connection_id = ?", m.ConnectionID).Order("is_deleted").Order("id").First(m)
+	tx := db.Where("ext_id = ?", m.ExtID).Where("connection_id = ?", m.ConnectionID).First(m)
 	err = tx.Error
 
 	return err
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 261d9a4..ad385b8 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_
@@ -4,7 +4,6 @@ import (
 	config "github.com/ManyakRus/starter/config_main"
 	"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_client"
 	"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
-	"math"
 	"testing"
 )
 
@@ -111,11 +110,44 @@ func TestDelete(t *testing.T) {
 
 	crud := Crud_GRPC{}
 	Otvet := lawsuit_status_types.LawsuitStatusType{}
-	Otvet.ID = math.MinInt64
-
-	err := crud.Delete(&Otvet)
+	Otvet.ID = Postgres_ID_Test
+	err := crud.Read(&Otvet)
 	if err != nil {
-		t.Error("TestDelete() error: ", err)
+		t.Error("TestRead() error: ", err)
+	}
+
+	if Otvet.IsDeleted == false {
+		err = crud.Delete(&Otvet)
+		if err != nil {
+			t.Error("TestDelete() error: ", err)
+		}
+		if Otvet.ID == 0 {
+			t.Error("TestDelete() error: ID =0")
+		}
+
+		err = crud.Restore(&Otvet)
+		if err != nil {
+			t.Error("TestDelete() error: ", err)
+		}
+		if Otvet.ID == 0 {
+			t.Error("TestDelete() error: ID =0")
+		}
+	} else {
+		err = crud.Restore(&Otvet)
+		if err != nil {
+			t.Error("TestDelete() error: ", err)
+		}
+		if Otvet.ID == 0 {
+			t.Error("TestDelete() error: ID =0")
+		}
+
+		err = crud.Delete(&Otvet)
+		if err != nil {
+			t.Error("TestDelete() error: ", err)
+		}
+		if Otvet.ID == 0 {
+			t.Error("TestDelete() error: ID =0")
+		}
 	}
 }
 
diff --git a/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table_test.go_ b/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table_test.go_
index 2a096d3..f28599b 100644
--- a/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table_test.go_
+++ b/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table_test.go_
@@ -5,7 +5,6 @@ import (
 	"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/nrpc_client"
 	"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
 	"testing"
-	"math"
 )
 
 // Postgres_ID_Test - ID таблицы для тестирования
@@ -111,10 +110,44 @@ func TestDelete(t *testing.T) {
 
 	crud := Crud_NRPC{}
 	Otvet := lawsuit_status_types.LawsuitStatusType{}
-	Otvet.ID = math.MinInt64
-	err := crud.Delete(&Otvet)
+	Otvet.ID = Postgres_ID_Test
+	err := crud.Read(&Otvet)
 	if err != nil {
-		t.Error("TestDelete() error: ", err)
+		t.Error("TestRead() error: ", err)
+	}
+
+	if Otvet.IsDeleted == false {
+		err = crud.Delete(&Otvet)
+		if err != nil {
+			t.Error("TestDelete() error: ", err)
+		}
+		if Otvet.ID == 0 {
+			t.Error("TestDelete() error: ID =0")
+		}
+
+		err = crud.Restore(&Otvet)
+		if err != nil {
+			t.Error("TestDelete() error: ", err)
+		}
+		if Otvet.ID == 0 {
+			t.Error("TestDelete() error: ID =0")
+		}
+	} else {
+		err = crud.Restore(&Otvet)
+		if err != nil {
+			t.Error("TestDelete() error: ", err)
+		}
+		if Otvet.ID == 0 {
+			t.Error("TestDelete() error: ID =0")
+		}
+
+		err = crud.Delete(&Otvet)
+		if err != nil {
+			t.Error("TestDelete() error: ", err)
+		}
+		if Otvet.ID == 0 {
+			t.Error("TestDelete() error: ID =0")
+		}
 	}
 }
 
diff --git a/examples/default/templates/configs_/crud_functions_rename.json b/examples/default/templates/configs_/crud_functions_rename.json
new file mode 100644
index 0000000..7a73a41
--- /dev/null
+++ b/examples/default/templates/configs_/crud_functions_rename.json
@@ -0,0 +1,2 @@
+{
+}
\ No newline at end of file
diff --git a/examples/default/templates/configs_/readme.txt b/examples/default/templates/configs_/readme.txt
index 1c44590..d3ef068 100644
--- a/examples/default/templates/configs_/readme.txt
+++ b/examples/default/templates/configs_/readme.txt
@@ -45,3 +45,17 @@ example:
 {
       "lawsuits": "NewLawsuit,AsLawsuit"
 }
+
+
+
+crud_functions_rename.json 
+TableName:{old:"",new:""}
+example:
+{
+      "functions": [
+	{
+	"old": "create_update_ctx",
+	"new":"create_update_ctx_original"
+	}
+	]
+}
diff --git a/examples/rapira/templates/configs_/crud_functions_rename.json b/examples/rapira/templates/configs_/crud_functions_rename.json
new file mode 100644
index 0000000..10c97af
--- /dev/null
+++ b/examples/rapira/templates/configs_/crud_functions_rename.json
@@ -0,0 +1,8 @@
+{
+  "lawsuits": [
+    {
+      "old": "create_update_ctx",
+      "new": "create_update_ctx_original"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/examples/rapira/templates/configs_/model_crud_delete_functions.json b/examples/rapira/templates/configs_/model_crud_delete_functions.json
index 6a8d05d..d8c0ee0 100644
--- a/examples/rapira/templates/configs_/model_crud_delete_functions.json
+++ b/examples/rapira/templates/configs_/model_crud_delete_functions.json
@@ -1,3 +1,3 @@
 {
-      "lawsuits": "NewLawsuit,AsLawsuit"
+      "lawsuits": "NewLawsuit,AsLawsuit,create_update_ctx"
 }
diff --git a/examples/rapira/templates/configs_/readme.txt b/examples/rapira/templates/configs_/readme.txt
index 1c44590..d3ef068 100644
--- a/examples/rapira/templates/configs_/readme.txt
+++ b/examples/rapira/templates/configs_/readme.txt
@@ -45,3 +45,17 @@ example:
 {
       "lawsuits": "NewLawsuit,AsLawsuit"
 }
+
+
+
+crud_functions_rename.json 
+TableName:{old:"",new:""}
+example:
+{
+      "functions": [
+	{
+	"old": "create_update_ctx",
+	"new":"create_update_ctx_original"
+	}
+	]
+}
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 dba3fc2..34b8f46 100644
--- a/internal/create_files/db_crud_tables/db_crud_tables.go
+++ b/internal/create_files/db_crud_tables/db_crud_tables.go
@@ -124,6 +124,9 @@ func CreateFiles(Table1 *types.Table) error {
 	//удаление пустого импорта
 	TextDB = create_files.DeleteEmptyImport(TextDB)
 
+	//переименование функций
+	TextDB = RenameFunctions(TextDB, Table1)
+
 	//запись файла
 	err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
 
@@ -417,3 +420,19 @@ func ReplaceText_created_at(s string, Table1 *types.Table) string {
 
 	return Otvet
 }
+
+func RenameFunctions(TextDB string, Table1 *types.Table) string {
+	Otvet := TextDB
+
+	TableName := strings.ToLower(Table1.Name)
+	Rename1, ok := types.MapRenameFunctions[TableName]
+	if ok == false {
+		return Otvet
+	}
+
+	for _, v := range Rename1 {
+		Otvet = strings.ReplaceAll(Otvet, " "+v.Old+"(", " "+v.New+"(")
+	}
+
+	return Otvet
+}
diff --git a/internal/load_configs/load_configs.go b/internal/load_configs/load_configs.go
index 0f86932..ce40668 100644
--- a/internal/load_configs/load_configs.go
+++ b/internal/load_configs/load_configs.go
@@ -22,6 +22,7 @@ func LoadConfigsAll() {
 	Load_TEXT_DB_IS_DELETED()
 	LoadConvertID()
 	LoadMapModelCrudDeleteFunctions()
+	LoadCrudFunctionsRename()
 }
 
 // LoadMappings - загружает маппинг ТипБД = ТипGolang, из файла .json
@@ -179,3 +180,26 @@ func Load_TEXT_DB_CREATED_AT() {
 	config.Settings.TEXT_DB_CREATED_AT = string(bytes)
 
 }
+
+// LoadCrudFunctionsRename - загружает маппинг ИмяТаблицы:{old:"",new:""}
+func LoadCrudFunctionsRename() {
+	dir := micro.ProgramDir_bin()
+	FileName := dir + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + constants.CONFIG_FOLDER_NAME + micro.SeparatorFile() + "crud_functions_rename.json"
+
+	var err error
+
+	//чтение файла
+	bytes, err := os.ReadFile(FileName)
+	if err != nil {
+		TextError := fmt.Sprint("ReadFile() error: ", err)
+		log.Panic(TextError)
+	}
+
+	//json в map
+	//var MapServiceURL2 = make(map[string]string)
+	err = json.Unmarshal(bytes, &types.MapRenameFunctions)
+	if err != nil {
+		log.Panic("Unmarshal() error: ", err)
+	}
+
+}
diff --git a/internal/load_configs/load_configs_test.go b/internal/load_configs/load_configs_test.go
index 9be78ce..43d7c76 100644
--- a/internal/load_configs/load_configs_test.go
+++ b/internal/load_configs/load_configs_test.go
@@ -1 +1,55 @@
 package load_configs
+
+import (
+	"encoding/json"
+	"github.com/ManyakRus/crud_generator/internal/config"
+	"github.com/ManyakRus/crud_generator/internal/constants"
+	"github.com/ManyakRus/crud_generator/internal/types"
+	"github.com/ManyakRus/starter/micro"
+	"os"
+	"testing"
+)
+
+func TestLoadCrudFunctionsRename(t *testing.T) {
+	config.LoadSettingsTxt()
+	config.FillSettings()
+	config.FillFlags()
+
+	LoadCrudFunctionsRename()
+}
+
+func TestSaveCrudFunctionsRename(t *testing.T) {
+	t.SkipNow()
+
+	var err error
+
+	config.LoadSettingsTxt()
+	config.FillSettings()
+	config.FillFlags()
+
+	dir := micro.ProgramDir_bin()
+	FileName := dir + config.Settings.TEMPLATE_FOLDERNAME + micro.SeparatorFile() + constants.CONFIG_FOLDER_NAME + micro.SeparatorFile() + "crud_functions_rename_test.json"
+
+	//File, _ := os.OpenFile(FileName, 0, 666)
+	//defer File.Close()
+
+	var bytes []byte
+	ReplaceStruct := types.ReplaceStruct{}
+	ReplaceStruct.Old = "create_update_ctx"
+	ReplaceStruct.New = "create_update_ctx_original"
+	FunctionsReplace := make([]types.ReplaceStruct, 0)
+	FunctionsReplace = append(FunctionsReplace, ReplaceStruct)
+	types.MapRenameFunctions["lawsuits"] = FunctionsReplace
+	//types.MapRenameFunctions["lawsuits2"] = FunctionsReplace
+	bytes, err = json.MarshalIndent(types.MapRenameFunctions, "", "  ")
+	if err != nil {
+
+	}
+
+	//_, err = File.Write([]byte("aaa"))
+	os.WriteFile(FileName, bytes, 0666)
+	if err != nil {
+
+	}
+
+}
diff --git a/internal/types/types.go b/internal/types/types.go
index 295b70e..cf791c9 100644
--- a/internal/types/types.go
+++ b/internal/types/types.go
@@ -24,6 +24,15 @@ type Table struct {
 	Comment     string `json:"table_comment"   gorm:"column:table_comment;default:''"`
 }
 
+type ReplaceStruct struct {
+	Old string `json:"old"`
+	New string `json:"new"`
+}
+
+//type FunctionsReplace struct {
+//	Functions []ReplaceStruct `json:"functions"`
+//}
+
 // MapReplaceName - карта замены имени поля на другое
 var MapReplaceName = make(map[string]string, 0)
 
@@ -35,3 +44,6 @@ var MapConvertID = make(map[string]string, 0)
 
 // MapModelCrudDeleteFunctions - карта функций которые будут удалены из файл model crud, ИмяТаблицыБД:ИмяФункцииГоу
 var MapModelCrudDeleteFunctions = make(map[string]string, 0)
+
+// MapRenameFunctions - карта функций которые будут переименованый в файлах crud
+var MapRenameFunctions = make(map[string][]ReplaceStruct, 0)