Jump to content

ICT:Automatic Numbering: Difference between revisions

From Costa Sano MediaWiki
Created page with "== ICT Documentation: Automatic Identifier Logic (Lua) == The `DigitalAssets` table uses a Lua script (Module:AssetIdentifier) to ensure unique, sequential numbering. === 1. Input Variables === The script requires three inputs from the Form:DigitalAsset: * `chapter_id` (from ResearchChapters) * `context_code` (from Places or Organisations) * `sequence_number` (calculated automatically) === 2. Identifier Construction === The final ID is constructed using the pa..."
 
No edit summary
 
Line 16: Line 16:
=== 3. Maintenance Note ===
=== 3. Maintenance Note ===
If a record is deleted, the `sequence_number` for that specific context will have a "gap." This is acceptable in archival practice to maintain the integrity of existing permalinks.
If a record is deleted, the `sequence_number` for that specific context will have a "gap." This is acceptable in archival practice to maintain the integrity of existing permalinks.
== ICT Documentation: Sequential Numbering (Lua) ==
To generate the `sequence_number` (e.g., 0007), the Lua module performs a Cargo query on the `DigitalAssets` table before the save is finalized.
=== 1. The Lookup Query ===
The script filters by `chapter_id` AND `context_code`:
<pre>
local results = mw.ext.cargo.query(
    'DigitalAssets',
    'sequence_number',
    {
        where = 'chapter_id = "' .. selectedChapter .. '" AND context_code = "' .. selectedContext .. '"',
        order_by = 'sequence_number DESC',
        limit = 1
    }
)
</pre>
=== 2. Increment Logic ===
* If no records exist: `sequence_number = 1`
* If records exist: `sequence_number = results[1].sequence_number + 1`
=== 3. Format Padding ===
The number is always padded to 4 digits for visual consistency in the archive:
`string.format("%04d", sequence_number)`

Latest revision as of 11:31, 12 February 2026

ICT Documentation: Automatic Identifier Logic (Lua)

The `DigitalAssets` table uses a Lua script (Module:AssetIdentifier) to ensure unique, sequential numbering.

1. Input Variables

The script requires three inputs from the Form:DigitalAsset:

  • `chapter_id` (from ResearchChapters)
  • `context_code` (from Places or Organisations)
  • `sequence_number` (calculated automatically)

2. Identifier Construction

The final ID is constructed using the pattern: `[ChapterCode]-[ContextCode]-[Sequence]`

  • Example: `CH01-OST-0001` (Chapter 1, Ostend, first asset)

3. Maintenance Note

If a record is deleted, the `sequence_number` for that specific context will have a "gap." This is acceptable in archival practice to maintain the integrity of existing permalinks.


ICT Documentation: Sequential Numbering (Lua)

To generate the `sequence_number` (e.g., 0007), the Lua module performs a Cargo query on the `DigitalAssets` table before the save is finalized.

1. The Lookup Query

The script filters by `chapter_id` AND `context_code`:

local results = mw.ext.cargo.query(
    'DigitalAssets',
    'sequence_number',
    {
        where = 'chapter_id = "' .. selectedChapter .. '" AND context_code = "' .. selectedContext .. '"',
        order_by = 'sequence_number DESC',
        limit = 1
    }
)

2. Increment Logic

  • If no records exist: `sequence_number = 1`
  • If records exist: `sequence_number = results[1].sequence_number + 1`

3. Format Padding

The number is always padded to 4 digits for visual consistency in the archive: `string.format("%04d", sequence_number)`