Skip to content

Create your database

This documentation describes the database configuration file for the capsule, in case you want to create your own models. The configuration uses TOML format to define database schema changes and structure. It really similar to liquibase and permit versionning of the database.

Configuration Header

version = "1.0.0"
changeSetId = "20241214-01"
author = "steevy"
description = "Initial schema setup"
database = "capsule-kit"

Header Fields

FieldDescriptionExample
versionSchema version number1.0.0
changeSetIdUnique identifier for the changeset20241214-01
authorAuthor of the changessteevy
descriptionBrief description of changesInitial schema setup
databaseTarget database namecapsule-kit

Schema Structure

Operations

The operations tag is the main tag to define an action to be performed on the database.

[[operations]]
type = "createTable"
tableName = "caplet"

Operations Fields

FieldData TypeDescription
typetextThe operation type to execute against the database
tableNametextName of the table to execute the operatio against
columnsList [ColumnDefinition]Definitions of the columns in the table
foreignKeysList [ForeignKeyDefinition]Definitions of the foreign keys in the table
Operations Type

Can be of value :

  • createTable
  • dropTable
  • alterTable
Columns Définitions

{ name = “id”, type = “text”, constraints = { primaryKey = true, nullable = false } },

Column NameData TypeDescription
nametextName of the column
typetextType of content stored
constraintsConstraint Definitionconstraints of the column
Constraint Definitions
Constraint TypeConstraint DefinitionValue
primaryKeyPRIMARY KEYboolean
notNullNOT NULLboolean

Foreign Key Relationships

Constraint NameReferenced Column
baseColumnNameThe name of the Primary Column
referencedTableNameThe name of the referenced table
referencedColumnNameThe name of the referenced table
constraintNameThe name of the foreign key constraint

Example

{ baseColumnName = "caplet_id", referencedTableName = "caplet", referencedColumnName = "id", constraintName = "fk_content_caplet_id_caplet_id" },

Usage Example

version = "1.0.0"
changeSetId = "20241214-01"
author = "steevy"
description = "Initial schema setup"
database = "capsule-kit"
[[operations]]
type = "createTable"
tableName = "caplet"
columns = [
{ name = "id", type = "text", constraints = { primaryKey = true, nullable = false } },
{ name = "title", type = "text", constraints = { nullable = false } },
{ name = "icon", type = "text" },
]
[[operations]]
type = "createTable"
tableName = "caplet_content"
columns = [
{ name = "id", type = "text", constraints = { primaryKey = true, nullable = false } },
{ name = "content_type", type = "text" },
{ name = "value", type = "text" },
{ name = "caplet_id", type = "text" }
]
foreignKeys = [
{ baseColumnName = "caplet_id", referencedTableName = "caplet", referencedColumnName = "id", constraintName = "fk_content_caplet_id_caplet_id" },
]