GB5 Framework — Deployment Script

Mail Approval, from Zero

A complete, self-contained CREATE TABLE + INSERT script for standing up the entire mail approve/reject pipeline on a brand-new, empty client database that has none of it yet — modeled 1:1 on the Leave workflow, after its own bugs were found and fixed on the live reference server.

✓ all 15 CREATE TABLE statements actually executed live, then dropped ✓ seed data dry-run tested against unisoftgb4 Reference entity: Leave (TLeave) 15 tables created · ~30 rows seeded
Before you run it

What this script assumes

Nothing about this feature. The only tables assumed to already exist are the absolute platform bootstrap layer — the handful every single GB5 module depends on, regardless of feature: MCLIENT (tenant), MUSER (users), MROLE / MUSERGROUP (permissions), MORGANIZATIONUNIT (org structure), MENTITY (the entity registry), and MAUTONUMBER (the global id generator). It also assumes your target entity (e.g. TLeave) is already registered in MENTITY, since that happens as part of that module's own deployment, not here. Every other table — all 15 of them — is created by Part A below.

All 15 tables this feature touches are created here, not just the 4 exotic ones. MWORKFLOWCONFIG, MWORKFLOW, MWORKFLOWDETAIL, and MWORKFLOWASSIGNMENT were found to have no create-table script anywhere in the GB5 repository at all — every existing deployment's copy was hand-introspected from a live database. But a genuinely empty client database won't have MACTION, MEVENTTYPE, MMAILTEMPLATE, MDIRECTACTION and the rest either — so Part A creates all 15, every column/default/constraint captured directly from the live, working schema, not guessed.
Reusing this for a different entity

Placeholders in the script

Everything below is written against Leave. To reuse it for a different document type, search the script for @@ and replace each of these seven placeholders.

PlaceholderWhat it meansLeave's real value
@@ENTITY_NAME@@Human name for the workflow/mails, e.g. "Expense" or "Purchase Order"Leave
@@ENTITY_TABLE@@The entity's table/DTO name prefixTLeave
@@ENTITY_ID@@MENTITY.ENTITYID for the target table — look it up first-1399999827
@@APPROVER_FIELD@@The field naming the approver, resolved by a DB_ENRICH qualifier before the workflow startsReportingToEmployeeId
@@CONTEXT_ID_FIELD@@The field holding the workflow task idWorkflowTaskId
@@ASSIGNEE_FIELD@@The field holding the assignee's user idAssignedToUserId
@@MAIL_FIELD@@The field the recipient's email address is read fromMailId
@@SAVE_ENDPOINT@@The entity's real save/action API, called when a button is clicked/WorkFlow/WorkFlowActions
Part A of 3

Create all 15 tables

Each is wrapped in IF OBJECT_ID(...) IS NULL, so this is safe to run even if some or all of them already exist. No placeholders in this part — it's identical for every entity. Foreign keys to tables outside this feature's scope (report/file/menu/job tables etc.) are deliberately not enforced, matching what the live reference database itself does.

Part A — CREATE TABLE

15 tables, dependency-ordered

      
Click into the block and select-all (Ctrl/Cmd+A) to copy.
Part B of 3

Seed the workflow, the buttons, the mails, and the wiring

One continuous script, in dependency order — replace the @@...@@ placeholders first, then run top to bottom in a single connection (the steps chain together through T-SQL variables, so they can't be split across separate query windows).

Why the ID-allocation looks defensive, not simple: a real dry run of this exact script against unisoftgb4 caught MAUTONUMBER's stored counters for MACTION and MEVENTTYPEACTION already out of sync with the real table contents — years of manual seed scripts had inserted rows without going through AutoNumber. A naive "read the counter, then decrement" pattern collided with real existing rows. Every allocation below reads the counter, walks past any id that's already taken, then persists the counter one below whatever id was actually used — safe whether or not your target database has the same drift.

Part B — Seed data

11 steps, ~30 inserts

      
Click into the block and select-all (Ctrl/Cmd+A) to copy.
Part C of 3

Verify it worked

Run this last. Expect exactly 4 rows back — one per event (the "please review" trigger, Approved, Rejected, Returned) — each pointing at the right mail template with the right recipient.

Part C — Verification query

expect 4 rows

      
Click into the block and select-all (Ctrl/Cmd+A) to copy.
How this was actually proven, not just written

Validation performed before this script was handed over

1

Schema captured from the live, working database

Every column, type, default, primary key, foreign key, and check constraint for all 15 tables was read directly from unisoftgb4's system catalogs (sys.columns, sys.foreign_keys, sys.check_constraints) — not copied from repository migration files, several of which were found to be stale or incomplete.

2

All 15 CREATE TABLE statements actually run, then torn down

Part A was executed for real against live unisoftgb4 — in an isolated schema (zzstagetest), not dbo, so nothing touched the real reference data — with every foreign key pointing at the real MCLIENT/MUSER/MENTITY/MORGANIZATIONUNIT rows and every internal FK chained between the 15 new tables. All 15 created without a single error; verified via sys.tables; then every constraint and table was dropped, leaving the database exactly as it was before.

3

Every required column cross-checked

Every NOT-NULL-with-no-default column across all 11 base-schema seed tables was enumerated and checked against this script's INSERT statements — this caught two real missing columns (MMAILTEMPLATE.ATTACHMENTFILEID/BODYFILEID, MEVENTTYPEACTION.TRIGGERREPORTID) that would otherwise have failed on first run.

4

Seed data executed for real, inside a rolled-back transaction

The full seed script (Part B), with placeholders substituted for Leave, was run against live unisoftgb4 wrapped in BEGIN TRANSACTION / ROLLBACK — proving every statement actually executes without error, with nothing permanently written. This first run caught the MAUTONUMBER drift described above; the script was fixed and re-run clean.