summaryrefslogtreecommitdiff
path: root/rust/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'rust/scripts')
-rw-r--r--rust/scripts/create_db.sh10
-rw-r--r--rust/scripts/create_db.sql41
-rw-r--r--rust/scripts/create_user.sql1
3 files changed, 52 insertions, 0 deletions
diff --git a/rust/scripts/create_db.sh b/rust/scripts/create_db.sh
new file mode 100644
index 0000000..cddcdd9
--- /dev/null
+++ b/rust/scripts/create_db.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+echo "choose a password for the database: 'input;"
+read input
+echo $(pwd)
+echo "creating database..."
+sudo mariadb -u root <<EOF
+$(cat scripts/create_user.sql)
+EOF
+
+sudo mariadb -u root < ./scripts/create_db.sql
diff --git a/rust/scripts/create_db.sql b/rust/scripts/create_db.sql
new file mode 100644
index 0000000..f803714
--- /dev/null
+++ b/rust/scripts/create_db.sql
@@ -0,0 +1,41 @@
+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,
+
+ 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)
+);
+
+ALTER TABLE song CONVERT TO CHARACTER SET utf8;
+ALTER TABLE album CONVERT TO CHARACTER SET utf8;
+ALTER TABLE artist CONVERT TO CHARACTER SET utf8;
+
+GRANT ALL PRIVILEGES ON balalaika.* TO 'balalaika_user'@'%' WITH GRANT OPTION;
+FLUSH PRIVILEGES;
diff --git a/rust/scripts/create_user.sql b/rust/scripts/create_user.sql
new file mode 100644
index 0000000..b2eaaaa
--- /dev/null
+++ b/rust/scripts/create_user.sql
@@ -0,0 +1 @@
+CREATE USER IF NOT EXISTS 'balalaika_user'@'%' IDENTIFIED BY '$input';