Corteza store layer
The store layer provides an extremely flexible way of defining how and where the data should be stored.
Schema management
Define new schemas
You can define a new schema in the store/rdbms/rdbms_schema.go
file.
The system goes over all definitions and assures that all of the tables are present in the connected database.
This step doesn’t take into account any potential schema manipulations. See Update existing schemas for details. |
// General bits regarding the package
// ...
func (s Schema) Tables() []*Table {
return []*Table{
// Other schema definitions
// ...
s.MessagingMessage(),
// Other schema definitions
// ...
}
}
// Other schema definitions
// ...
func (Schema) MessagingMessage() *Table {
return TableDef("messaging_message",
ID,
ColumnDef("type", ColumnTypeText),
ColumnDef("message", ColumnTypeText),
ColumnDef("meta", ColumnTypeJson),
ColumnDef("rel_channel", ColumnTypeIdentifier),
ColumnDef("rel_user", ColumnTypeIdentifier),
ColumnDef("reply_to", ColumnTypeIdentifier, DefaultValue("0")),
ColumnDef("replies", ColumnTypeInteger, DefaultValue("0")),
CUDTimestamps,
)
}
// Other schema definitions
// ...
Update existing schemas
When developing new features that require new store definitions, don’t clutter the If you are working with others, make sure to also coordinate this with them. |
You can define schema altering in the store/rdbms/generic_upgrades.go
file.
The system will go over all of the definitions and assure that everything is up-to-date.
This is an idempotent operation, meaning that the result will always be the same. Using plain human words — the system will only apply the changes that have not yet been applied. The result is the same, no matter how many times you run it. |
// General bits regarding the package
// ...
func (g genericUpgrades) Before(ctx context.Context) error {
return g.all(ctx,
g.RenameActionlog,
// Other operations
// ...
)
}
// Other definitions
// ...
func (g genericUpgrades) RenameActionlog(ctx context.Context) error {
return g.RenameTable(ctx, "sys_actionlog", "actionlog")
}
// Other definitions
// ...