Development - Mago-DACH-Hub/documentation Wiki

1. Create the database table

The first step when creating an application is to create the necessary database table.
All databases are defined and hosted in the Dbl library of your application.
To create a new table you use the tblegacy tool:

PS C:\development\Standard\Applications\Comics\comics> tbl t CO_Collections
Welcome to the TBLegacy Table generator!
You are about to add a table to the comics module of the Comics application.
? Is it a codeless table? No
? Which is the hosting library ? Dbl
? Which kind of table you want: master
? Scaffold some default fields (Y) or start with no fields (n)? Yes
    force ..\..\..\..\..\Users\klemic\.yo-rc-global.json
   create DatabaseScript\Create\All\CO_Collections.sql
    force DatabaseScript\Create\CreateInfo.xml
   create Dbl\TCollections.h
   create Dbl\TCollections.cpp
    force Dbl\DblInterface.cpp
    force Dbl\Dbl.vcxproj
    force ModuleObjects\DatabaseObjects.xml
    force EFCore\EFSchemaObjects.xml

No change to package.json was detected. No package manager install will be executed.

The TBLegacy Table Generator creates a .cpp and a .h file for your table and registers the class into your Library Interface:

/* EXAMPLE DblInterface.cpp */
        REGISTER_TABLE		(TTest)

Then open the folder DatabaseScript and write your .sql script in the Create/All folder.

├── Create
│   ├── All
│   │   ├── Alter_MA_InventoryReasons.sql
│   │   ├── Alter_MA_Items.sql
│   │   ├── CO_Boxes.sql
│   │   └── CO_Collections.sql
│   └── CreateInfo.xml

Another important file is CreateInfo.xml. This is where the table is defined as a step and linked to a SQL-Script:

<?xml version="1.0" encoding="UTF-8"?>
    <ModuleInfo name="comics" />
        <Step numstep="1" script="CO_Collections.sql" />
        <Step numstep="2" script="CO_Boxes.sql" />
        <Step numstep="3" script="Alter_MA_Items.sql" />
	<Step numstep="4" script="Alter_MA_InventoryReasons.sql" />
    <Level2 />

The other file used by the AdministrationConsole to be aware of the changes is ModuleObjects/DatabaseObjects.xml:

<?xml version="1.0" encoding="UTF-8"?>
        <Table namespace="Comics.comics.Dbl.CO_Collections" mastertable="true" >
            <Create release="1" createstep="1" />
        <Table namespace="Comics.comics.Dbl.CO_Boxes" mastertable="true" >
            <Create release="2" createstep="1" />
        <Table namespace="Comics.comics.Dbl.CO_CollectionsBox" >
            <Create release="2" createstep="1" />
        <Table namespace="Comics.comics.Dbl.CO_ReceiptsBox" >
            <Create release="2" createstep="1" />

After that you should be able to run the AdministrationConsole and alter the database structure by right clicking on the company and selecting create/update database structure.

⚠️ ** Fallback** ⚠️