-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge(sql_refactor): better sql; (#9)
**Changes:** - Migrations are now run with `refinery`. I changed the format to use `,` at the start of lines, this makes it harder to accidentally leave a trailing `,` on the last line. - Permissions are now case insensitive & I changed the case used in responses from `camelCase` to `PascalCase`. - Changed the name of session to token and moved `POST /login` to `POST /token` & `DELETE /session` to `DELETE /token`. - Moved `DangerousUser` to `User` and it no longer stores sensitive information only the permissions and username. - I also refactored a bunch of internal stuff, but I am not going to write that down because I am the only one who is ever going to read this -_- > This PR might be a bit too big... [feat(sql): mv migrations to dir run by refinery.](91b8872) [feat(database)!: permissions now case insensitive.](ce55af0) [feat(migrations): add migrations of permissions and sessions.](e59d115) [refactor(login): moved api::user::DangerousUserLogin.](e11adb8) [refactor(api): mv user_login -> session_write.](97d1958) [feat(tokens)!: mv /login -> /token & /session -> /token.](51beb2e) [refactor(tokens)!: DangerousUser -> User & use token table.](5345175) [feat(sql): junction tables & better sql.](29d37e8) [fix(dependencies): rm unused dependency sqlvec.](24b4d2a) [fix(dependencies): rm unused dependency rusqlite-from-row.](2522c45)
- Loading branch information
Showing
44 changed files
with
755 additions
and
571 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,4 +83,4 @@ | |
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE IF NOT EXISTS users (username TEXT PRIMARY KEY | ||
, hash TEXT NOT NULL | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE IF NOT EXISTS user_permissions (id TEXT NOT NULL | ||
, username TEXT NOT NULL | ||
, PRIMARY KEY (id, username) | ||
, FOREIGN KEY (id) REFERENCES permissions(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
, FOREIGN KEY (username) REFERENCES users(username) ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE IF NOT EXISTS tokens (id TEXT PRIMARY KEY | ||
, username TEXT NOT NULL | ||
, FOREIGN KEY (username) REFERENCES users(username) ON DELETE CASCADE ON UPDATE CASCADE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PRAGMA foreign_keys = ON |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS invites (code TEXT PRIMARY KEY | ||
, permissions TEXT NOT NULL DEFAULT '' | ||
, remaining INTEGER NOT NULL DEFAULT 1 | ||
, creator TEXT NOT NULL | ||
, FOREIGN KEY (creator) REFERENCES users(username) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE IF NOT EXISTS invite_permissions (id TEXT NOT NULL | ||
, code TEXT NOT NULL | ||
, PRIMARY KEY (id, code) | ||
, FOREIGN KEY (id) REFERENCES permissions(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
, FOREIGN KEY (code) REFERENCES invites(code) ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE IF NOT EXISTS genres ( | ||
id TEXT PRIMARY KEY | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE IF NOT EXISTS artists (id TEXT PRIMARY KEY | ||
, name TEXT NOT NULL | ||
, bio TEXT NOT NULL DEFAULT '' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS artist_genres (artist_id TEXT NOT NULL | ||
, genre_id TEXT NOT NULL | ||
, PRIMARY KEY (artist_id, genre_id) | ||
, FOREIGN KEY (artist_id) REFERENCES artists(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
, FOREIGN KEY (genre_id) REFERENCES genres(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE IF NOT EXISTS albums (id TEXT PRIMARY KEY | ||
, name TEXT NOT NULL | ||
, release INTEGER NOT NULL DEFAULT 0 | ||
, count INTEGER NOT NULL DEFAULT 1 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS artist_albums (album_id TEXT NOT NULL | ||
, artist_id TEXT NOT NULL | ||
, PRIMARY KEY (album_id, artist_id) | ||
, FOREIGN KEY (album_id) REFERENCES albums(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
, FOREIGN KEY (artist_id) REFERENCES artists(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS album_genres (album_id TEXT NOT NULL | ||
, genre_id TEXT NOT NULL | ||
, PRIMARY KEY (album_id, genre_id) | ||
, FOREIGN KEY (album_id) REFERENCES albums(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
, FOREIGN KEY (genre_id) REFERENCES genres(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS tracks (id TEXT PRIMARY KEY | ||
, name TEXT NOT NULL | ||
, release INTEGER NOT NULL DEFAULT 0 | ||
, duration INTEGER NOT NULL DEFAULT 0 | ||
, lyrics TEXT NOT NULL DEFAULT '' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS album_tracks (track_id TEXT NOT NULL | ||
, album_id TEXT NOT NULL | ||
, PRIMARY KEY (track_id, album_id) | ||
, FOREIGN KEY (track_id) REFERENCES tracks(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
, FOREIGN KEY (album_id) REFERENCES albums(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE IF NOT EXISTS track_genres (track_id TEXT NOT NULL | ||
, genre_id TEXT NOT NULL | ||
, PRIMARY KEY (track_id, genre_id) | ||
, FOREIGN KEY (track_id) REFERENCES tracks(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
, FOREIGN KEY (genre_id) REFERENCES genres(id) ON DELETE CASCADE ON UPDATE CASCADE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE IF NOT EXISTS permissions ( | ||
id TEXT PRIMARY KEY | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use crate::database::permissions::Permission; | ||
use strum::IntoEnumIterator; | ||
|
||
pub fn migration() -> String { | ||
format!( | ||
"INSERT OR IGNORE INTO permissions (id) VALUES ('{}');", | ||
Permission::iter() | ||
.map(|p| p.to_string()) | ||
.collect::<Vec<String>>() | ||
.join("'), ('") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.