-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
97 lines (90 loc) · 5.62 KB
/
Copy pathinit.sql
File metadata and controls
97 lines (90 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
set names utf8mb4 collate utf8mb4_unicode_ci;
create table if not exists inventory(
id int auto_increment comment '限量材料id,自增',
name varchar(20) not null comment '材料名称',
description varchar(100) not null default '' comment '材料描述',
picture varchar(200) not null default '' comment '材料图片',
price int not null default 0 comment '价值',
count int not null default 0 comment '库存量',
primary key (id)
)default charset=utf8mb4;
-- 查询、购买和抢购实验统一围绕星髓展开。
-- inventory 是独立的抢购活动库存,不与 materials.stock 的普通购买库存混用。
insert into inventory (id,name,description,picture,price,count) values
(4,'星髓','从坠星内部提取的高密度魔力介质,仅用于高阶炼成与能量校准。','img/star-marrow-relic.png',5200,300);
create table if not exists orders(
id int auto_increment comment '订单id,自增',
activity_id int not null default 1 comment '活动id',
gift_id int not null comment '商品id',
user_id int not null comment '用户id',
count int not null default 1 comment '购买数量',
status varchar(32) not null default 'pending_payment' comment '订单状态: pending_payment/paid/cancelled',
inventory_mode varchar(16) not null comment '库存模式: redis/mysql',
stock_released tinyint(1) not null default 0 comment '取消库存是否已回补',
expires_at datetime not null comment '支付截止时间',
paid_at datetime null comment '支付完成时间',
cancelled_at datetime null comment '取消时间',
cancel_reason varchar(64) not null default '' comment '取消原因',
create_time datetime default current_timestamp comment '订单创建时间',
update_time datetime default current_timestamp on update current_timestamp comment '订单更新时间',
primary key (id),
key idx_user (user_id),
key idx_status_expires (status, expires_at),
unique key uk_activity_user (activity_id, user_id)
)default charset=utf8mb4;
-- 材料情报店只读实验的权威档案。
-- 应用启动时也会 AutoMigrate + FirstOrCreate,以兼容不会重新执行 init.sql 的老数据卷。
create table if not exists profession_archives(
id int not null,
code varchar(64) not null,
name varchar(64) not null,
title varchar(128) not null,
sigil varchar(16) not null,
accent varchar(16) not null,
summary varchar(600) not null,
oath varchar(255) not null,
primary key (id),
unique key uk_profession_code (code)
)default charset=utf8mb4;
insert ignore into profession_archives (id,code,name,title,sigil,accent,summary,oath) values
(1,'night-warden','守夜人','替沉睡的城邦守住最后一盏灯','夜','#315c78','他们认识每一条在午夜改道的河,也听得见城墙深处极轻的裂响。守夜人的职责不是战胜黑暗,而是让所有人醒来时,仍相信黎明会如约而至。','灯不必照亮远方,只要不在我手中熄灭。'),
(2,'clockwork-smith','机巧师','让沉默的铜与铁重新学会呼吸','械','#9a6737','机巧师的工作台从不真正安静。齿轮记得手指的温度,旧钟会在无人处低声报时,而每一件被世人判定报废的器物,都可能在他们掌心获得第二次心跳。','世上没有废铁,只有尚未被听懂的请求。'),
(3,'star-reader','观星者','从群星的迟信里辨认尚未发生的风暴','星','#6659a8','他们在最高的塔上记录星辰,把几百年前启程的光译成今日的预兆。观星者并不预言命运;他们只是比旁人更早看见选择的代价。','星辰从不回答,只把问题照得更清楚。'),
(4,'raven-physician','渡鸦医师','在瘟风经过之后替名字留住体温','鸦','#48645a','渡鸦医师随黑羽穿过封闭的城门。他们携带草药、银针和一本从不公开的姓名册:治愈一人便划去一个名字,未能归来的人,则由他们亲自送回故乡。','疾病可以带走呼吸,不能带走一个人被记得的方式。');
-- 购买主实验订单账本。request_id 是幂等边界;它与 materials.stock 共用一个事务。
create table if not exists purchase_lab_orders(
id bigint unsigned not null auto_increment,
batch_id varchar(96) not null,
request_id varchar(128) not null,
material_id int not null,
quantity int not null,
strategy varchar(40) not null,
status varchar(24) not null,
purchase_latency_ms decimal(12,3) not null default 0,
created_at datetime(3) not null default current_timestamp(3),
primary key (id),
unique key uk_purchase_lab_request (request_id),
key idx_purchase_lab_batch (batch_id),
key idx_purchase_lab_material (material_id)
)default charset=utf8mb4;
-- Outbox 与异步方案的订单、库存扣减同事务写入;发布和消费状态允许恢复与重试。
create table if not exists purchase_lab_outbox(
id bigint unsigned not null auto_increment,
batch_id varchar(96) not null,
event_id varchar(160) not null,
request_id varchar(128) not null,
material_id int not null,
status varchar(24) not null,
retry_count int not null default 0,
last_error varchar(500) not null default '',
next_retry_at datetime(3) null,
created_at datetime(3) not null default current_timestamp(3),
published_at datetime(3) null,
invalidated_at datetime(3) null,
primary key (id),
unique key uk_purchase_outbox_event (event_id),
unique key uk_purchase_outbox_request (request_id),
key idx_purchase_outbox_batch (batch_id),
key idx_purchase_outbox_material (material_id),
key idx_purchase_outbox_status (status)
)default charset=utf8mb4;