-- CREATE DATABASE
CREATE DATABASE agile_metrics
  WITH ENCODING='UTF8'
       OWNER=postgres
           CONNECTION LIMIT=-1;

-- Table: "user"

-- DROP TABLE "user";

CREATE TABLE "user"
(
  id bigserial NOT NULL,
  asana_id bigint,
  name character varying(200),
  email character varying(200),
  photo_url character varying(500),
  created_at timestamp with time zone NOT NULL DEFAULT now(),
  updated_at timestamp with time zone,
  deleted_at timestamp with time zone,
  username character varying(100),
  password character varying(100),
  CONSTRAINT pk_user_id PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE "user"
  OWNER TO postgres;

-- Table: token

-- DROP TABLE token;

CREATE TABLE token
(
  id bigserial NOT NULL,
  user_id bigint,
  created_at timestamp with time zone NOT NULL DEFAULT now(),
  updated_at timestamp with time zone,
  deleted_at timestamp with time zone,
  expiry timestamp with time zone,
  access_token character varying(500),
  refresh_token character varying(60),
  token_type character varying(50),
  CONSTRAINT pk_token_id PRIMARY KEY (id),
  CONSTRAINT fk_token_user_id FOREIGN KEY (user_id)
      REFERENCES "user" (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
  OIDS=FALSE
);
ALTER TABLE token
  OWNER TO postgres;

-- Index: fki_token_user_id

-- DROP INDEX fki_token_user_id;

CREATE INDEX fki_token_user_id
  ON token
  USING btree
  (user_id);
