--- user-roles


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

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

-- users

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

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

ALTER TABLE users
  ALTER COLUMN updated_at DATETIMEOFFSET NOT NULL;
ALTER TABLE users
  ALTER COLUMN position NVARCHAR(255) NOT NULL;
