diff --git a/README.md b/README.md index 8f41e4a..3833d11 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,12 @@ _MySQL_-compatible or _PostgreSQL_ database. _Supysonic_ does not automatically create the database and tables it needs to work. Thus the database and tables must be created prior to running the application. Please refer to the documentation of the DBMS you've chosen on how -to create a database and how to use a command-line client. +to create a database and how to use a command-line client. If you want to use +_PostgreSQL_ you'll have to add the `citext` extension to the database once +created. This can be done when connected to the database as the superuser with +the folowing SQL command: + + supysonic=# CREATE EXTENSION citext; Table creation scripts are provided in the `schema` folder for _SQLite_, _MySQL_ and _PostgreSQL_. Just feed them to any client you're able to use. diff --git a/schema/migration/20180311.postgresql.sql b/schema/migration/20180311.postgresql.sql new file mode 100644 index 0000000..f6623e0 --- /dev/null +++ b/schema/migration/20180311.postgresql.sql @@ -0,0 +1,9 @@ +START TRANSACTION; + +ALTER TABLE folder ALTER COLUMN name TYPE CITEXT; +ALTER TABLE artist ALTER COLUMN name TYPE CITEXT; +ALTER TABLE album ALTER COLUMN name TYPE CITEXT; +ALTER TABLE track ALTER COLUMN title TYPE CITEXT; + +COMMIT; + diff --git a/schema/migration/20180311.sqlite.sql b/schema/migration/20180311.sqlite.sql new file mode 100644 index 0000000..9ec02dd --- /dev/null +++ b/schema/migration/20180311.sqlite.sql @@ -0,0 +1,52 @@ +BEGIN TRANSACTION; + +ALTER TABLE folder RENAME TO folder_old; +ALTER TABLE track RENAME TO track_old; + +CREATE TABLE folder ( + id CHAR(36) PRIMARY KEY, + root BOOLEAN NOT NULL, + name VARCHAR(256) NOT NULL COLLATE NOCASE, + path VARCHAR(4096) NOT NULL, + created DATETIME NOT NULL, + has_cover_art BOOLEAN NOT NULL, + last_scan INTEGER NOT NULL, + parent_id CHAR(36) REFERENCES folder +); + +CREATE TABLE track ( + id CHAR(36) PRIMARY KEY, + disc INTEGER NOT NULL, + number INTEGER NOT NULL, + title VARCHAR(256) NOT NULL COLLATE NOCASE, + year INTEGER, + genre VARCHAR(256), + duration INTEGER NOT NULL, + album_id CHAR(36) NOT NULL REFERENCES album, + artist_id CHAR(36) NOT NULL REFERENCES artist, + bitrate INTEGER NOT NULL, + path VARCHAR(4096) NOT NULL, + content_type VARCHAR(32) NOT NULL, + created DATETIME NOT NULL, + last_modification INTEGER NOT NULL, + play_count INTEGER NOT NULL, + last_play DATETIME, + root_folder_id CHAR(36) NOT NULL REFERENCES folder, + folder_id CHAR(36) NOT NULL REFERENCES folder +); + +INSERT INTO folder (id, root, name, path, created, has_cover_art, last_scan, parent_id) +SELECT id, root, name, path, created, has_cover_art, last_scan, parent_id +FROM folder_old; + +INSERT INTO track(id, disc, number, title, year, genre, duration, album_id, artist_id, bitrate, path, content_type, created, last_modification, play_count, last_play, root_folder_id, folder_id) +SELECT id, disc, number, title, year, genre, duration, album_id, artist_id, bitrate, path, content_type, created, last_modification, play_count, last_play, root_folder_id, folder_id +FROM track_old; + +DROP TABLE folder_old; +DROP TABLE track_old; + +COMMIT; + +VACUUM; + diff --git a/schema/postgresql.sql b/schema/postgresql.sql index a325d55..4aadbc2 100644 --- a/schema/postgresql.sql +++ b/schema/postgresql.sql @@ -1,7 +1,7 @@ CREATE TABLE folder ( id UUID PRIMARY KEY, root BOOLEAN NOT NULL, - name VARCHAR(256) NOT NULL, + name CITEXT NOT NULL, path VARCHAR(4096) NOT NULL, created TIMESTAMP NOT NULL, has_cover_art BOOLEAN NOT NULL, @@ -11,12 +11,12 @@ CREATE TABLE folder ( CREATE TABLE artist ( id UUID PRIMARY KEY, - name VARCHAR(256) NOT NULL + name CITEXT NOT NULL ); CREATE TABLE album ( id UUID PRIMARY KEY, - name VARCHAR(256) NOT NULL, + name CITEXT NOT NULL, artist_id UUID NOT NULL REFERENCES artist ); @@ -24,7 +24,7 @@ CREATE TABLE track ( id UUID PRIMARY KEY, disc INTEGER NOT NULL, number INTEGER NOT NULL, - title VARCHAR(256) NOT NULL, + title CITEXT NOT NULL, year INTEGER, genre VARCHAR(256), duration INTEGER NOT NULL, diff --git a/schema/sqlite.sql b/schema/sqlite.sql index 9dbc93f..4d7872f 100644 --- a/schema/sqlite.sql +++ b/schema/sqlite.sql @@ -1,7 +1,7 @@ CREATE TABLE folder ( id CHAR(36) PRIMARY KEY, root BOOLEAN NOT NULL, - name VARCHAR(256) NOT NULL, + name VARCHAR(256) NOT NULL COLLATE NOCASE, path VARCHAR(4096) NOT NULL, created DATETIME NOT NULL, has_cover_art BOOLEAN NOT NULL, @@ -24,7 +24,7 @@ CREATE TABLE track ( id CHAR(36) PRIMARY KEY, disc INTEGER NOT NULL, number INTEGER NOT NULL, - title VARCHAR(256) NOT NULL, + title VARCHAR(256) NOT NULL COLLATE NOCASE, year INTEGER, genre VARCHAR(256), duration INTEGER NOT NULL,