2

I need some help to structure some tables that will help me out having a good personalized way to have different access name per client with personalized allowed commands in each acess level.

So consider client A has create site Y, which he wants to create the follow access groups:

  • Admin (have all acess),
  • VIP (can access room 1),
  • Basic (can access louge),
  • Banned (cannot enter at all)

The same way client A create his personalized access I want all my other clients to be able to create their own personalized access where they can name it anything they see fit in their own language and later just put in what commands they will have access to by being on that given access level.

I have the follow tables as example (sorry that this isnt a datagram, work bench keep crashing on me when I make example and I am open to suggestion for alternatives to create datagrams as good as or better than workbench):

  • client TABLE:

    id int,
    username varchar,
    password varchar,
    status varchar
    
  • site TABLE:

    id int,
    owner_client_id,
    name varchar
    
  • access TABLE:

    id int,
    name varchar,
    commands int (bitmask?)
    
  • site_access TABLE

    id int,
    client_id,
    site_id,
    access_id
    
  • commands

    id int,
    action varchar,
    alias varchar,
    description varchar
    

On my application all the commands actions are alredy pre-defined and the user cannot change them in what they do or the default name, but they are allowed to create alias.

So let's say I have the command kick, they could make an alias to name it "k" or "explosion" or they could name the alias anything they want.

Some of my doubts:

  1. Initially I tought of using site_access to link everything together, client that has access to site and what access it has and from their access what commands each have, is that a good way to go with it ?

  2. I have many commands that will be pulled from the database but since some have their own alias I dont thin I could use a bitmask for the acess and still being able to query the alias if not null could I so I would have to use a list of commands or are there good options ?

  3. What engine should I use, InnoDB or MyISAM in my case ?

  4. Is it ok to mix engines or not a good idea at all ?

  5. What should I change on my current table structure and could you provide any samples too (if possible) ?

UPDATE:

enter image description here

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`clients`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`clients` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`clients` (
  `id` INT NOT NULL,
  `username` VARCHAR(45) NOT NULL ,
  `password` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX `username_UNIQUE` (`username` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`sites`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`sites` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`sites` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`groups`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`groups` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`groups` (
  `id` INT NOT NULL ,
  `name` VARCHAR(45) NOT NULL ,
  `alias` VARCHAR(45) NOT NULL ,
  `commands` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`membership`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`membership` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`membership` (
  `client_id` INT NOT NULL ,
  `group_id` INT NOT NULL ,
  PRIMARY KEY (`client_id`, `group_id`) ,
  INDEX `client_id` (`client_id` ASC) ,
  INDEX `group_id` (`group_id` ASC) ,
  CONSTRAINT `client_id`
    FOREIGN KEY (`client_id` )
    REFERENCES `mydb`.`clients` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `group_id`
    FOREIGN KEY (`group_id` )
    REFERENCES `mydb`.`groups` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`access`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`access` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`access` (
  `site_id` INT NOT NULL ,
  `group_id` INT NOT NULL ,
  PRIMARY KEY (`site_id`, `group_id`) ,
  INDEX `site_id` (`site_id` ASC) ,
  INDEX `group_id` (`group_id` ASC) ,
  CONSTRAINT `site_id`
    FOREIGN KEY (`site_id` )
    REFERENCES `mydb`.`sites` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `group_id`
    FOREIGN KEY (`group_id` )
    REFERENCES `mydb`.`groups` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
Prix
  • 19,417
  • 15
  • 73
  • 132

1 Answers1

1

I would do it a bit differently

  • Client Table
  • Group Table
  • Membership Table (Client - Group)
  • Site Table
  • Access Table (Group Site)

Also see pages 12-13 in this link for ideas http://support.sas.com/resources/papers/proceedings09/265-2009.pdf

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
  • +1 That makes sense so you are tiying up clients to a group and the groups to the site, would that layout work well if 1 client is able to have different access to multiple sites as well ? – Prix Jun 19 '11 at 15:17
  • Yes, but you would need extra groups, for example "Site A Low Access", "Site A High Access", "Site B Low Access". Then a user could have low access in one site and high acess in another. – Shiraz Bhaiji Jun 19 '11 at 17:09
  • yeah that was what I was initially thinking thanks to clear that out, would you advise me in the other questions such as using innodb to take advantage of the fk or not really needed and i could use just myisam... ? – Prix Jun 19 '11 at 17:57
  • there is a good discussion of it here. http://stackoverflow.com/questions/20148/myisam-versus-innodb looks like innodb is the way to go – Shiraz Bhaiji Jun 19 '11 at 20:43
  • if you dont mind, I tried making the tables folloing your advice and would appreciate if u could take a look at my question update with some guidance ;) side note is that I mainly used myisam so am not sure if i did it right perhaps the key usages i did are not needed or wrong placed, note that the sql file was auto generated by the workbench. – Prix Jun 19 '11 at 22:45