nomilo/migrations/2021-03-26-164945_create_users/up.sql

26 lines
684 B
SQL

-- Your SQL goes here
CREATE TABLE localuser (
`user_id` VARCHAR NOT NULL PRIMARY KEY,
`email` VARCHAR NOT NULL UNIQUE,
`password` VARCHAR NOT NULL,
`role` TEXT CHECK(role IN ('admin', 'zoneadmin')) NOT NULL, -- note: migrate to postgres so enum are actually a thing
FOREIGN KEY(user_id) REFERENCES user(id)
);
CREATE TABLE user (
`id` VARCHAR NOT NULL PRIMARY KEY
);
CREATE TABLE user_zone (
`user_id` VARCHAR NOT NULL,
`zone_id` VARCHAR NOT NULL,
PRIMARY KEY(user_id, zone_id),
FOREIGN KEY(user_id) REFERENCES user(id),
FOREIGN KEY(zone_id) REFERENCES zone(id)
);
CREATE TABLE zone (
`id` VARCHAR NOT NULL PRIMARY KEY,
`name` VARCHAR NOT NULL UNIQUE
);