DROP TABLE IF EXISTS datas;
DROP TABLE IF EXISTS refs;

CREATE TABLE refs (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
   ,ref_type ENUM( 'H', 'A' ) NOT NULL DEFAULT 'H'
   ,refcount BIGINT UNSIGNED NOT NULL DEFAULT 1
   ,classname LONGTEXT
) ENGINE=MyISAM;

CREATE TABLE datas (
    id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
   ,ref_id BIGINT UNSIGNED NOT NULL
   ,data_type ENUM( 'S', 'R' ) DEFAULT 'S'
   ,`key` LONGTEXT NOT NULL
   ,value LONGTEXT
   ,FOREIGN KEY (ref_id) REFERENCES refs (id)
        ON DELETE CASCADE ON UPDATE CASCADE
   ,UNIQUE INDEX (ref_id, `key` (700) )
) ENGINE=MyISAM;
