DROP TABLE IF EXISTS ACCESS_TOKEN;

CREATE TABLE ACCESS_TOKEN (
   ACCESS_TOKEN_ID INT NOT NULL AUTO_INCREMENT,
   TOKEN_HASH VARCHAR(40) NOT NULL,
   USER_NAME VARCHAR(100) NOT NULL,
   NOTE TEXT NOT NULL
);

ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_PK PRIMARY KEY (ACCESS_TOKEN_ID);
ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_FK0 FOREIGN KEY (USER_NAME) REFERENCES ACCOUNT (USER_NAME)
  ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE ACCESS_TOKEN ADD CONSTRAINT IDX_ACCESS_TOKEN_TOKEN_HASH UNIQUE(TOKEN_HASH);
