diff --git a/supysonic/schema/migration/mysql/20181010.py b/supysonic/schema/migration/mysql/20181010.py deleted file mode 100644 index cc42071..0000000 --- a/supysonic/schema/migration/mysql/20181010.py +++ /dev/null @@ -1,24 +0,0 @@ -import argparse -from supysonic import db -try: - import MySQLdb as provider -except ImportError: - import pymysql as provider - -parser = argparse.ArgumentParser() -parser.add_argument('username') -parser.add_argument('password') -parser.add_argument('database') -parser.add_argument('-H', '--host', default = 'localhost', help = 'default: localhost') -args = parser.parse_args() - -with provider.connect(host = args.host, user = args.username, passwd = args.password, db = args.database) as conn: - c = conn.cursor() - c.execute('ALTER TABLE track ADD COLUMN has_art BOOLEAN NOT NULL DEFAULT false') - - art = dict() - c.execute('SELECT path FROM track') - for row in c: - art[row[0]] = bool(db.Track._extract_cover_art(row[0].encode('utf-8'))) - c.executemany('UPDATE track SET has_art=? WHERE path=?', [ (a, p) for p, a in art.items() ]) - conn.commit() diff --git a/supysonic/schema/migration/mysql/20181010.sql b/supysonic/schema/migration/mysql/20181010.sql new file mode 100644 index 0000000..df807de --- /dev/null +++ b/supysonic/schema/migration/mysql/20181010.sql @@ -0,0 +1,6 @@ +START TRANSACTION; + +ALTER TABLE track ADD has_art BOOLEAN DEFAULT false NOT NULL; + +COMMIT; + diff --git a/supysonic/schema/migration/postgres/20181010.py b/supysonic/schema/migration/postgres/20181010.py deleted file mode 100644 index 8716e26..0000000 --- a/supysonic/schema/migration/postgres/20181010.py +++ /dev/null @@ -1,21 +0,0 @@ -import argparse -import psycopg2 -from supysonic import db - -parser = argparse.ArgumentParser() -parser.add_argument('username') -parser.add_argument('password') -parser.add_argument('database') -parser.add_argument('-H', '--host', default = 'localhost', help = 'default: localhost') -args = parser.parse_args() - -with psycopg2.connect(host = args.host, user = args.username, password = args.password, dbname = args.database) as conn: - c = conn.cursor() - c.execute('ALTER TABLE track ADD COLUMN has_art BOOLEAN NOT NULL DEFAULT false') - - art = dict() - c.execute('SELECT path FROM track') - for row in c.fetchall(): - art[row[0]] = bool(db.Track._extract_cover_art(row[0].encode('utf-8'))) - c.executemany('UPDATE track SET has_art=%s WHERE path=%s', [ (a, p) for p, a in art.items() ]) - conn.commit() diff --git a/supysonic/schema/migration/postgres/20181010.sql b/supysonic/schema/migration/postgres/20181010.sql new file mode 100644 index 0000000..df807de --- /dev/null +++ b/supysonic/schema/migration/postgres/20181010.sql @@ -0,0 +1,6 @@ +START TRANSACTION; + +ALTER TABLE track ADD has_art BOOLEAN DEFAULT false NOT NULL; + +COMMIT; + diff --git a/supysonic/schema/migration/sqlite/20181010.py b/supysonic/schema/migration/sqlite/20181010.py deleted file mode 100644 index c3b7103..0000000 --- a/supysonic/schema/migration/sqlite/20181010.py +++ /dev/null @@ -1,18 +0,0 @@ -import argparse -import sqlite3 -from supysonic import db - -parser = argparse.ArgumentParser() -parser.add_argument('dbfile', help = 'Path to the SQLite database file') -args = parser.parse_args() - -with sqlite3.connect(args.dbfile) as conn: - c = conn.cursor() - c.execute('ALTER TABLE track ADD COLUMN has_art BOOLEAN NOT NULL DEFAULT false') - - art = dict() - for row in c.execute('SELECT path FROM track'): - art[row[0]] = bool(db.Track._extract_cover_art(row[0].encode('utf-8'))) - c.executemany('UPDATE track SET has_art=? WHERE path=?', [ (a, p) for p, a in art.items() ]) - conn.commit() - conn.execute('VACUUM') diff --git a/supysonic/schema/migration/sqlite/20181010.sql b/supysonic/schema/migration/sqlite/20181010.sql new file mode 100644 index 0000000..f4013c9 --- /dev/null +++ b/supysonic/schema/migration/sqlite/20181010.sql @@ -0,0 +1,3 @@ +ALTER TABLE track ADD has_art BOOLEAN DEFAULT false NOT NULL; + +COMMIT; diff --git a/supysonic/schema/mysql.sql b/supysonic/schema/mysql.sql index 68571b4..5c48f03 100644 --- a/supysonic/schema/mysql.sql +++ b/supysonic/schema/mysql.sql @@ -29,7 +29,7 @@ CREATE TABLE IF NOT EXISTS track ( year INTEGER, genre VARCHAR(256), duration INTEGER NOT NULL, - has_art BOOLEAN NOT NULL, + has_art BOOLEAN NOT NULL DEFAULT false, album_id BINARY(16) NOT NULL REFERENCES album, artist_id BINARY(16) NOT NULL REFERENCES artist, bitrate INTEGER NOT NULL, diff --git a/supysonic/schema/postgres.sql b/supysonic/schema/postgres.sql index 5f447c1..66cbb60 100644 --- a/supysonic/schema/postgres.sql +++ b/supysonic/schema/postgres.sql @@ -29,7 +29,7 @@ CREATE TABLE IF NOT EXISTS track ( year INTEGER, genre VARCHAR(256), duration INTEGER NOT NULL, - has_art BOOLEAN NOT NULL, + has_art BOOLEAN NOT NULL DEFAULT false, album_id UUID NOT NULL REFERENCES album, artist_id UUID NOT NULL REFERENCES artist, bitrate INTEGER NOT NULL, diff --git a/supysonic/schema/sqlite.sql b/supysonic/schema/sqlite.sql index c7781b4..169ab58 100644 --- a/supysonic/schema/sqlite.sql +++ b/supysonic/schema/sqlite.sql @@ -31,7 +31,7 @@ CREATE TABLE IF NOT EXISTS track ( year INTEGER, genre VARCHAR(256), duration INTEGER NOT NULL, - has_art BOOLEAN NOT NULL, + has_art BOOLEAN NOT NULL DEFAULT false, album_id CHAR(36) NOT NULL REFERENCES album, artist_id CHAR(36) NOT NULL REFERENCES artist, bitrate INTEGER NOT NULL,