
USE partsltd_prod;

SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning 
FROM INFORMATION_SCHEMA.TABLES 
WHERE 
        TABLE_SCHEMA = 'partsltd_prod' 
    AND TABLE_NAME = 'PH_Permission'
;

CREATE TABLE IF NOT EXISTS partsltd_prod.PH_Permission (
      id_permission INT NOT NULL AUTO_INCREMENT PRIMARY KEY
    , code VARCHAR(50)
    , name VARCHAR(255)
    , id_permission_group INT NOT NULL
    , CONSTRAINT FK_PH_Permission_id_permission_group
		FOREIGN KEY (id_permission_group)
        REFERENCES partsltd_prod.PH_Permission_Group(id_group)
    , id_access_level_required INT NOT NULL
    , CONSTRAINT FK_PH_Permission_id_access_level_required
		FOREIGN KEY (id_access_level_required)
        REFERENCES partsltd_prod.PH_Access_Level(id_access_level)
    , display_order INT NOT NULL
    , active BIT NOT NULL DEFAULT 1
);