zAddField_Proc (procedure)
- Type: PROCEDURE
- Deterministic: NO
- SQL data access: CONTAINS SQL
Parameters
| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | sColumnName |
varchar(100) |
| 2 | IN | sTableName |
varchar(100) |
| 3 | IN | sType |
varchar(100) |
| 4 | IN | sDefault |
varchar(100) |
| 5 | IN | sIsNull |
varchar(100) |
| 6 | IN | sComment |
varchar(255) |
Body
Body is not pre-cached. To inspect: mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDUREzAddFieldProc'._
Narrative
Business context: Maintenance / migration helper (lower-case z-prefixed). Idempotent column-adder used by Flyway scripts and several DB routines to grow a business table by one new column without failing when the column already exists — ALTER TABLE ... ADD COLUMN only fires when information_schema.COLUMNS shows the column is missing.
What it does: Reads the current schema via SELECT DATABASE(), lower-cases sType. Guards with IF NOT EXISTS (SELECT * FROM information_schema.COLUMNS WHERE COLUMN_NAME=sColumnName AND TABLE_SCHEMA=sTableSchema AND TABLE_NAME=sTableName). When sDefault is '' it picks a type-appropriate default ('', 0, 0.000000, b'0', now()); when non-empty it formats the value for the type. Builds ALTER TABLE \` ADD COLUMN `` and runs it throughPREPARE/EXECUTE. Skips entirely whensTableName='salsalesorderslave'(hardcoded carve-out). Also inserts the table name into aaaa(bb)` audit-stub row before the ALTER — likely leftover from prior debugging.
Invocation: Used by other DB routines: sp_do_initsysjurisdiction, sp_int_dbSet, Sp_sYzfy_JN. Extensively called by Flyway migrations under xly-src/xlyEntry/src/main/resources/flyway/V*.sql, xlyFace/.../V*.sql, xlyPlc/.../V*.sql plus customer upgrade scripts in script/标版/upgrade/ (e.g. V2.0.21__20240125_addColumn.sql, 20220105-2751-保存、删除调过程/zAddFieldProc.sql). Fires whenever the application boot path runs Flyway or a maintainer applies a manual upgrade SQL. The INSERT into aaa(bb) debug write will fail if table aaa is absent — flag for cleanup.