我们最终设计使用两个表一个非常简单的库存系统:container
和vial
。
container
定义了存储单元的层次结构,并被设计为具有动态深度。这意味着我们可以创建一个冰柜与深度为3,和另一个用的1
CREATE TABLE container(
id SERIAL PRIMARY KEY,
name VARCHAR(64) NOT NULL,
labels VARCHAR(128) NOT NULL,
slots VARCHAR(64) NOT NULL
);
CREATE TABLE vial(
id SERIAL PRIMARY KEY,
sample_name VARCHAR(64) NOT NULL,
position VARCHAR(64) NOT NULL,
FOREIGN KEY (container) REFERENCES container(id)
);
例如,深度,以创建具有5架,10盒/齿条三级深度冷冻,并随后的25瓶/箱,你会做以下几点:
INSERT INTO container (name, labels, slots) VALUES ('Blood Freezer', 'rack,box,vial', '5,10,25');
当我们希望把一对夫妇瓶在冰箱:
INSERT INTO vial (sample_name, position, container) VALUES ('Patient 2345', '0,0,0', 1);
INSERT INTO vial (sample_name, position, container) VALUES ('Patient 3456', '0,0,1', 1);
要看到所有的小瓶在第一架:
SELECT * FROM vial WHERE position LIKE '0,%' AND container = 1;
要找到空瓶,我们使用脚本做这样的事情:
all_vials = []
all_slots = get_all_slots_for_container("Blood Freezer")
for slots in all_slots:
previous_vials = all_vials[:]
all_vials = []
if not previous_vials:
for i in range(slots):
new_vial = Vial.create_from_position_index(i)
all_vials.append(new_vial)
else:
for previous_vial in previous_vials:
for i in range(slots):
new_vial = Vial.create_from_previous_and_add_position_index(previous_vial, i)
all_vials.append(new_vial)
filled_vials = get_filled_vials_for_container("Blood Freezer")
return filter_out_filled_vials(all_vials, filled_vials)