Skip to main content

A table's structure

A table of a SQL connector can carry its structure — its columns and indexes — when it belongs to the application: a table of settings, of references, of results that no other system creates. The framework then creates the table in the database and keeps it up to date: a missing column or index is added, a text or a number widened, on demand from the table's Structure stage and at each liberty-admin migrate. Nothing is ever dropped, narrowed or retyped by itself. A table without a structure — a JD Edwards table, a table of another system — is never touched.

Open it from Liberty Next → Data → Connectors → a SQL connector → Tables → a table → the Structure stage, between General and Read.


At a glance​

customers· connector crmGeneralStructure5 column(s) · created and widened by the frameworkReadsetUpdatesetInsertsetDeletesetThe table the application owns: the framework creates it, adds a missing column or index, widens a text or a number — on demand hereand at each upgrade (liberty-admin migrate). Nothing is dropped, narrowed or retyped by itself.Databasecrm_test ▾Checked, applied, read and loaded on this one. An upgrade (liberty-admin migrate) applies the structure to every database of the connector.customersSchema (empty: the connection's)ColumnsNAMETYPESIZE / DIGITSDECIMALSKEYREQUIREDDEFAULTDICTIONARY ITEMcustomer_idLarge whole number ▾CUSTOMER_ID↑ ↓ 🗑nameText ▾120NAME↑ ↓ 🗑countryText ▾2FRCOUNTRY↑ ↓ 🗑credit_limitDecimal number ▾1520↑ ↓ 🗑created_atDate and time ▾↑ ↓ 🗑+ Add a columnIndexescustomers_ix1countryUnique+ Add an indexPreview the changes▶ Apply to the databaseWrite the statementsRead it from the databaseForget the structure2 statement(s) bring customers to what is declared.• country: 3 characters in the database, 2 declared — a column is not narrowedKept, not declared: legacy_code.ALTER TABLE customers ADD credit_limit NUMERIC(15, 2) DEFAULT 0;CREATE INDEX customers_ix1 ON customers (country)Load a fileA spreadsheet or a delimited file, its first row naming the columns: every row goes in, or none.customers.xlsxEmpty the table first⤒ LoadStructure stagebetween General and ReadName in the databaseempty: the table's ownColumnstype, size, key, required, defaultIndexesname, columns, uniqueRefused, and whynarrower, retyped, key changedLoad a filexlsx / csv, all rows or noneDictionary itemlabel and rules of the columnPreview the changesreads only, says what is missingApply to the databasestatements shown, one transactionRead it from the databasea table already thereThe statementsin the database's own dialectDatabasewhen the connector has several

Three kinds of table​

The stage card says which kind the table is, and the stage shows what fits:

The card saysThe tableThe stage shows
not the application'sDeclares no structure: the framework never creates nor changes it (a JD Edwards table, a table of another system).A short explanation, Declare its structure and Read it from the database.
N column(s) · created and widened by the frameworkDeclares its structure.The editor of the columns and indexes, the buttons that compare and apply it, and Load a file.
N column(s) · owned by nomasx1Belongs to an installed application, which creates and changes it at each of its upgrades.Its columns and indexes, read-only — see An application's own tables.

Declare a structure​

Two ways to start:

  • Declare its structure starts from one column, id, a Large whole number that is the key.
  • Read it from the database fills the structure from the table the database already has — its columns, their types and sizes, the key, the indexes. The usual way for a table created by hand or by a script, whose structure the framework should look after.

Above the columns, two fields:

FieldEffect
Its name in the database (empty: the table's own name)The name of the table in the database, when it differs from the table's name in the connector.
Schema (empty: the connection's)The database schema the table is in. Empty, the schema the pool's account works in.

The structure is saved with the connector by Save on the Connectors page. Declaring, changing or forgetting it changes nothing in the database by itself: Apply to the database does, and so does the next liberty-admin migrate.

Columns​

ColumnEffect
NameThe column's name in the database: letters, digits and _, starting with a letter.
TypeText, Whole number, Large whole number, Decimal number, Date, Date and time, Yes / no, Long text — written in each database's own type.
Size / digitsA Text: the most characters it holds, 255 when empty (4,000 at most). A Decimal number: its digits in all (38 at most); empty, as many as the database allows.
DecimalsA Decimal number: the digits after the decimal point.
KeyPart of the table's primary key. A key column is always required. No automatic numbering: a key value comes from the data or from a sequence, as the screens expect.
RequiredThe column may not be left empty.
DefaultThe value written when a row gives none — a number as digits, a text as it is.
Dictionary itemThe dictionary entry that names and formats the column in the screens.

The arrows move a column up or down; the bin removes it from the structure — not from the database. Add a column adds a Text column at the end.

Indexes​

Each index has a Name (offered as <table>_ix1, <table>_ix2…), its Columns, separated by commas, in order, and Unique when no two rows may share the same values. Add an index adds one.

Checks​

A banner lists what keeps the structure from being compared or applied, and the buttons stay disabled until it is fixed:

MessageCause
Declare at least one column.The structure has no column.
Column X: letters, digits and _ only.A column name is empty or holds another character.
Column X is declared twice.Two columns have the same name (case ignored).
Index X: give it a name and columns of the table.An index has no name, no column, or a column the structure does not declare.

Compare and apply​

ButtonEffect
Preview the changesCompares the structure, as it is on the page — saved or not — with the table in the connector's database, and shows the statements that would bring it there. Reads only.
Apply to the databaseShows the same statements in a confirmation; once confirmed, runs them in one transaction — all of them or none.

The answer is a banner, with the statements beneath it:

  • customers is as declared: nothing to do.
  • customers does not exist: 3 statement(s) create it. — the table with its key, then its indexes.
  • 2 statement(s) bring customers to what is declared.
  • customers: 2 statement(s) applied.

The statements are written in the dialect of the connector's database — PostgreSQL, Oracle, SQL Server, MySQL, MariaDB… On SQLite, which does not enforce a column's size, nothing is widened.

Several databases​

When the connector serves several databases — a connector on several databases —, a Database picker appears under the stage's explanation, set to the connector's own pool at first: Checked, applied, read and loaded on this one. Preview the changes, Apply to the database, Read it from the database and Load a file work on the database picked. liberty-admin migrate applies the structure to every database of the connector.

What is done​

In the structureIn the database
A table the database lacksCreated, with its key and indexes.
A column the table lacksAdded. A required column also needs a Default: a table that already has rows would refuse it.
A Text given a larger sizeWidened.
A Decimal number given more digitsWidened.
A column unticked RequiredMade optional.
An index the table lacksCreated.

What is refused​

A change that could lose data or fail on the rows already there is not made. The banner lists it with the reason, and the rest is applied:

ChangeReason given
A column narrowed — fewer characters or fewer digitsa column is not narrowed / a number is not narrowed
A column given another typea type is not changed — except a Whole number column of the database declared as Large whole number or Decimal number, which is accepted as it is.
A column the database lets empty, declared Requiredmade required by hand once every row has a value
A new Required column without a Defaulta new column that may not be empty needs a default
Another primary keya key is not changed

A column the database has and the structure does not declare is kept, and said: Kept, not declared: legacy_code. Such a change is made by hand on the database — then Read it from the database brings the structure in line.


Write the statements​

Write the statements writes the table's four statements — Read, Update, Insert, Delete — from its columns, with the conventions the screens use: upper-case parameters (:NAME), and a row found by its key's original value (:CUSTOMER_ID_ORIGINAL). The write statements are marked writable. A table without a key gets the Read only. When the table already has statements, a confirmation names those that will be replaced.


Forget the structure​

Forget the structure removes the declaration from the connector, after a confirmation. The table stays in the database as it is; the framework neither creates nor changes it.


Load a file​

Load a file, at the bottom of the stage, fills the table from a spreadsheet (.xlsx, .xlsm) or a delimited file (.csv, .txt, .tsv) — reference values, a first set of settings:

  • the first row names the columns; each column of the file goes into the table's column of the same name, its values converted to the column's type;
  • every row goes in, or none: the first line that cannot be read stops the load and is named — customers.csv, line 42: … — nothing was loaded;
  • Empty the table first deletes the table's rows before loading, in the same transaction;
  • the table must exist in the database — apply its structure first; a file of more than 200,000 rows is refused.

The answer gives the rows loaded and the columns they filled: 1,240 row(s) loaded (customer_id, name, country). For a file that comes back every day or every month, a Nomaflow job with a file_load step is the tool: rejects kept, partitions, a watched folder.


An application's own tables​

An installed application — Nomasx-1, Nomajde — creates and changes its own tables at each of its upgrades. On a connector that reaches the database of such an application, a table it owns shows, in its Structure stage, the columns the application gives it — Name, Type, Key, Required — and its indexes, read-only, under the banner The application nomasx1 owns this table…. To change such a table, change the application: a structure declared on top of it would compete with its upgrades.

Write the statements and Load a file stay available on these tables.


At each upgrade​

liberty-admin migrate — run by every upgrade, ./liberty upgrade and liberty-ops upgrade — applies every declared table on each database of its connector, as Apply to the database does: the missing tables are created, what they lack is added, the refused changes are listed. --dry-run lists the tables that would change without touching them. A table that fails does not stop the others. When the command is limited to one application (--app), the declared tables are left aside. See Schema migrations and the CLI.


Under the hood​

The structure is saved with the table in connectors.toml, under the table's structure. The Structure stage is the way to edit it.


Access​

The Connectors page belongs to the Liberty Next workspace: superusers only. The server checks it on each call — preview, apply, read, load.


Tips & best practices​

  • Start from the database: for a table that already exists, Read it from the database gives the exact columns and key; then adjust.
  • Preview before applying, on each database of the connector — pick it in Database: a table may differ from one database to another.
  • Give a required column a default when the table already has rows — or add it optional, fill it, then make it required by hand.
  • Fill the Dictionary item of each column: the screens then show its label and format without more work.
  • Load reference values with Load a file once; for a file that keeps coming, use a Nomaflow job.