--- user-roles


CREATE TABLE user_roles (
  id          BIGINT PRIMARY KEY,
  title       VARCHAR(64)   NOT NULL,
  description VARCHAR(255)  NOT NULL,
  admin       BOOLEAN       NOT NULL,
  deleted     BOOLEAN       NOT NULL,
  permissions VARCHAR(4000) NOT NULL,

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

CREATE SEQUENCE user_roles_id_seq;

-- users

ALTER TABLE users
  ADD role_id BIGINT REFERENCES user_roles (id);
ALTER TABLE users
  ADD position VARCHAR(255);
ALTER TABLE users
  ADD updated_at TIMESTAMPTZ;
ALTER TABLE users
  ADD deleted_at TIMESTAMPTZ;
ALTER TABLE users
  ADD restored_at TIMESTAMPTZ;


UPDATE users
SET updated_at = created_at;
UPDATE users
SET "position" = '';

ALTER TABLE users
  ALTER COLUMN updated_at SET NOT NULL;
ALTER TABLE users
  ALTER COLUMN "position" SET NOT NULL;
