The Store Layer

The store layer provides a flexible way of defining how and where we should store the data.

RDBMS schema management

Define a new schema

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.

The following example defines a table for Corteza Low Code modules:
// General bits regarding the package
// ...

func (s Schema) Tables() []*Table {
  return []*Table{
    // Other schema definitions
    // ...

    s.ComposeModule(),

    // Other schema definitions
    // ...
  }
}

// Other schema definitions
// ...

func (Schema) ComposeModule() *Table {
  return TableDef("compose_module",
    ID,
    ColumnDef("rel_namespace", ColumnTypeIdentifier),
    ColumnDef("handle", ColumnTypeVarchar, ColumnTypeLength(handleLength)),
    ColumnDef("name", ColumnTypeText),
    ColumnDef("meta", ColumnTypeJson),
    CUDTimestamps,

    AddIndex("namespace", IColumn("rel_namespace")),
    AddIndex("unique_handle", IColumn("rel_namespace"), IExpr("LOWER(handle)"), IWhere("LENGTH(handle) > 0 AND deleted_at IS NULL")),
  )
}

// Other schema definitions
// ...

Update existing schemas

When developing new features that require new store definitions, don’t clutter the generic_upgrades.go file. Either drop the original table and re-create it or manually apply the updates.

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 ensure that everything is up-to-date.

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.

The following example renames the actionlog table:
// 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
// ...