summaryrefslogtreecommitdiff
path: root/scripts/create_db.sql
blob: 56423f5636eb9d78a472197a89d5d197e4ee9a33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
CREATE DATABASE IF NOT EXISTS balalaika;
USE balalaika;

DROP TABLE IF EXISTS song;
DROP TABLE IF EXISTS album;
DROP TABLE IF EXISTS artist;

CREATE TABLE artist (
    id int NOT NULL AUTO_INCREMENT,
    name varchar(255),

    PRIMARY KEY (id)
);

CREATE TABLE album (
    id int NOT NULL AUTO_INCREMENT,
    name varchar(255),
    cover varchar(510),
    artist_id int,
    release_date date,

    PRIMARY KEY (id),
    FOREIGN KEY (artist_id) REFERENCES artist(id)
);

CREATE TABLE song (
    id int NOT NULL AUTO_INCREMENT,
    name varchar(255),
    lyrics TEXT,

    album_id int,

    PRIMARY KEY (id),
    FOREIGN KEY (album_id) REFERENCES album(id)
);

CREATE OR REPLACE TABLE user (
    id int auto_increment,
    name varchar(255) unique,
    password varchar(510),
    primary key(id)
);

ALTER TABLE song CONVERT TO CHARACTER SET utf8;
ALTER TABLE album CONVERT TO CHARACTER SET utf8;
ALTER TABLE artist CONVERT TO CHARACTER SET utf8;
ALTER TABLE user CONVERT TO CHARACTER SET utf8;

GRANT ALL PRIVILEGES ON balalaika.* TO 'balalaika_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;