cargagep-v2/db/migrations/20260823153310_create_bikes.sql
2026-08-23 17:47:31 +02:00

22 lines
732 B
SQL

-- migrate:up
-- A bike is either available for reservation, or withdrawn from the fleet
-- (maintenance, damage, ...). The set of states is fixed by the app, so an enum
-- type is the right fit here.
CREATE TYPE bike_status AS ENUM ('in_service', 'out_of_service');
CREATE TABLE bikes (
id SERIAL PRIMARY KEY,
"name" TEXT NOT NULL,
-- Identifier written on the keys, and how many of them exist for this bike
key_number TEXT,
key_quantity INTEGER NOT NULL DEFAULT 0,
drivetrain TEXT,
battery TEXT,
status bike_status NOT NULL DEFAULT 'in_service',
CONSTRAINT bikes_key_quantity_positive CHECK (key_quantity >= 0)
);
-- migrate:down
DROP TABLE IF EXISTS bikes;
DROP TYPE IF EXISTS bike_status;