-- auto-generated definition
create table shop_order
(
id bigint auto_increment
primary key,
order_id bigint not null comment '订单ID',
user_id bigint not null comment '用户ID',
success int not null,
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
constraint shop_order_order_id_uindex
unique (order_id)
) comment '订单表';
create index shop_order_user_id_index
on shop_order (user_id);
-- auto-generated definition
create table shop_stock
(
id bigint auto_increment
primary key,
sku_id bigint not null comment 'SKU ID',
name varchar(255) not null comment '商品名称',
count bigint default 0 not null comment '库存数量',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
update_time datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间'
) comment '商品库存表';
-- auto-generated definition
create table shop_stock_record
(
id bigint auto_increment
primary key,
order_id bigint not null comment '订单id',
user_id bigint not null comment '用户ID',
sku_id bigint not null comment 'SKU ID',
count int not null comment '库存变更数量',
status tinyint default 0 not null comment '状态:0-初始化,1-已成功创建订单,2-库存已回滚',
create_time datetime default CURRENT_TIMESTAMP not null comment '创建时间',
constraint shop_stock_record_order_id_sku_id_uindex
unique (order_id, sku_id)
) comment '库存操作记录表';
create index shop_stock_record_create_time_status_index
on shop_stock_record (create_time, status);
create index shop_stock_record_user_id_index
on shop_stock_record (user_id);
-
Notifications
You must be signed in to change notification settings - Fork 0
huangtaojava/seckill-mysql
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About
仅使用mysql实现库存秒杀并保证数据最终一致性
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published