you can think of Wechat users and mobile phone number users as two login methods.
I recommend not composing a table.
this is my user table minimalist design
< H1 > member < / H1 >
CREATE TABLE `member` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`tel` bigint(20) DEFAULT NULL COMMENT '',
`password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`status` tinyint(4) NOT NULL DEFAULT '0' COMMENT ' 0:',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `member_tel_unique` (`tel`),
KEY `member_tel_status_index` (`tel`,`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
< H1 > member_data < / H1 >
CREATE TABLE `member_data` (
`member_id` bigint(20) NOT NULL COMMENT '',
`sex` enum('0','1','2') COLLATE utf8mb4_unicode_ci NOT NULL COMMENT ' 0=> 1=> 2=>',
`nick_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '/',
`img` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
UNIQUE KEY `member_data_member_id_unique` (`member_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
< H1 > member_authorized < / H1 >
CREATE TABLE `member_authorized` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`member_id` bigint(20) NOT NULL COMMENT '',
`prefix` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
`token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
`data` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `member_authorized_prefix_index` (`prefix`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
if Wechat users have an independent user id, it will be difficult to organize. It can only be regarded as two users. If you merge two users into one, I feel I can write a function. To prompt the user whether to merge the two, let the user choose
when binding a mobile phone, save the record of the mobile phone user to the Wechat user table. In other words, add a field to the Wechat user table to associate with the mobile phone user table.
suggest a final primary table. Wechat has a user id field in a table, and the user's id in the primary table is self-increasing primary key
two tables are done.
- user table
attribute: user's ID, nickname, avatar, and other user attributes, not mobile phone number
- Login method Table
attribute: primary key ID,type (mobile or Wechat openid and other types of), openid (mobile numbers or other types of id,varchar used by Wechat openid and other types of id,varchar (40)), user ID,banned (whether login is prohibited)
type+openid do an index.
if you bind, you can insert a piece of data into the table without confusion.