feat(suppliers)!: full customers model - structured address + custom fields
The dodavatele modal is now an exact mirror of the customers modal (minus the PDF field-order picker): Nazev+ARES, Ulice, Mesto+PSC, Zeme, ICO+ARES, DIC, and the same "Vlastni pole" editor (maxWidth md). Two migrations on sklad_suppliers: - structured street/city/postal_code/country replace the free-text address blob (best-effort split: street / PSC regex / city) - custom_fields LONGTEXT replaces contact_person/email/phone/notes; existing values are preserved as labeled custom fields The encode/decode of the custom_fields blob is shared with customers via the new utils/custom-fields.ts. The PO PDF supplier block renders the structured address + custom-field lines like the customer block; the supplier picker/detail selects and types follow. Legacy clients sending the dropped keys are silently stripped (tested). Suppliers list shows Ulice/Mesto instead of the dropped contact columns; search covers name/ico/city. BREAKING CHANGE: sklad_suppliers.address, contact_person, email, phone, notes columns dropped (data migrated); deploy must run prisma migrate deploy + generate. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
-- Suppliers get a structured address (street/city/postal_code/country) like
|
||||
-- customers; the single free-text `address` blob is dropped. Existing data is
|
||||
-- split best-effort: newlines normalized to ", ", first comma segment ->
|
||||
-- street, the PSC (3+2 digits) -> postal_code, the remainder -> city.
|
||||
-- Unparseable one-segment addresses keep their full text in `street`.
|
||||
|
||||
-- AlterTable: add the structured columns
|
||||
ALTER TABLE `sklad_suppliers`
|
||||
ADD COLUMN `street` VARCHAR(255) NULL AFTER `phone`,
|
||||
ADD COLUMN `city` VARCHAR(255) NULL AFTER `street`,
|
||||
ADD COLUMN `postal_code` VARCHAR(20) NULL AFTER `city`,
|
||||
ADD COLUMN `country` VARCHAR(100) NULL AFTER `postal_code`;
|
||||
|
||||
-- Preserve data: best-effort split of the legacy free-text address
|
||||
UPDATE `sklad_suppliers`
|
||||
SET
|
||||
`street` = NULLIF(TRIM(SUBSTRING_INDEX(REPLACE(REPLACE(`address`, '\r', ''), '\n', ', '), ',', 1)), ''),
|
||||
`postal_code` = REGEXP_SUBSTR(`address`, '[0-9]{3}[ ]?[0-9]{2}'),
|
||||
`city` = NULLIF(TRIM(BOTH ',' FROM TRIM(REGEXP_REPLACE(
|
||||
SUBSTRING(
|
||||
REPLACE(REPLACE(`address`, '\r', ''), '\n', ', '),
|
||||
CHAR_LENGTH(SUBSTRING_INDEX(REPLACE(REPLACE(`address`, '\r', ''), '\n', ', '), ',', 1)) + 2
|
||||
),
|
||||
'[0-9]{3}[ ]?[0-9]{2}', ''))), '')
|
||||
WHERE `address` IS NOT NULL AND `address` <> '';
|
||||
|
||||
-- AlterTable: drop the legacy blob
|
||||
ALTER TABLE `sklad_suppliers` DROP COLUMN `address`;
|
||||
Reference in New Issue
Block a user