Added unit to db and structs/types.

This commit is contained in:
2026-01-26 22:09:32 +01:00
parent 7879f69255
commit 8a27639aad
14 changed files with 243 additions and 60 deletions
+35
View File
@@ -0,0 +1,35 @@
-- Add migration script here
CREATE TABLE unit
(
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 ),
name text NOT NULL,
display text NOT NULL,
CONSTRAINT unit_id PRIMARY KEY (id)
INCLUDE(id)
);
-- Insert units
INSERT INTO unit (name, display) VALUES ('KG', 'kg');
INSERT INTO unit (name, display) VALUES ('G', 'g');
INSERT INTO unit (name, display) VALUES ('L', 'l');
INSERT INTO unit (name, display) VALUES ('ML', 'ml');
INSERT INTO unit (name, display) VALUES ('Stk', 'Stk');
-- Alter article and variant table to add unit
ALTER TABLE public.variant
ADD unit_id bigint NOT NULL DEFAULT 1,
ADD CONSTRAINT variant_unit_id_fkey
foreign key (unit_id)
references unit(id)
ON DELETE NO ACTION;
ALTER TABLE public.article
ADD default_unit_id bigint NOT NULL DEFAULT 1,
ADD CONSTRAINT article_unit_id_fkey
foreign key (default_unit_id)
references unit(id)
ON DELETE NO ACTION;
-- Add display text to origin table
ALTER TABLE public.origin
ADD display text NOT NULL DEFAULT 'NOT SET';