# migrations

domain: workspace
migration:
CREATE TABLE workspaces(
    workspace_id BLOB PRIMARY KEY,
    dock_anchor TEXT, -- Enum: 'Bottom' / 'Right' / 'Expanded'
    dock_visible INTEGER, -- Boolean
    timestamp TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL
) STRICT;


domain: pane
migration:
CREATE TABLE pane_groups(
    group_id INTEGER PRIMARY KEY,
    workspace_id BLOB NOT NULL,
    parent_group_id INTEGER, -- NULL indicates that this is a root node
    position INTEGER, -- NULL indicates that this is a root node
    axis TEXT NOT NULL, -- Enum:  'Vertical' / 'Horizontal'
    FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id) ON DELETE CASCADE,
    FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
) STRICT;

CREATE TABLE panes(
    pane_id INTEGER PRIMARY KEY,
    workspace_id BLOB NOT NULL,
    parent_group_id INTEGER, -- NULL, this is a dock pane
    position INTEGER, -- NULL, this is a dock pane
    FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id) ON DELETE CASCADE,
    FOREIGN KEY(parent_group_id) REFERENCES pane_groups(group_id) ON DELETE CASCADE
) STRICT;


domain: item
migration:
CREATE TABLE items(
    item_id INTEGER NOT NULL, -- This is the item's view id, so this is not unique
    workspace_id BLOB NOT NULL,
    pane_id INTEGER NOT NULL,
    kind TEXT NOT NULL,
    position INTEGER NOT NULL,
    FOREIGN KEY(workspace_id) REFERENCES workspaces(workspace_id) ON DELETE CASCADE
    FOREIGN KEY(pane_id) REFERENCES panes(pane_id) ON DELETE CASCADE
    PRIMARY KEY(item_id, workspace_id)
) STRICT;


