CREATE TABLE groups_permissions (
  id            NUMBER(19)       PRIMARY KEY,
  project_id    NUMBER(19)       NOT NULL REFERENCES projects(id),
  parent_id     NUMBER(19)       REFERENCES groups(id),
  title         VARCHAR2(64)  NOT NULL,
  description   VARCHAR2(255) NOT NULL,
  admin         NUMBER(1)      NOT NULL,
  permissions   VARCHAR2(4000)      NOT NULL,

  total_groups  NUMBER(5)      NOT NULL,
  total_members NUMBER(5)      NOT NULL,

  deleted       NUMBER(1)      NOT NULL,
  created_at    timestamp with time zone  NOT NULL,
  updated_at    timestamp with time zone  NOT NULL,
  deleted_at    timestamp with time zone,
  options       VARCHAR2(4000)
);

CREATE SEQUENCE groups_permissions_id_seq;

CREATE TABLE group_permissions_members (
  id          NUMBER(19)      PRIMARY KEY,
  group_id    NUMBER(19)      NOT NULL REFERENCES groups_permissions(id),
  user_id     NUMBER(19)      NOT NULL REFERENCES users(id),
  deleted     NUMBER(1)     NOT NULL,

  created_at  timestamp with time zone NOT NULL,
  updated_at  timestamp with time zone NOT NULL,
  deleted_at  timestamp with time zone,
  restored_at timestamp with time zone
);

CREATE SEQUENCE group_permissions_members_id_seq;
