Show correct table count matching filter in confirmation

This commit is contained in:
2026-03-29 18:27:49 +02:00
parent b229e039a3
commit 5483e2e1ae
4 changed files with 212 additions and 37 deletions

View File

@@ -1,31 +0,0 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package dbmodel
import "git.ma-al.com/goc_marek/gormcol"
const TableNamePsModuleShop = "ps_module_shop"
// PsModuleShop mapped from table <ps_module_shop>
type PsModuleShop struct {
IDModule int32 `gorm:"column:id_module;primaryKey" json:"id_module"`
IDShop int32 `gorm:"column:id_shop;primaryKey;index:id_shop,priority:1" json:"id_shop"`
EnableDevice bool `gorm:"column:enable_device;not null;default:7" json:"enable_device"`
}
// TableName PsModuleShop's table name
func (*PsModuleShop) TableName() string {
return TableNamePsModuleShop
}
var PsModuleShopCols = struct {
IDModule gormcol.Field
IDShop gormcol.Field
EnableDevice gormcol.Field
}{
IDModule: gormcol.Field{}.Set((&PsModuleShop{}).TableName(), "id_module"),
IDShop: gormcol.Field{}.Set((&PsModuleShop{}).TableName(), "id_shop"),
EnableDevice: gormcol.Field{}.Set((&PsModuleShop{}).TableName(), "enable_device"),
}

View File

@@ -0,0 +1,190 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package dbmodel
import (
"git.ma-al.com/goc_marek/gormcol"
"time"
)
const TableNamePsProduct = "ps_product"
// PsProduct mapped from table <ps_product>
type PsProduct struct {
IDProduct int32 `gorm:"column:id_product;primaryKey;autoIncrement:true;index:product_manufacturer,priority:2" json:"id_product"`
IDSupplier *int32 `gorm:"column:id_supplier;index:product_supplier,priority:1" json:"id_supplier"`
IDManufacturer *int32 `gorm:"column:id_manufacturer;index:idx_product_manufacturer,priority:1;index:product_manufacturer,priority:1" json:"id_manufacturer"`
IDCategoryDefault *int32 `gorm:"column:id_category_default;index:id_category_default,priority:1" json:"id_category_default"`
IDShopDefault int32 `gorm:"column:id_shop_default;not null;default:1" json:"id_shop_default"`
IDTaxRulesGroup int32 `gorm:"column:id_tax_rules_group;not null" json:"id_tax_rules_group"`
OnSale bool `gorm:"column:on_sale;not null" json:"on_sale"`
OnlineOnly bool `gorm:"column:online_only;not null" json:"online_only"`
Ean13 *string `gorm:"column:ean13" json:"ean13"`
Isbn *string `gorm:"column:isbn" json:"isbn"`
Upc *string `gorm:"column:upc" json:"upc"`
Ecotax float64 `gorm:"column:ecotax;not null;default:0.000000" json:"ecotax"`
Quantity int32 `gorm:"column:quantity;not null" json:"quantity"`
MinimalQuantity int32 `gorm:"column:minimal_quantity;not null;default:1" json:"minimal_quantity"`
LowStockThreshold *int32 `gorm:"column:low_stock_threshold" json:"low_stock_threshold"`
LowStockAlert bool `gorm:"column:low_stock_alert;not null" json:"low_stock_alert"`
Price float64 `gorm:"column:price;not null;default:0.000000" json:"price"`
WholesalePrice float64 `gorm:"column:wholesale_price;not null;default:0.000000" json:"wholesale_price"`
Unity *string `gorm:"column:unity" json:"unity"`
UnitPriceRatio float64 `gorm:"column:unit_price_ratio;not null;default:0.000000" json:"unit_price_ratio"`
IDUnit int32 `gorm:"column:id_unit;not null" json:"id_unit"`
AdditionalShippingCost float64 `gorm:"column:additional_shipping_cost;not null;default:0.00" json:"additional_shipping_cost"`
Reference *string `gorm:"column:reference" json:"reference"`
SupplierReference *string `gorm:"column:supplier_reference" json:"supplier_reference"`
Location *string `gorm:"column:location" json:"location"`
Width float64 `gorm:"column:width;not null;default:0.000000" json:"width"`
Height float64 `gorm:"column:height;not null;default:0.000000" json:"height"`
Depth float64 `gorm:"column:depth;not null;default:0.000000" json:"depth"`
Weight float64 `gorm:"column:weight;not null;default:0.000000" json:"weight"`
OutOfStock int32 `gorm:"column:out_of_stock;not null;default:2" json:"out_of_stock"`
AdditionalDeliveryTimes int32 `gorm:"column:additional_delivery_times;not null;default:1" json:"additional_delivery_times"`
QuantityDiscount *bool `gorm:"column:quantity_discount" json:"quantity_discount"`
Customizable int32 `gorm:"column:customizable;not null" json:"customizable"`
UploadableFiles int32 `gorm:"column:uploadable_files;not null" json:"uploadable_files"`
TextFields int32 `gorm:"column:text_fields;not null" json:"text_fields"`
Active bool `gorm:"column:active;not null" json:"active"`
RedirectType string `gorm:"column:redirect_type;not null" json:"redirect_type"`
IDTypeRedirected int32 `gorm:"column:id_type_redirected;not null" json:"id_type_redirected"`
AvailableForOrder bool `gorm:"column:available_for_order;not null;default:1" json:"available_for_order"`
AvailableDate *time.Time `gorm:"column:available_date" json:"available_date"`
ShowCondition bool `gorm:"column:show_condition;not null" json:"show_condition"`
Condition string `gorm:"column:condition;not null;default:new" json:"condition"`
ShowPrice bool `gorm:"column:show_price;not null;default:1" json:"show_price"`
Indexed bool `gorm:"column:indexed;not null;index:indexed,priority:1" json:"indexed"`
Visibility string `gorm:"column:visibility;not null;index:idx_product_visibility,priority:1;index:idx_ps_product_visibility,priority:1;index:idx_visibility,priority:1;default:both" json:"visibility"`
CacheIsPack bool `gorm:"column:cache_is_pack;not null" json:"cache_is_pack"`
CacheHasAttachments bool `gorm:"column:cache_has_attachments;not null" json:"cache_has_attachments"`
IsVirtual bool `gorm:"column:is_virtual;not null" json:"is_virtual"`
CacheDefaultAttribute *int32 `gorm:"column:cache_default_attribute" json:"cache_default_attribute"`
DateAdd time.Time `gorm:"column:date_add;not null;index:date_add,priority:1" json:"date_add"`
DateUpd time.Time `gorm:"column:date_upd;not null;index:state,priority:2" json:"date_upd"`
AdvancedStockManagement bool `gorm:"column:advanced_stock_management;not null" json:"advanced_stock_management"`
PackStockType int32 `gorm:"column:pack_stock_type;not null;default:3" json:"pack_stock_type"`
State int32 `gorm:"column:state;not null;index:state,priority:1;default:1" json:"state"`
DeliveryDays *int32 `gorm:"column:delivery_days" json:"delivery_days"`
}
// TableName PsProduct's table name
func (*PsProduct) TableName() string {
return TableNamePsProduct
}
var PsProductCols = struct {
IDProduct gormcol.Field
IDSupplier gormcol.Field
IDManufacturer gormcol.Field
IDCategoryDefault gormcol.Field
IDShopDefault gormcol.Field
IDTaxRulesGroup gormcol.Field
OnSale gormcol.Field
OnlineOnly gormcol.Field
Ean13 gormcol.Field
Isbn gormcol.Field
Upc gormcol.Field
Ecotax gormcol.Field
Quantity gormcol.Field
MinimalQuantity gormcol.Field
LowStockThreshold gormcol.Field
LowStockAlert gormcol.Field
Price gormcol.Field
WholesalePrice gormcol.Field
Unity gormcol.Field
UnitPriceRatio gormcol.Field
IDUnit gormcol.Field
AdditionalShippingCost gormcol.Field
Reference gormcol.Field
SupplierReference gormcol.Field
Location gormcol.Field
Width gormcol.Field
Height gormcol.Field
Depth gormcol.Field
Weight gormcol.Field
OutOfStock gormcol.Field
AdditionalDeliveryTimes gormcol.Field
QuantityDiscount gormcol.Field
Customizable gormcol.Field
UploadableFiles gormcol.Field
TextFields gormcol.Field
Active gormcol.Field
RedirectType gormcol.Field
IDTypeRedirected gormcol.Field
AvailableForOrder gormcol.Field
AvailableDate gormcol.Field
ShowCondition gormcol.Field
Condition gormcol.Field
ShowPrice gormcol.Field
Indexed gormcol.Field
Visibility gormcol.Field
CacheIsPack gormcol.Field
CacheHasAttachments gormcol.Field
IsVirtual gormcol.Field
CacheDefaultAttribute gormcol.Field
DateAdd gormcol.Field
DateUpd gormcol.Field
AdvancedStockManagement gormcol.Field
PackStockType gormcol.Field
State gormcol.Field
DeliveryDays gormcol.Field
}{
IDProduct: gormcol.Field{}.Set((&PsProduct{}).TableName(), "id_product"),
IDSupplier: gormcol.Field{}.Set((&PsProduct{}).TableName(), "id_supplier"),
IDManufacturer: gormcol.Field{}.Set((&PsProduct{}).TableName(), "id_manufacturer"),
IDCategoryDefault: gormcol.Field{}.Set((&PsProduct{}).TableName(), "id_category_default"),
IDShopDefault: gormcol.Field{}.Set((&PsProduct{}).TableName(), "id_shop_default"),
IDTaxRulesGroup: gormcol.Field{}.Set((&PsProduct{}).TableName(), "id_tax_rules_group"),
OnSale: gormcol.Field{}.Set((&PsProduct{}).TableName(), "on_sale"),
OnlineOnly: gormcol.Field{}.Set((&PsProduct{}).TableName(), "online_only"),
Ean13: gormcol.Field{}.Set((&PsProduct{}).TableName(), "ean13"),
Isbn: gormcol.Field{}.Set((&PsProduct{}).TableName(), "isbn"),
Upc: gormcol.Field{}.Set((&PsProduct{}).TableName(), "upc"),
Ecotax: gormcol.Field{}.Set((&PsProduct{}).TableName(), "ecotax"),
Quantity: gormcol.Field{}.Set((&PsProduct{}).TableName(), "quantity"),
MinimalQuantity: gormcol.Field{}.Set((&PsProduct{}).TableName(), "minimal_quantity"),
LowStockThreshold: gormcol.Field{}.Set((&PsProduct{}).TableName(), "low_stock_threshold"),
LowStockAlert: gormcol.Field{}.Set((&PsProduct{}).TableName(), "low_stock_alert"),
Price: gormcol.Field{}.Set((&PsProduct{}).TableName(), "price"),
WholesalePrice: gormcol.Field{}.Set((&PsProduct{}).TableName(), "wholesale_price"),
Unity: gormcol.Field{}.Set((&PsProduct{}).TableName(), "unity"),
UnitPriceRatio: gormcol.Field{}.Set((&PsProduct{}).TableName(), "unit_price_ratio"),
IDUnit: gormcol.Field{}.Set((&PsProduct{}).TableName(), "id_unit"),
AdditionalShippingCost: gormcol.Field{}.Set((&PsProduct{}).TableName(), "additional_shipping_cost"),
Reference: gormcol.Field{}.Set((&PsProduct{}).TableName(), "reference"),
SupplierReference: gormcol.Field{}.Set((&PsProduct{}).TableName(), "supplier_reference"),
Location: gormcol.Field{}.Set((&PsProduct{}).TableName(), "location"),
Width: gormcol.Field{}.Set((&PsProduct{}).TableName(), "width"),
Height: gormcol.Field{}.Set((&PsProduct{}).TableName(), "height"),
Depth: gormcol.Field{}.Set((&PsProduct{}).TableName(), "depth"),
Weight: gormcol.Field{}.Set((&PsProduct{}).TableName(), "weight"),
OutOfStock: gormcol.Field{}.Set((&PsProduct{}).TableName(), "out_of_stock"),
AdditionalDeliveryTimes: gormcol.Field{}.Set((&PsProduct{}).TableName(), "additional_delivery_times"),
QuantityDiscount: gormcol.Field{}.Set((&PsProduct{}).TableName(), "quantity_discount"),
Customizable: gormcol.Field{}.Set((&PsProduct{}).TableName(), "customizable"),
UploadableFiles: gormcol.Field{}.Set((&PsProduct{}).TableName(), "uploadable_files"),
TextFields: gormcol.Field{}.Set((&PsProduct{}).TableName(), "text_fields"),
Active: gormcol.Field{}.Set((&PsProduct{}).TableName(), "active"),
RedirectType: gormcol.Field{}.Set((&PsProduct{}).TableName(), "redirect_type"),
IDTypeRedirected: gormcol.Field{}.Set((&PsProduct{}).TableName(), "id_type_redirected"),
AvailableForOrder: gormcol.Field{}.Set((&PsProduct{}).TableName(), "available_for_order"),
AvailableDate: gormcol.Field{}.Set((&PsProduct{}).TableName(), "available_date"),
ShowCondition: gormcol.Field{}.Set((&PsProduct{}).TableName(), "show_condition"),
Condition: gormcol.Field{}.Set((&PsProduct{}).TableName(), "condition"),
ShowPrice: gormcol.Field{}.Set((&PsProduct{}).TableName(), "show_price"),
Indexed: gormcol.Field{}.Set((&PsProduct{}).TableName(), "indexed"),
Visibility: gormcol.Field{}.Set((&PsProduct{}).TableName(), "visibility"),
CacheIsPack: gormcol.Field{}.Set((&PsProduct{}).TableName(), "cache_is_pack"),
CacheHasAttachments: gormcol.Field{}.Set((&PsProduct{}).TableName(), "cache_has_attachments"),
IsVirtual: gormcol.Field{}.Set((&PsProduct{}).TableName(), "is_virtual"),
CacheDefaultAttribute: gormcol.Field{}.Set((&PsProduct{}).TableName(), "cache_default_attribute"),
DateAdd: gormcol.Field{}.Set((&PsProduct{}).TableName(), "date_add"),
DateUpd: gormcol.Field{}.Set((&PsProduct{}).TableName(), "date_upd"),
AdvancedStockManagement: gormcol.Field{}.Set((&PsProduct{}).TableName(), "advanced_stock_management"),
PackStockType: gormcol.Field{}.Set((&PsProduct{}).TableName(), "pack_stock_type"),
State: gormcol.Field{}.Set((&PsProduct{}).TableName(), "state"),
DeliveryDays: gormcol.Field{}.Set((&PsProduct{}).TableName(), "delivery_days"),
}

View File

@@ -7,11 +7,11 @@ import (
"log/slog" "log/slog"
"os" "os"
"os/exec" "os/exec"
"regexp"
"strings" "strings"
"time" "time"
"git.ma-al.com/goc_marek/gormcol" "git.ma-al.com/goc_marek/gormcol"
"git.ma-al.com/goc_marek/gormcol/app/model/dbmodel"
"github.com/joho/godotenv" "github.com/joho/godotenv"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -21,8 +21,6 @@ import (
// and generates GORM models with column descriptors. // and generates GORM models with column descriptors.
func main() { func main() {
fmt.Printf("gormcol.Column(dbmodel.PsModuleShop.IDModule): %v\n", dbmodel.PsModuleShopCols.EnableDevice.TabCol())
dsn := flag.String("dsn", "", "database DSN (e.g. user:pass@tcp(host:3306)/dbname)") dsn := flag.String("dsn", "", "database DSN (e.g. user:pass@tcp(host:3306)/dbname)")
filter := flag.String("filter", "", "regex to match table names (triggers batch mode)") filter := flag.String("filter", "", "regex to match table names (triggers batch mode)")
all := flag.Bool("all", false, "generate all tables matching filter (shows confirmation)") all := flag.Bool("all", false, "generate all tables matching filter (shows confirmation)")
@@ -84,7 +82,7 @@ func main() {
yellow := "\033[33m" yellow := "\033[33m"
reset := "\033[0m" reset := "\033[0m"
fmt.Printf("%sBatch mode:%s generating tables matching filter '%s'\n", yellow, reset, cfg.TableFilter) fmt.Printf("%sBatch mode:%s generating tables matching filter '%s'\n", yellow, reset, cfg.TableFilter)
if !confirmGenerateAll(db) { if !confirmGenerateAll(db, cfg.TableFilter) {
fmt.Println("Aborted.") fmt.Println("Aborted.")
os.Exit(0) os.Exit(0)
} }
@@ -138,7 +136,7 @@ func selectTablesInteractive(db *gorm.DB) ([]string, error) {
// confirmGenerateAll displays a confirmation prompt before generating all tables. // confirmGenerateAll displays a confirmation prompt before generating all tables.
// Returns true if user confirms, false if cancelled or timeout. // Returns true if user confirms, false if cancelled or timeout.
func confirmGenerateAll(db *gorm.DB) bool { func confirmGenerateAll(db *gorm.DB, filter string) bool {
type migratorWithGetTables interface { type migratorWithGetTables interface {
GetTables() ([]string, error) GetTables() ([]string, error)
} }
@@ -153,10 +151,28 @@ func confirmGenerateAll(db *gorm.DB) bool {
return false return false
} }
// Count tables matching the filter.
re, err := regexp.Compile("^" + filter + "$")
if err != nil {
return false
}
var matched int
for _, name := range tableNames {
if re.MatchString(name) {
matched++
}
}
if matched == 0 {
fmt.Printf("No tables match filter '%s'.\n", filter)
return false
}
// Display yellow warning message and wait for user input. // Display yellow warning message and wait for user input.
yellow := "\033[33m" yellow := "\033[33m"
reset := "\033[0m" reset := "\033[0m"
msg := fmt.Sprintf("%sWARNING:%s Generate all %d tables? [Enter] confirm / [Esc] cancel", yellow, reset, len(tableNames)) msg := fmt.Sprintf("%sWARNING:%s Generate all %d tables? [Enter] confirm / [Esc] cancel", yellow, reset, matched)
script := fmt.Sprintf(`echo; echo -e '%s'; read -t 10 -n 1 -s key; if [[ -z "$key" ]]; then exit 0; elif [[ "$key" == $'\e' ]]; then exit 1; else exit 0; fi`, msg) script := fmt.Sprintf(`echo; echo -e '%s'; read -t 10 -n 1 -s key; if [[ -z "$key" ]]; then exit 0; elif [[ "$key" == $'\e' ]]; then exit 1; else exit 0; fi`, msg)
cmd := exec.Command("bash", "-c", script) cmd := exec.Command("bash", "-c", script)

BIN
gormcol

Binary file not shown.