ringfinger/backend/scripts/setup.sql

39 lines
1.3 KiB
MySQL
Raw Normal View History

2020-08-19 23:45:39 +02:00
START TRANSACTION;
2020-08-25 11:20:51 +02:00
USE $DB_NAME;
2020-08-19 23:45:39 +02:00
CREATE TABLE User (
UserId int(10) unsigned NOT NULL AUTO_INCREMENT,
Username varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
Password varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,
Email varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
JabberAddress varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
IsAdmin BOOL NOT NULL DEFAULT 0,
2020-08-19 23:45:39 +02:00
PRIMARY KEY (UserId),
UNIQUE KEY Username (Username),
UNIQUE KEY Email (Email),
UNIQUE KEY JabberAddress (JabberAddress)
);
CREATE TABLE Fingerprint (
FingerprintId int(10) unsigned NOT NULL AUTO_INCREMENT,
Fingerprint varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
UserId int(10) unsigned NOT NULL,
PRIMARY KEY (FingerprintId),
UNIQUE KEY Fingerprint (Fingerprint),
KEY User (UserId),
2020-08-20 22:28:22 +02:00
CONSTRAINT User FOREIGN KEY (UserId) REFERENCES User (UserId) ON DELETE CASCADE
2020-08-19 23:45:39 +02:00
);
CREATE TABLE Sharing (
SharingId int(10) unsigned NOT NULL AUTO_INCREMENT,
User int(10) unsigned NOT NULL,
UserShared int(10) unsigned NOT NULL,
PRIMARY KEY (SharingId),
UNIQUE KEY User (User, UserShared),
KEY UserSharedId (UserShared),
2020-08-20 22:28:22 +02:00
CONSTRAINT UserId FOREIGN KEY (User) REFERENCES User (UserId) ON DELETE CASCADE,
CONSTRAINT UserSharedId FOREIGN KEY (UserShared) REFERENCES User (UserId) ON DELETE CASCADE
2020-08-19 23:45:39 +02:00
);
COMMIT;