Skip to content

Instantly share code, notes, and snippets.

@schmunk42
Created March 28, 2014 18:31
Show Gist options
  • Select an option

  • Save schmunk42/9839772 to your computer and use it in GitHub Desktop.

Select an option

Save schmunk42/9839772 to your computer and use it in GitHub Desktop.
Yii 2 User Extension Data Model
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'The KEY obviously',
`username` varchar(20) NOT NULL DEFAULT '' COMMENT 'Login name (alnum)',
`email` varchar(128) NOT NULL DEFAULT '' COMMENT 'User e-mail address',
`password` varchar(128) NOT NULL DEFAULT '' COMMENT 'Secure password hash',
`auth_client` varchar(128) NOT NULL DEFAULT '' COMMENT 'Eg. local, LDAP, GitHub, Twitter, Facebook, ...',
`auth_key` varchar(128) NOT NULL DEFAULT '' COMMENT 'External ID',
`activation_key` varchar(128) NOT NULL DEFAULT '' COMMENT 'Key to activate the account, sent by email',
`superuser` int(1) NOT NULL DEFAULT '0' COMMENT '** Not sure if needed, IMHO should be implemented in another way **',
`status` int(1) NOT NULL DEFAULT '0' COMMENT 'Eg. registered,confirmed,activated,banned',
`registered_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Timestamp of the registration',
`last_login_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Last login time',
PRIMARY KEY (`id`),
UNIQUE KEY `user_username` (`username`),
UNIQUE KEY `user_email` (`email`),
UNIQUE KEY `user_auth` (`auth_client`, `auth_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@nineinchnick

Copy link
Copy Markdown

superuser is not needed and status should be either flags or be split into more columns, becuase and account can have an confirmed/unconcirmed email and at the same time the admin can ban/unban it or it could get self-locked/unlocked in case of some events like failed login attempts.

@robregonm

Copy link
Copy Markdown

Looks good. However, I agree with @nineinchnick, since superuser field is not needed (it could be a module param).
Also, I like the suggestion regarding the snetwork table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment