mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2025-01-03 01:22:21 +02:00
сделал ./crud_functions_rename.json
This commit is contained in:
parent
3c64c2a56b
commit
1965956ffa
@ -5,7 +5,8 @@ FILEMAIN=./cmd/$(SERVICENAME)/main.go
|
|||||||
FILEAPP=./bin/$(SERVICENAME)
|
FILEAPP=./bin/$(SERVICENAME)
|
||||||
|
|
||||||
NEW_REPO=$(SERVICENAME)
|
NEW_REPO=$(SERVICENAME)
|
||||||
GENERATION_PROTO=cd ./api && ./generation_code.sh
|
CD_GENERATION_PROTO=cd ./api
|
||||||
|
GENERATION_PROTO=generation_code.sh
|
||||||
|
|
||||||
|
|
||||||
run:
|
run:
|
||||||
@ -53,6 +54,7 @@ conn:
|
|||||||
init:
|
init:
|
||||||
clear
|
clear
|
||||||
go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service
|
go mod init gitlab.aescorp.ru/dsp_dev/claim/sync_service
|
||||||
|
$(CD_GENERATION_PROTO)
|
||||||
$(GENERATION_PROTO)
|
$(GENERATION_PROTO)
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go mod vendor
|
go mod vendor
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
bin/templates/configs_/crud_functions_rename.json
Normal file
8
bin/templates/configs_/crud_functions_rename.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"lawsuits": [
|
||||||
|
{
|
||||||
|
"old": "create_update_ctx",
|
||||||
|
"new": "create_update_ctx_original"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
8
bin/templates/configs_/crud_functions_rename_test.json
Normal file
8
bin/templates/configs_/crud_functions_rename_test.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"lawsuits": [
|
||||||
|
{
|
||||||
|
"old": "create_update_ctx",
|
||||||
|
"new": "create_update_ctx_original"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
{
|
{
|
||||||
|
"lawsuits": "NewLawsuit,AsLawsuit,create_update_ctx"
|
||||||
}
|
}
|
||||||
|
@ -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"
|
||||||
}
|
}
|
@ -1,2 +1,4 @@
|
|||||||
{
|
{
|
||||||
|
"ext_id": true,
|
||||||
|
"created_at": false
|
||||||
}
|
}
|
||||||
|
@ -45,3 +45,17 @@ example:
|
|||||||
{
|
{
|
||||||
"lawsuits": "NewLawsuit,AsLawsuit"
|
"lawsuits": "NewLawsuit,AsLawsuit"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
crud_functions_rename.json
|
||||||
|
TableName:{old:"",new:""}
|
||||||
|
example:
|
||||||
|
{
|
||||||
|
"functions": [
|
||||||
|
{
|
||||||
|
"old": "create_update_ctx",
|
||||||
|
"new":"create_update_ctx_original"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
@ -21,15 +21,15 @@ DB_PASSWORD=
|
|||||||
INCLUDE_TABLES=""
|
INCLUDE_TABLES=""
|
||||||
|
|
||||||
#INCLUDE_TABLES - table name ignore filter. Regular expression
|
#INCLUDE_TABLES - table name ignore filter. Regular expression
|
||||||
EXCLUDE_TABLES=
|
EXCLUDE_TABLES="ext_"
|
||||||
|
|
||||||
#---------------------Template settings---------------------
|
#---------------------Template settings---------------------
|
||||||
|
|
||||||
#SERVICE_REPOSITORY_URL - URL of your new service repository (Github, gitlab, etc.)
|
#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 - 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 - service name in your template files
|
||||||
TEMPLATE_SERVICE_NAME=sync_service
|
TEMPLATE_SERVICE_NAME=sync_service
|
||||||
@ -96,7 +96,7 @@ TEXT_TEMPLATE_TABLENAME="lawsuit_status_types"
|
|||||||
USE_DEFAULT_TEMPLATE=true
|
USE_DEFAULT_TEMPLATE=true
|
||||||
|
|
||||||
#HAS_IS_DELETED - fill "true" if you have "is_deleted" column, and want Delete() Restore() functions.
|
#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---------------------
|
#---------------------Create files settings---------------------
|
||||||
|
|
||||||
|
@ -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/network/grpc/grpc_proto"
|
||||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||||
"testing"
|
"testing"
|
||||||
"math"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LawsuitStatusType_ID_Test - ID таблицы для тестирования
|
// LawsuitStatusType_ID_Test - ID таблицы для тестирования
|
||||||
@ -38,7 +37,7 @@ func Test_server_LawsuitStatusType_Delete(t *testing.T) {
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
Request := grpc_proto.RequestId{}
|
Request := grpc_proto.RequestId{}
|
||||||
Request.Id = math.MinInt64
|
Request.Id = LawsuitStatusType_ID_Test
|
||||||
Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
|
Request.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
|
||||||
|
|
||||||
server1 := &ServerGRPC{}
|
server1 := &ServerGRPC{}
|
||||||
|
@ -146,14 +146,12 @@ func (crud Crud_DB) create_update_ctx(ctx context.Context, m *lawsuit_status_typ
|
|||||||
if is_create == true {
|
if is_create == true {
|
||||||
if int64(m.ID) != 0 {
|
if int64(m.ID) != 0 {
|
||||||
TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0")
|
TextError := fmt.Sprint("db.Save() ", TableName, " error: id !=0")
|
||||||
// log.Panic(sError)
|
|
||||||
err = errors.New(TextError)
|
err = errors.New(TextError)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if int64(m.ID) == 0 {
|
} else if int64(m.ID) == 0 {
|
||||||
TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0")
|
TextError := fmt.Sprint("db.Save() ", TableName, " error: id =0")
|
||||||
err = errors.New(TextError)
|
err = errors.New(TextError)
|
||||||
// log.Panic(sError)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +208,7 @@ func (crud Crud_DB) Delete(m *lawsuit_status_types.LawsuitStatusType) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete_ctx - удаляет запись в БД
|
// Delete_ctx - записывает is_deleted = true
|
||||||
func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
|
func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.LawsuitStatusType) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -219,11 +217,53 @@ func (crud Crud_DB) Delete_ctx(ctx context.Context, m *lawsuit_status_types.Laws
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
db := postgres_gorm.GetConnection()
|
m2 := lawsuit_status_types.LawsuitStatusType{}
|
||||||
db.WithContext(ctx)
|
m2.ID = m.ID
|
||||||
|
err = crud.Read_ctx(ctx, &m2)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
tx := db.Delete(m)
|
m2.IsDeleted = true
|
||||||
err = tx.Error
|
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
|
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 := postgres_gorm.GetConnection()
|
||||||
db.WithContext(ctx)
|
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
|
err = tx.Error
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
config "github.com/ManyakRus/starter/config_main"
|
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/network/grpc/grpc_client"
|
||||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||||
"math"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,11 +110,44 @@ func TestDelete(t *testing.T) {
|
|||||||
|
|
||||||
crud := Crud_GRPC{}
|
crud := Crud_GRPC{}
|
||||||
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||||
Otvet.ID = math.MinInt64
|
Otvet.ID = Postgres_ID_Test
|
||||||
|
err := crud.Read(&Otvet)
|
||||||
err := crud.Delete(&Otvet)
|
|
||||||
if err != nil {
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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/network/nrpc/nrpc_client"
|
||||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types"
|
||||||
"testing"
|
"testing"
|
||||||
"math"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Postgres_ID_Test - ID таблицы для тестирования
|
// Postgres_ID_Test - ID таблицы для тестирования
|
||||||
@ -111,10 +110,44 @@ func TestDelete(t *testing.T) {
|
|||||||
|
|
||||||
crud := Crud_NRPC{}
|
crud := Crud_NRPC{}
|
||||||
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
Otvet := lawsuit_status_types.LawsuitStatusType{}
|
||||||
Otvet.ID = math.MinInt64
|
Otvet.ID = Postgres_ID_Test
|
||||||
err := crud.Delete(&Otvet)
|
err := crud.Read(&Otvet)
|
||||||
if err != nil {
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
@ -45,3 +45,17 @@ example:
|
|||||||
{
|
{
|
||||||
"lawsuits": "NewLawsuit,AsLawsuit"
|
"lawsuits": "NewLawsuit,AsLawsuit"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
crud_functions_rename.json
|
||||||
|
TableName:{old:"",new:""}
|
||||||
|
example:
|
||||||
|
{
|
||||||
|
"functions": [
|
||||||
|
{
|
||||||
|
"old": "create_update_ctx",
|
||||||
|
"new":"create_update_ctx_original"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"lawsuits": [
|
||||||
|
{
|
||||||
|
"old": "create_update_ctx",
|
||||||
|
"new": "create_update_ctx_original"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"lawsuits": "NewLawsuit,AsLawsuit"
|
"lawsuits": "NewLawsuit,AsLawsuit,create_update_ctx"
|
||||||
}
|
}
|
||||||
|
@ -45,3 +45,17 @@ example:
|
|||||||
{
|
{
|
||||||
"lawsuits": "NewLawsuit,AsLawsuit"
|
"lawsuits": "NewLawsuit,AsLawsuit"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
crud_functions_rename.json
|
||||||
|
TableName:{old:"",new:""}
|
||||||
|
example:
|
||||||
|
{
|
||||||
|
"functions": [
|
||||||
|
{
|
||||||
|
"old": "create_update_ctx",
|
||||||
|
"new":"create_update_ctx_original"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
@ -124,6 +124,9 @@ func CreateFiles(Table1 *types.Table) error {
|
|||||||
//удаление пустого импорта
|
//удаление пустого импорта
|
||||||
TextDB = create_files.DeleteEmptyImport(TextDB)
|
TextDB = create_files.DeleteEmptyImport(TextDB)
|
||||||
|
|
||||||
|
//переименование функций
|
||||||
|
TextDB = RenameFunctions(TextDB, Table1)
|
||||||
|
|
||||||
//запись файла
|
//запись файла
|
||||||
err = os.WriteFile(FilenameReadyDB, []byte(TextDB), constants.FILE_PERMISSIONS)
|
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
|
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
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@ func LoadConfigsAll() {
|
|||||||
Load_TEXT_DB_IS_DELETED()
|
Load_TEXT_DB_IS_DELETED()
|
||||||
LoadConvertID()
|
LoadConvertID()
|
||||||
LoadMapModelCrudDeleteFunctions()
|
LoadMapModelCrudDeleteFunctions()
|
||||||
|
LoadCrudFunctionsRename()
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadMappings - загружает маппинг ТипБД = ТипGolang, из файла .json
|
// LoadMappings - загружает маппинг ТипБД = ТипGolang, из файла .json
|
||||||
@ -179,3 +180,26 @@ func Load_TEXT_DB_CREATED_AT() {
|
|||||||
config.Settings.TEXT_DB_CREATED_AT = string(bytes)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -1 +1,55 @@
|
|||||||
package load_configs
|
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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -24,6 +24,15 @@ type Table struct {
|
|||||||
Comment string `json:"table_comment" gorm:"column:table_comment;default:''"`
|
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 - карта замены имени поля на другое
|
// MapReplaceName - карта замены имени поля на другое
|
||||||
var MapReplaceName = make(map[string]string, 0)
|
var MapReplaceName = make(map[string]string, 0)
|
||||||
|
|
||||||
@ -35,3 +44,6 @@ var MapConvertID = make(map[string]string, 0)
|
|||||||
|
|
||||||
// MapModelCrudDeleteFunctions - карта функций которые будут удалены из файл model crud, ИмяТаблицыБД:ИмяФункцииГоу
|
// MapModelCrudDeleteFunctions - карта функций которые будут удалены из файл model crud, ИмяТаблицыБД:ИмяФункцииГоу
|
||||||
var MapModelCrudDeleteFunctions = make(map[string]string, 0)
|
var MapModelCrudDeleteFunctions = make(map[string]string, 0)
|
||||||
|
|
||||||
|
// MapRenameFunctions - карта функций которые будут переименованый в файлах crud
|
||||||
|
var MapRenameFunctions = make(map[string][]ReplaceStruct, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user