Data Seeding (Master Data)

Data Seeding is the process of populating the database with initial configuration records, catalogs, or essential master data (e.g., Statuses, Priorities, Default Roles) required for the application to function immediately after deployment.

Seeding via the Studio UI

In the Master Data (Seeds) module, you are presented with a spreadsheet-like interface for each Entity.

  1. Select an Entity from the sidebar.
  2. Add rows and fill in the data. The UI provides dropdowns for Enum values and Foreign Keys.
  3. If the entity contains a File or Image field, the UI allows you to upload the file directly.

The Generated JSON (Data/{EntityName}.json)

Seeds are not stored in a single monolithic file. Instead, they are saved as individual JSON arrays within the tenant's Data/ directory.

The Negative ID Strategy

To distinguish seed data from runtime data generated by users, all seed records MUST use Negative Integers for their Id (e.g., -1, -2). The engine uses these negative IDs to resolve referential integrity before committing the records to the database with true, auto-incremented positive IDs.

Example: Data/Category.json

[
  {
    "Id": -1,
    "Name": "Hardware",
    "IsActive": true
  },
  {
    "Id": -2,
    "Name": "Software",
    "IsActive": true
  }
]

Resolving Foreign Keys

When defining a record that relies on a foreign key, assign the exact negative Id of the parent seed record directly to the navigation property name.

Example: Data/Product.json

[
  {
    "Id": -1,
    "Name": "Server Rack",
    "Category": -1, 
    "Price": 1500.00
  }
]

(Note: The field is named Category, NOT CategoryId.)

Seeding Files and Images

File seeding requires two steps. First, the physical file must exist in the Data/seedFiles/ directory. Second, a metadata record must be created in Struktural_Sys_File.

Example: Data/Struktural_Sys_File.json

[
  {
    "Id": -100,
    "OriginalName": "rack_photo.png",
    "SeedFileName": "rack_photo.png", 
    "ContentType": "image/png",
    "SizeBytes": 0 
  }
]

(Note: Setting SizeBytes to 0 signals the engine to calculate the true size during the database insertion).

You can then link this file to a business entity: Example: Data/Product.json

[
  {
    "Id": -1,
    "Name": "Server Rack",
    "Category": -1,
    "Image": -100
  }
]