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

26 lines
684 B
MySQL
Raw Normal View History

2021-03-26 22:30:38 +00:00
-- Your SQL goes here
CREATE TABLE localuser (
2021-04-05 22:56:15 +00:00
`user_id` VARCHAR NOT NULL PRIMARY KEY,
2023-02-22 12:52:12 +00:00
`email` VARCHAR NOT NULL UNIQUE,
2021-04-05 22:56:15 +00:00
`password` VARCHAR NOT NULL,
`role` TEXT CHECK(role IN ('admin', 'zoneadmin')) NOT NULL, -- note: migrate to postgres so enum are actually a thing
2021-03-26 22:30:38 +00:00
FOREIGN KEY(user_id) REFERENCES user(id)
);
CREATE TABLE user (
2021-04-05 22:56:15 +00:00
`id` VARCHAR NOT NULL PRIMARY KEY
2021-03-26 22:30:38 +00:00
);
2021-04-05 21:21:40 +00:00
CREATE TABLE user_zone (
2021-04-05 22:56:15 +00:00
`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
);