CREATE TABLE branch_groups
(
    id            BIGINT IDENTITY(1,1) PRIMARY KEY,
    project_id    BIGINT         NOT NULL REFERENCES projects (id),
    parent_id     BIGINT REFERENCES branch_groups (id),
    title         NVARCHAR(64)   NOT NULL,
    description   NVARCHAR(255)  NOT NULL,

    total_groups  INTEGER        NOT NULL,
    total_members INTEGER        NOT NULL,

    deleted       BIT            NOT NULL,
    created_at    DATETIMEOFFSET NOT NULL,
    updated_at    DATETIMEOFFSET NOT NULL,
    deleted_at    DATETIMEOFFSET
);

CREATE TABLE branch_group_members
(
    id          BIGINT IDENTITY(1,1) PRIMARY KEY,
    group_id    BIGINT         NOT NULL REFERENCES branch_groups (id),
    user_id     BIGINT         NOT NULL REFERENCES users (id),
    deleted     BIT            NOT NULL,

    created_at  DATETIMEOFFSET NOT NULL,
    updated_at  DATETIMEOFFSET NOT NULL,
    deleted_at  DATETIMEOFFSET,
    restored_at DATETIMEOFFSET
);

