partdb/schema.sql

92 lines
2.9 KiB
MySQL
Raw Normal View History

2023-01-23 14:05:06 +01:00
-- enable foreign key support in sqlite
2023-02-26 12:10:01 +01:00
PRAGMA foreign_keys = ON;
2023-01-23 14:05:06 +01:00
-- part manufacturer
CREATE TABLE IF NOT EXISTS manufacturer (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- index
2023-01-23 14:05:06 +01:00
name TEXT NOT NULL UNIQUE, -- manufacturer (expanded version, without legal form)
nick TEXT, -- manufacturer nickname
partof INTEGER, -- if the manufacturer has been acquired or is part of another
homepage TEXT, -- URL to home page
search TEXT, -- URL to search page
FOREIGN KEY (partof) REFERENCES manufacturer (id)
);
-- part distributor
CREATE TABLE IF NOT EXISTS distributor (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- index
2023-01-23 14:05:06 +01:00
name TEXT NOT NULL UNIQUE,
homepage TEXT, -- URL to home page
product_page TEXT -- URL to product page (%s is replace by sku)
);
-- the part itself
CREATE TABLE IF NOT EXISTS part (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- index
2023-01-23 14:05:06 +01:00
name TEXT NOT NULL UNIQUE,
2023-01-23 14:40:35 +01:00
description TEXT, -- a short (searchable) description
details TEXT, -- even more part details than just in the description
2023-01-23 14:05:06 +01:00
manufacturer INTEGER,
2023-01-28 00:20:29 +01:00
mpn TEXT,
2023-01-23 14:05:06 +01:00
family INTEGER, -- if this part is part of a part family
datasheet TEXT, -- URL to datasheet
2023-01-29 10:09:42 +01:00
package TEXT,
2023-01-23 14:05:06 +01:00
page TEXT, -- URL to product page
FOREIGN KEY (manufacturer) REFERENCES manufacturer (id),
2023-01-29 10:09:42 +01:00
FOREIGN KEY (family) REFERENCES part (id)
2023-01-23 14:05:06 +01:00
);
2023-01-23 14:41:22 +01:00
-- a project (as part) can be an assembly of other parts
CREATE TABLE IF NOT EXISTS assembly (
assembled INTEGER NOT NULL, -- the assembly project
component INTEGER NOT NULL, -- the component part
quantity INTEGER NOT NULL, -- quantity of component
FOREIGN KEY (assembled) REFERENCES part (id),
FOREIGN KEY (component) REFERENCES part (id),
UNIQUE (assembled, component)
);
2023-01-23 14:05:06 +01:00
-- a part at a distributor
CREATE TABLE IF NOT EXISTS distribution (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- index
2023-01-23 14:05:06 +01:00
part INTEGER NOT NULL, -- the part
distributor INTEGER NOT NULL, -- the part distributor
sku TEXT NOT NULL, -- distributor part number
FOREIGN KEY (part) REFERENCES part (id),
FOREIGN KEY (distributor) REFERENCES distributor (id)
);
-- part property
CREATE TABLE IF NOT EXISTS property (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- index
2023-01-25 11:57:54 +01:00
name TEXT NOT NULL -- property name (min V, ...)
2023-01-23 14:05:06 +01:00
);
-- property value
2023-01-31 21:54:27 +01:00
CREATE TABLE IF NOT EXISTS properties (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- index
2023-01-23 14:05:06 +01:00
part INTEGER NOT NULL, -- the part
property INTEGER NOT NULL,
value TEXT,
FOREIGN KEY (part) REFERENCES part (id),
FOREIGN KEY (property) REFERENCES property (id)
);
-- part location
CREATE TABLE IF NOT EXISTS location (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- index
2023-01-23 14:05:06 +01:00
name TEXT NOT NULL UNIQUE,
container TEXT -- container type
);
-- local stock
CREATE TABLE IF NOT EXISTS inventory (
id INTEGER PRIMARY KEY AUTOINCREMENT, -- index
2023-01-23 14:05:06 +01:00
part INTEGER NOT NULL,
location INTEGER,
quantity INTEGER NOT NULL,
FOREIGN KEY (part) REFERENCES part (id),
2023-01-23 14:41:06 +01:00
FOREIGN KEY (location) REFERENCES location (id),
UNIQUE (part, location)
2023-01-23 14:05:06 +01:00
);