You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
inventory-app/migrations/20241107225934_initial.sql

74 lines
2.0 KiB

-- Add migration script here
CREATE TABLE IF NOT EXISTS User (
id INTEGER PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
role INTEGER NOT NULL,
FOREIGN KEY(role) REFERENCES UserRole(id)
);
CREATE TABLE IF NOT EXISTS UserRole (
id INTEGER PRIMARY KEY NOT NULL,
name TEXT NOT NULL UNIQUE
);
INSERT INTO UserRole (id, name) VALUES
(1,'admin'),
(10,'edit'),
(99,'view');
CREATE TABLE IF NOT EXISTS InventoryItem (
id INTEGER PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
display_unit INTEGER NOT NULL DEFAULT 1,
reorder_point REAL NOT NULL,
allow_fractional_units BOOLEAN NOT NULL,
FOREIGN KEY(display_unit) REFERENCES DisplayUnit(id)
);
CREATE TABLE IF NOT EXISTS PositiveAdjustment (
id INTEGER PRIMARY KEY NOT NULL,
item INTEGER NOT NULL,
user INTEGER NOT NULL,
create_date TIMESTAMP NOT NULL,
target_date TIMESTAMP NOT NULL,
amount REAL NOT NULL,
unit_price INTEGER NOT NULL,
FOREIGN KEY(user) REFERENCES User(id),
FOREIGN KEY(item) REFERENCES InventoryItem(id)
);
CREATE TABLE IF NOT EXISTS NegativeAdjustment (
id INTEGER PRIMARY KEY NOT NULL,
item INTEGER NOT NULL,
user INTEGER NOT NULL,
create_date TIMESTAMP NOT NULL,
target_date TIMESTAMP NOT NULL,
amount REAL NOT NULL,
reason INTEGER NOT NULL,
FOREIGN KEY(user) REFERENCES User(id),
FOREIGN KEY(item) REFERENCES InventoryItem(id),
FOREIGN KEY(reason) REFERENCES NegativeAdjustmentReason(id)
);
CREATE TABLE IF NOT EXISTS NegativeAdjustmentReason (
id INTEGER PRIMARY KEY NOT NULL,
name TEXT NOT NULL
);
INSERT INTO NegativeAdjustmentReason (id, name) VALUES
(10,'Sale'),
(20,'Loss'),
(25,'Expired');
CREATE TABLE IF NOT EXISTS DisplayUnit (
id INTEGER PRIMARY KEY NOT NULL,
unit TEXT NOT NULL,
abbreviation TEXT NOT NULL
);
INSERT INTO DisplayUnit (id, unit, abbreviation) VALUES
(1,'count', 'ct'),
(2,'milliliter', 'ml'),
(3,'milligram', 'mg');

Powered by TurnKey Linux.