开发者

MySQL structure for personalized users access per site?

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:

MySQL structure for personalized users access per site?

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;


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜