diff --git a/libresonic-main/pom.xml b/libresonic-main/pom.xml index 499b9ffc..9232f483 100644 --- a/libresonic-main/pom.xml +++ b/libresonic-main/pom.xml @@ -125,6 +125,12 @@ 2.1 + + org.apache.commons + commons-lang3 + 3.3.2 + + com.google.guava guava @@ -366,6 +372,13 @@ runtime + + org.liquibase + liquibase-core + + 3.5.1 + + diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/DaoHelperFactory.java b/libresonic-main/src/main/java/org/libresonic/player/dao/DaoHelperFactory.java deleted file mode 100644 index e3287d37..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/DaoHelperFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of Libresonic. - * - * Libresonic is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Libresonic is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Libresonic. If not, see . - * - * Copyright 2015 (C) Sindre Mehus - */ - -package org.libresonic.player.dao; - -/** - * @author Sindre Mehus - * @version $Id$ - */ -public class DaoHelperFactory { - - public static DaoHelper create() { - return new HsqlDaoHelper(); - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/GenericDaoHelper.java b/libresonic-main/src/main/java/org/libresonic/player/dao/GenericDaoHelper.java new file mode 100644 index 00000000..d4007f80 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/GenericDaoHelper.java @@ -0,0 +1,28 @@ +package org.libresonic.player.dao; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; + +public class GenericDaoHelper implements DaoHelper { + + JdbcTemplate jdbcTemplate; + + NamedParameterJdbcTemplate namedParameterJdbcTemplate; + + public GenericDaoHelper( + JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate namedParameterJdbcTemplate + ) { + this.jdbcTemplate = jdbcTemplate; + this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; + } + + @Override + public JdbcTemplate getJdbcTemplate() { + return jdbcTemplate; + } + + @Override + public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { + return namedParameterJdbcTemplate; + } +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/HsqlDaoHelper.java b/libresonic-main/src/main/java/org/libresonic/player/dao/HsqlDaoHelper.java deleted file mode 100644 index 43880551..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/HsqlDaoHelper.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This file is part of Libresonic. - * - * Libresonic is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Libresonic is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Libresonic. If not, see . - * - * Copyright 2015 (C) Sindre Mehus - */ -package org.libresonic.player.dao; - -import java.io.File; - -import javax.sql.DataSource; - -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import org.springframework.jdbc.datasource.DriverManagerDataSource; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; -import org.libresonic.player.dao.schema.hsql.Schema25; -import org.libresonic.player.dao.schema.hsql.Schema26; -import org.libresonic.player.dao.schema.hsql.Schema27; -import org.libresonic.player.dao.schema.hsql.Schema28; -import org.libresonic.player.dao.schema.hsql.Schema29; -import org.libresonic.player.dao.schema.hsql.Schema30; -import org.libresonic.player.dao.schema.hsql.Schema31; -import org.libresonic.player.dao.schema.hsql.Schema32; -import org.libresonic.player.dao.schema.hsql.Schema33; -import org.libresonic.player.dao.schema.hsql.Schema34; -import org.libresonic.player.dao.schema.hsql.Schema35; -import org.libresonic.player.dao.schema.hsql.Schema36; -import org.libresonic.player.dao.schema.hsql.Schema37; -import org.libresonic.player.dao.schema.hsql.Schema38; -import org.libresonic.player.dao.schema.hsql.Schema40; -import org.libresonic.player.dao.schema.hsql.Schema43; -import org.libresonic.player.dao.schema.hsql.Schema45; -import org.libresonic.player.dao.schema.hsql.Schema46; -import org.libresonic.player.dao.schema.hsql.Schema47; -import org.libresonic.player.dao.schema.hsql.Schema49; -import org.libresonic.player.dao.schema.hsql.Schema50; -import org.libresonic.player.dao.schema.hsql.Schema51; -import org.libresonic.player.dao.schema.hsql.Schema52; -import org.libresonic.player.dao.schema.hsql.Schema53; -import org.libresonic.player.dao.schema.hsql.Schema61; -import org.libresonic.player.dao.schema.hsql.Schema62; -import org.libresonic.player.service.SettingsService; - -/** - * DAO helper class which creates the data source, and updates the database schema. - * - * @author Sindre Mehus - */ -public class HsqlDaoHelper implements DaoHelper { - - private static final Logger LOG = Logger.getLogger(HsqlDaoHelper.class); - - private Schema[] schemas = {new Schema25(), new Schema26(), new Schema27(), new Schema28(), new Schema29(), - new Schema30(), new Schema31(), new Schema32(), new Schema33(), new Schema34(), - new Schema35(), new Schema36(), new Schema37(), new Schema38(), new Schema40(), - new Schema43(), new Schema45(), new Schema46(), new Schema47(), new Schema49(), - new Schema50(), new Schema51(), new Schema52(), new Schema53(), new Schema61(), - new Schema62()}; - private DataSource dataSource; - private static boolean shutdownHookAdded; - - public HsqlDaoHelper() { - dataSource = createDataSource(); - checkDatabase(); - addShutdownHook(); - } - - private void addShutdownHook() { - if (shutdownHookAdded) { - return; - } - shutdownHookAdded = true; - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - System.err.println("Shutting down database..."); - getJdbcTemplate().execute("shutdown"); - System.err.println("Shutting down database - Done!"); - } - }); - } - - /** - * Returns a JDBC template for performing database operations. - * - * @return A JDBC template. - */ - public JdbcTemplate getJdbcTemplate() { - return new JdbcTemplate(dataSource); - } - - public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { - return new NamedParameterJdbcTemplate(dataSource); - } - - private DataSource createDataSource() { - File libresonicHome = SettingsService.getLibresonicHome(); - DriverManagerDataSource ds = new DriverManagerDataSource(); - ds.setDriverClassName("org.hsqldb.jdbcDriver"); - ds.setUrl("jdbc:hsqldb:file:" + libresonicHome.getPath() + "/db/libresonic"); - ds.setUsername("sa"); - ds.setPassword(""); - - return ds; - } - - private void checkDatabase() { - LOG.info("Checking database schema."); - try { - for (Schema schema : schemas) { - schema.execute(getJdbcTemplate()); - } - LOG.info("Done checking database schema."); - } catch (Exception x) { - LOG.error("Failed to initialize database.", x); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java index 37d9f6a4..4dc8dc2a 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java @@ -153,7 +153,7 @@ public class PlayerDao extends AbstractDao { update(sql, player.getName(), player.getType(), player.getUsername(), player.getIpAddress(), player.isAutoControlEnabled(), player.isM3uBomEnabled(), player.getLastSeen(), player.getTranscodeScheme().name(), player.isDynamicIp(), - player.getTechnology(), player.getClientId(), player.getId()); + player.getTechnology().name(), player.getClientId(), player.getId()); } private void addPlaylist(Player player) { diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/UserDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/UserDao.java index b8aa5e45..f9b05984 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/UserDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/UserDao.java @@ -61,6 +61,8 @@ public class UserDao extends AbstractDao { private UserRowMapper userRowMapper = new UserRowMapper(); private UserSettingsRowMapper userSettingsRowMapper = new UserSettingsRowMapper(); + String userTableQuote = ""; + /** * Returns the user with the given username. * @@ -68,7 +70,7 @@ public class UserDao extends AbstractDao { * @return The user, or null if not found. */ public User getUserByName(String username) { - String sql = "select " + USER_COLUMNS + " from user where username=?"; + String sql = "select " + USER_COLUMNS + " from " + getUserTable() + " where username=?"; return queryOne(sql, userRowMapper, username); } @@ -79,7 +81,7 @@ public class UserDao extends AbstractDao { * @return The user, or null if not found. */ public User getUserByEmail(String email) { - String sql = "select " + USER_COLUMNS + " from user where email=?"; + String sql = "select " + USER_COLUMNS + " from " + getUserTable() + " where email=?"; return queryOne(sql, userRowMapper, email); } @@ -89,7 +91,7 @@ public class UserDao extends AbstractDao { * @return Possibly empty array of all users. */ public List getAllUsers() { - String sql = "select " + USER_COLUMNS + " from user"; + String sql = "select " + USER_COLUMNS + " from " + getUserTable(); return query(sql, userRowMapper); } @@ -99,7 +101,7 @@ public class UserDao extends AbstractDao { * @param user The user to create. */ public void createUser(User user) { - String sql = "insert into user (" + USER_COLUMNS + ") values (" + questionMarks(USER_COLUMNS) + ')'; + String sql = "insert into " + getUserTable() + " (" + USER_COLUMNS + ") values (" + questionMarks(USER_COLUMNS) + ')'; update(sql, user.getUsername(), encrypt(user.getPassword()), user.getEmail(), user.isLdapAuthenticated(), user.getBytesStreamed(), user.getBytesDownloaded(), user.getBytesUploaded()); writeRoles(user); @@ -117,7 +119,7 @@ public class UserDao extends AbstractDao { update("delete from user_role where username=?", username); update("delete from player where username=?", username); - update("delete from user where username=?", username); + update("delete from " + getUserTable() + " where username=?", username); } /** @@ -126,7 +128,7 @@ public class UserDao extends AbstractDao { * @param user The user to update. */ public void updateUser(User user) { - String sql = "update user set password=?, email=?, ldap_authenticated=?, bytes_streamed=?, bytes_downloaded=?, bytes_uploaded=? " + + String sql = "update " + getUserTable() + " set password=?, email=?, ldap_authenticated=?, bytes_streamed=?, bytes_downloaded=?, bytes_uploaded=? " + "where username=?"; getJdbcTemplate().update(sql, new Object[]{encrypt(user.getPassword()), user.getEmail(), user.isLdapAuthenticated(), user.getBytesStreamed(), user.getBytesDownloaded(), user.getBytesUploaded(), @@ -355,4 +357,12 @@ public class UserDao extends AbstractDao { return settings; } } + + private String getUserTable() { + return userTableQuote + "user" + userTableQuote; + } + + public void setUserTableQuote(String userTableQuote) { + this.userTableQuote = userTableQuote; + } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/Schema.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/Schema.java deleted file mode 100644 index 13872a82..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/Schema.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema; - -import org.springframework.jdbc.core.*; - -/** - * Used for creating and evolving the database schema. - * - * @author Sindre Mehus - */ -public abstract class Schema { - - /** - * Executes this schema. - * @param template The JDBC template to use. - */ - public abstract void execute(JdbcTemplate template); - - /** - * Returns whether the given table exists. - * @param template The JDBC template to use. - * @param table The table in question. - * @return Whether the table exists. - */ - protected boolean tableExists(JdbcTemplate template, String table) { - try { - template.execute("select 1 from " + table); - } catch (Exception x) { - return false; - } - return true; - } - - /** - * Returns whether the given column in the given table exists. - * @param template The JDBC template to use. - * @param column The column in question. - * @param table The table in question. - * @return Whether the column exists. - */ - protected boolean columnExists(JdbcTemplate template, String column, String table) { - try { - template.execute("select " + column + " from " + table + " where 1 = 0"); - } catch (Exception x) { - return false; - } - return true; - } - - - protected boolean rowExists(JdbcTemplate template, String whereClause, String table) { - try { - int rowCount = template.queryForObject("select count(*) from " + table + " where " + whereClause,Integer.class); - return rowCount > 0; - } catch (Exception x) { - return false; - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema25.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema25.java deleted file mode 100644 index 14dc996d..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema25.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 2.5. - * - * @author Sindre Mehus - */ -public class Schema25 extends Schema { - private static final Logger LOG = Logger.getLogger(Schema25.class); - - public void execute(JdbcTemplate template) { - if (!tableExists(template, "version")) { - - // Increase data file limit. See http://www.hsqldb.org/doc/guide/ch04.html - template.execute("set property \"hsqldb.cache_file_scale\" 8"); - - LOG.info("Database table 'version' not found. Creating it."); - template.execute("create table version (version int not null)"); - template.execute("insert into version values (1)"); - LOG.info("Database table 'version' was created successfully."); - } - - if (!tableExists(template, "role")) { - LOG.info("Database table 'role' not found. Creating it."); - template.execute("create table role (" + - "id int not null," + - "name varchar not null," + - "primary key (id))"); - template.execute("insert into role values (1, 'admin')"); - template.execute("insert into role values (2, 'download')"); - template.execute("insert into role values (3, 'upload')"); - template.execute("insert into role values (4, 'playlist')"); - template.execute("insert into role values (5, 'coverart')"); - LOG.info("Database table 'role' was created successfully."); - } - - if (!tableExists(template, "user")) { - LOG.info("Database table 'user' not found. Creating it."); - template.execute("create table user (" + - "username varchar not null," + - "password varchar not null," + - "primary key (username))"); - template.execute("insert into user values ('admin', 'admin')"); - LOG.info("Database table 'user' was created successfully."); - } - - if (!tableExists(template, "user_role")) { - LOG.info("Database table 'user_role' not found. Creating it."); - template.execute("create table user_role (" + - "username varchar not null," + - "role_id int not null," + - "primary key (username, role_id)," + - "foreign key (username) references user(username)," + - "foreign key (role_id) references role(id))"); - template.execute("insert into user_role values ('admin', 1)"); - template.execute("insert into user_role values ('admin', 2)"); - template.execute("insert into user_role values ('admin', 3)"); - template.execute("insert into user_role values ('admin', 4)"); - template.execute("insert into user_role values ('admin', 5)"); - LOG.info("Database table 'user_role' was created successfully."); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema26.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema26.java deleted file mode 100644 index 05413aaf..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema26.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.*; -import org.libresonic.player.dao.schema.Schema; -import org.libresonic.player.util.Util; -import org.springframework.jdbc.core.*; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 2.6. - * - * @author Sindre Mehus - */ -public class Schema26 extends Schema { - private static final Logger LOG = Logger.getLogger(Schema26.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 2",Integer.class) == 0) { - LOG.info("Updating database schema to version 2."); - template.execute("insert into version values (2)"); - } - - if (!tableExists(template, "music_folder")) { - LOG.info("Database table 'music_folder' not found. Creating it."); - template.execute("create table music_folder (" + - "id identity," + - "path varchar not null," + - "name varchar not null," + - "enabled boolean not null)"); - template.execute("insert into music_folder values (null, '" + Util.getDefaultMusicFolder() + "', 'Music', true)"); - LOG.info("Database table 'music_folder' was created successfully."); - } - - if (!tableExists(template, "music_file_info")) { - LOG.info("Database table 'music_file_info' not found. Creating it."); - template.execute("create cached table music_file_info (" + - "id identity," + - "path varchar not null," + - "rating int," + - "comment varchar," + - "play_count int," + - "last_played datetime)"); - template.execute("create index idx_music_file_info_path on music_file_info(path)"); - LOG.info("Database table 'music_file_info' was created successfully."); - } - - if (!tableExists(template, "internet_radio")) { - LOG.info("Database table 'internet_radio' not found. Creating it."); - template.execute("create table internet_radio (" + - "id identity," + - "name varchar not null," + - "stream_url varchar not null," + - "homepage_url varchar," + - "enabled boolean not null)"); - LOG.info("Database table 'internet_radio' was created successfully."); - } - - if (!tableExists(template, "player")) { - LOG.info("Database table 'player' not found. Creating it."); - template.execute("create table player (" + - "id int not null," + - "name varchar," + - "type varchar," + - "username varchar," + - "ip_address varchar," + - "auto_control_enabled boolean not null," + - "last_seen datetime," + - "cover_art_scheme varchar not null," + - "transcode_scheme varchar not null," + - "primary key (id))"); - LOG.info("Database table 'player' was created successfully."); - } - - // 'dynamic_ip' was added in 2.6.beta2 - if (!columnExists(template, "dynamic_ip", "player")) { - LOG.info("Database column 'player.dynamic_ip' not found. Creating it."); - template.execute("alter table player " + - "add dynamic_ip boolean default true not null"); - LOG.info("Database column 'player.dynamic_ip' was added successfully."); - } - - if (template.queryForObject("select count(*) from role where id = 6",Integer.class) == 0) { - LOG.info("Role 'comment' not found in database. Creating it."); - template.execute("insert into role values (6, 'comment')"); - template.execute("insert into user_role " + - "select distinct u.username, 6 from user u, user_role ur " + - "where u.username = ur.username and ur.role_id in (1, 5)"); - LOG.info("Role 'comment' was created successfully."); - } - } - -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema27.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema27.java deleted file mode 100644 index 08ae2aa4..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema27.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.*; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.*; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 2.7. - * - * @author Sindre Mehus - */ -public class Schema27 extends Schema { - private static final Logger LOG = Logger.getLogger(Schema27.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 3",Integer.class) == 0) { - LOG.info("Updating database schema to version 3."); - template.execute("insert into version values (3)"); - - LOG.info("Converting database column 'music_file_info.path' to varchar_ignorecase."); - template.execute("drop index idx_music_file_info_path"); - template.execute("alter table music_file_info alter column path varchar_ignorecase not null"); - template.execute("create index idx_music_file_info_path on music_file_info(path)"); - LOG.info("Database column 'music_file_info.path' was converted successfully."); - } - - if (!columnExists(template, "bytes_streamed", "user")) { - LOG.info("Database columns 'user.bytes_streamed/downloaded/uploaded' not found. Creating them."); - template.execute("alter table user add bytes_streamed bigint default 0 not null"); - template.execute("alter table user add bytes_downloaded bigint default 0 not null"); - template.execute("alter table user add bytes_uploaded bigint default 0 not null"); - LOG.info("Database columns 'user.bytes_streamed/downloaded/uploaded' were added successfully."); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema28.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema28.java deleted file mode 100644 index 515a4c0f..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema28.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.*; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.*; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 2.8. - * - * @author Sindre Mehus - */ -public class Schema28 extends Schema { - private static final Logger LOG = Logger.getLogger(Schema28.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 4",Integer.class) == 0) { - LOG.info("Updating database schema to version 4."); - template.execute("insert into version values (4)"); - } - - if (!tableExists(template, "user_settings")) { - LOG.info("Database table 'user_settings' not found. Creating it."); - template.execute("create table user_settings (" + - "username varchar not null," + - "locale varchar," + - "theme_id varchar," + - "final_version_notification boolean default true not null," + - "beta_version_notification boolean default false not null," + - "main_caption_cutoff int default 35 not null," + - "main_track_number boolean default true not null," + - "main_artist boolean default true not null," + - "main_album boolean default false not null," + - "main_genre boolean default false not null," + - "main_year boolean default false not null," + - "main_bit_rate boolean default false not null," + - "main_duration boolean default true not null," + - "main_format boolean default false not null," + - "main_file_size boolean default false not null," + - "playlist_caption_cutoff int default 35 not null," + - "playlist_track_number boolean default false not null," + - "playlist_artist boolean default true not null," + - "playlist_album boolean default true not null," + - "playlist_genre boolean default false not null," + - "playlist_year boolean default true not null," + - "playlist_bit_rate boolean default false not null," + - "playlist_duration boolean default true not null," + - "playlist_format boolean default true not null," + - "playlist_file_size boolean default true not null," + - "primary key (username)," + - "foreign key (username) references user(username) on delete cascade)"); - LOG.info("Database table 'user_settings' was created successfully."); - } - - if (!tableExists(template, "transcoding")) { - LOG.info("Database table 'transcoding' not found. Creating it."); - template.execute("create table transcoding (" + - "id identity," + - "name varchar not null," + - "source_format varchar not null," + - "target_format varchar not null," + - "step1 varchar not null," + - "step2 varchar," + - "step3 varchar," + - "enabled boolean not null)"); - - template.execute("insert into transcoding values(null,'wav > mp3', 'wav', 'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,true)"); - template.execute("insert into transcoding values(null,'flac > mp3','flac','mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,true)"); - template.execute("insert into transcoding values(null,'ogg > mp3' ,'ogg' ,'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,true)"); - template.execute("insert into transcoding values(null,'wma > mp3' ,'wma' ,'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,true)"); - template.execute("insert into transcoding values(null,'m4a > mp3' ,'m4a' ,'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,false)"); - template.execute("insert into transcoding values(null,'aac > mp3' ,'aac' ,'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,false)"); - template.execute("insert into transcoding values(null,'ape > mp3' ,'ape' ,'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,true)"); - template.execute("insert into transcoding values(null,'mpc > mp3' ,'mpc' ,'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,true)"); - template.execute("insert into transcoding values(null,'mv > mp3' ,'mv' ,'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,true)"); - template.execute("insert into transcoding values(null,'shn > mp3' ,'shn' ,'mp3','ffmpeg -i %s -v 0 -f wav -','lame -b %b --tt %t --ta %a --tl %l -S --resample 44.1 - -',null,true)"); - - LOG.info("Database table 'transcoding' was created successfully."); - } - - if (!tableExists(template, "player_transcoding")) { - LOG.info("Database table 'player_transcoding' not found. Creating it."); - template.execute("create table player_transcoding (" + - "player_id int not null," + - "transcoding_id int not null," + - "primary key (player_id, transcoding_id)," + - "foreign key (player_id) references player(id) on delete cascade," + - "foreign key (transcoding_id) references transcoding(id) on delete cascade)"); - LOG.info("Database table 'player_transcoding' was created successfully."); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema29.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema29.java deleted file mode 100644 index bef298f9..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema29.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.*; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.*; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 2.9. - * - * @author Sindre Mehus - */ -public class Schema29 extends Schema { - private static final Logger LOG = Logger.getLogger(Schema29.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 5",Integer.class) == 0) { - LOG.info("Updating database schema to version 5."); - template.execute("insert into version values (5)"); - } - - if (!tableExists(template, "user_rating")) { - LOG.info("Database table 'user_rating' not found. Creating it."); - template.execute("create table user_rating (" + - "username varchar not null," + - "path varchar not null," + - "rating double not null," + - "primary key (username, path)," + - "foreign key (username) references user(username) on delete cascade)"); - LOG.info("Database table 'user_rating' was created successfully."); - - template.execute("insert into user_rating select 'admin', path, rating from music_file_info " + - "where rating is not null and rating > 0"); - LOG.info("Migrated data from 'music_file_info' to 'user_rating'."); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema30.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema30.java deleted file mode 100644 index 18e73175..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema30.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.*; -import org.libresonic.player.dao.schema.Schema; -import org.libresonic.player.domain.TranscodeScheme; -import org.springframework.jdbc.core.*; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 3.0. - * - * @author Sindre Mehus - */ -public class Schema30 extends Schema { - private static final Logger LOG = Logger.getLogger(Schema30.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 6", Integer.class) == 0) { - LOG.info("Updating database schema to version 6."); - template.execute("insert into version values (6)"); - } - - if (!columnExists(template, "last_fm_enabled", "user_settings")) { - LOG.info("Database columns 'user_settings.last_fm_*' not found. Creating them."); - template.execute("alter table user_settings add last_fm_enabled boolean default false not null"); - template.execute("alter table user_settings add last_fm_username varchar null"); - template.execute("alter table user_settings add last_fm_password varchar null"); - LOG.info("Database columns 'user_settings.last_fm_*' were added successfully."); - } - - if (!columnExists(template, "transcode_scheme", "user_settings")) { - LOG.info("Database column 'user_settings.transcode_scheme' not found. Creating it."); - template.execute("alter table user_settings add transcode_scheme varchar default '" + - TranscodeScheme.OFF.name() + "' not null"); - LOG.info("Database column 'user_settings.transcode_scheme' was added successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema31.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema31.java deleted file mode 100644 index 6019070c..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema31.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 3.1. - * - * @author Sindre Mehus - */ -public class Schema31 extends Schema { - private static final Logger LOG = Logger.getLogger(Schema31.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 7",Integer.class) == 0) { - LOG.info("Updating database schema to version 7."); - template.execute("insert into version values (7)"); - } - - if (!columnExists(template, "enabled", "music_file_info")) { - LOG.info("Database column 'music_file_info.enabled' not found. Creating it."); - template.execute("alter table music_file_info add enabled boolean default true not null"); - LOG.info("Database column 'music_file_info.enabled' was added successfully."); - } - - if (!columnExists(template, "default_active", "transcoding")) { - LOG.info("Database column 'transcoding.default_active' not found. Creating it."); - template.execute("alter table transcoding add default_active boolean default true not null"); - LOG.info("Database column 'transcoding.default_active' was added successfully."); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema32.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema32.java deleted file mode 100644 index 85ad7f50..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema32.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 3.2. - * - * @author Sindre Mehus - */ -public class Schema32 extends Schema { - private static final Logger LOG = Logger.getLogger(Schema32.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 8",Integer.class) == 0) { - LOG.info("Updating database schema to version 8."); - template.execute("insert into version values (8)"); - } - - if (!columnExists(template, "show_now_playing", "user_settings")) { - LOG.info("Database column 'user_settings.show_now_playing' not found. Creating it."); - template.execute("alter table user_settings add show_now_playing boolean default true not null"); - LOG.info("Database column 'user_settings.show_now_playing' was added successfully."); - } - - if (!columnExists(template, "selected_music_folder_id", "user_settings")) { - LOG.info("Database column 'user_settings.selected_music_folder_id' not found. Creating it."); - template.execute("alter table user_settings add selected_music_folder_id int default -1 not null"); - LOG.info("Database column 'user_settings.selected_music_folder_id' was added successfully."); - } - - if (!tableExists(template, "podcast_channel")) { - LOG.info("Database table 'podcast_channel' not found. Creating it."); - template.execute("create table podcast_channel (" + - "id identity," + - "url varchar not null," + - "title varchar," + - "description varchar," + - "status varchar not null," + - "error_message varchar)"); - LOG.info("Database table 'podcast_channel' was created successfully."); - } - - if (!tableExists(template, "podcast_episode")) { - LOG.info("Database table 'podcast_episode' not found. Creating it."); - template.execute("create table podcast_episode (" + - "id identity," + - "channel_id int not null," + - "url varchar not null," + - "path varchar," + - "title varchar," + - "description varchar," + - "publish_date datetime," + - "duration varchar," + - "bytes_total bigint," + - "bytes_downloaded bigint," + - "status varchar not null," + - "error_message varchar," + - "foreign key (channel_id) references podcast_channel(id) on delete cascade)"); - LOG.info("Database table 'podcast_episode' was created successfully."); - } - - if (template.queryForObject("select count(*) from role where id = 7",Integer.class) == 0) { - LOG.info("Role 'podcast' not found in database. Creating it."); - template.execute("insert into role values (7, 'podcast')"); - template.execute("insert into user_role " + - "select distinct u.username, 7 from user u, user_role ur " + - "where u.username = ur.username and ur.role_id = 1"); - LOG.info("Role 'podcast' was created successfully."); - } - - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema33.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema33.java deleted file mode 100644 index ffb0f4c1..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema33.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 3.3. - * - * @author Sindre Mehus - */ -public class Schema33 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema33.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 9",Integer.class) == 0) { - LOG.info("Updating database schema to version 9."); - template.execute("insert into version values (9)"); - } - - if (!columnExists(template, "client_side_playlist", "player")) { - LOG.info("Database column 'player.client_side_playlist' not found. Creating it."); - template.execute("alter table player add client_side_playlist boolean default false not null"); - LOG.info("Database column 'player.client_side_playlist' was added successfully."); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema34.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema34.java deleted file mode 100644 index 7f3b09c6..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema34.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 3.4. - * - * @author Sindre Mehus - */ -public class Schema34 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema34.class); - - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 10",Integer.class) == 0) { - LOG.info("Updating database schema to version 10."); - template.execute("insert into version values (10)"); - } - - if (!columnExists(template, "ldap_authenticated", "user")) { - LOG.info("Database column 'user.ldap_authenticated' not found. Creating it."); - template.execute("alter table user add ldap_authenticated boolean default false not null"); - LOG.info("Database column 'user.ldap_authenticated' was added successfully."); - } - - if (!columnExists(template, "party_mode_enabled", "user_settings")) { - LOG.info("Database column 'user_settings.party_mode_enabled' not found. Creating it."); - template.execute("alter table user_settings add party_mode_enabled boolean default false not null"); - LOG.info("Database column 'user_settings.party_mode_enabled' was added successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema35.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema35.java deleted file mode 100644 index 5ed4b9d5..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema35.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.apache.commons.io.IOUtils; -import org.springframework.jdbc.core.JdbcTemplate; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 3.5. - * - * @author Sindre Mehus - */ -public class Schema35 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema35.class); - - private static final String[] AVATARS = { - "Formal", "Engineer", "Footballer", "Green-Boy", - - "Linux-Zealot", "Mac-Zealot", "Windows-Zealot", "Army-Officer", "Beatnik", - "All-Caps", "Clown", "Commie-Pinko", "Forum-Flirt", "Gamer", "Hopelessly-Addicted", - "Jekyll-And-Hyde", "Joker", "Lurker", "Moderator", "Newbie", "No-Dissent", - "Performer", "Push-My-Button", "Ray-Of-Sunshine", "Red-Hot-Chili-Peppers-1", - "Red-Hot-Chili-Peppers-2", "Red-Hot-Chili-Peppers-3", "Red-Hot-Chili-Peppers-4", - "Ringmaster", "Rumor-Junkie", "Sozzled-Surfer", "Statistician", "Tech-Support", - "The-Guru", "The-Referee", "Troll", "Uptight", - - "Fire-Guitar", "Drum", "Headphones", "Mic", "Turntable", "Vinyl", - - "Cool", "Laugh", "Study" - }; - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 11",Integer.class) == 0) { - LOG.info("Updating database schema to version 11."); - template.execute("insert into version values (11)"); - } - - if (!columnExists(template, "now_playing_allowed", "user_settings")) { - LOG.info("Database column 'user_settings.now_playing_allowed' not found. Creating it."); - template.execute("alter table user_settings add now_playing_allowed boolean default true not null"); - LOG.info("Database column 'user_settings.now_playing_allowed' was added successfully."); - } - - if (!columnExists(template, "web_player_default", "user_settings")) { - LOG.info("Database column 'user_settings.web_player_default' not found. Creating it."); - template.execute("alter table user_settings add web_player_default boolean default false not null"); - LOG.info("Database column 'user_settings.web_player_default' was added successfully."); - } - - if (template.queryForObject("select count(*) from role where id = 8",Integer.class) == 0) { - LOG.info("Role 'stream' not found in database. Creating it."); - template.execute("insert into role values (8, 'stream')"); - template.execute("insert into user_role select distinct u.username, 8 from user u"); - LOG.info("Role 'stream' was created successfully."); - } - - if (!tableExists(template, "system_avatar")) { - LOG.info("Database table 'system_avatar' not found. Creating it."); - template.execute("create table system_avatar (" + - "id identity," + - "name varchar," + - "created_date datetime not null," + - "mime_type varchar not null," + - "width int not null," + - "height int not null," + - "data binary not null)"); - LOG.info("Database table 'system_avatar' was created successfully."); - } - - for (String avatar : AVATARS) { - createAvatar(template, avatar); - } - - if (!tableExists(template, "custom_avatar")) { - LOG.info("Database table 'custom_avatar' not found. Creating it."); - template.execute("create table custom_avatar (" + - "id identity," + - "name varchar," + - "created_date datetime not null," + - "mime_type varchar not null," + - "width int not null," + - "height int not null," + - "data binary not null," + - "username varchar not null," + - "foreign key (username) references user(username) on delete cascade)"); - LOG.info("Database table 'custom_avatar' was created successfully."); - } - - if (!columnExists(template, "avatar_scheme", "user_settings")) { - LOG.info("Database column 'user_settings.avatar_scheme' not found. Creating it."); - template.execute("alter table user_settings add avatar_scheme varchar default 'NONE' not null"); - LOG.info("Database column 'user_settings.avatar_scheme' was added successfully."); - } - - if (!columnExists(template, "system_avatar_id", "user_settings")) { - LOG.info("Database column 'user_settings.system_avatar_id' not found. Creating it."); - template.execute("alter table user_settings add system_avatar_id int"); - template.execute("alter table user_settings add foreign key (system_avatar_id) references system_avatar(id)"); - LOG.info("Database column 'user_settings.system_avatar_id' was added successfully."); - } - - if (!columnExists(template, "jukebox", "player")) { - LOG.info("Database column 'player.jukebox' not found. Creating it."); - template.execute("alter table player add jukebox boolean default false not null"); - LOG.info("Database column 'player.jukebox' was added successfully."); - } - } - - private void createAvatar(JdbcTemplate template, String avatar) { - if (template.queryForObject("select count(*) from system_avatar where name = ?", new Object[]{avatar},Integer.class) == 0) { - - InputStream in = null; - try { - in = getClass().getResourceAsStream("/org/libresonic/player/dao/schema/" + avatar + ".png"); - byte[] imageData = IOUtils.toByteArray(in); - template.update("insert into system_avatar values (null, ?, ?, ?, ?, ?, ?)", - new Object[]{avatar, new Date(), "image/png", 48, 48, imageData}); - LOG.info("Created avatar '" + avatar + "'."); - } catch (IOException x) { - LOG.error("Failed to create avatar '" + avatar + "'.", x); - } finally { - IOUtils.closeQuietly(in); - } - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema36.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema36.java deleted file mode 100644 index 03c71a7b..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema36.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implementes the database schema for Libresonic version 3.6. - * - * @author Sindre Mehus - */ -public class Schema36 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema36.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 12",Integer.class) == 0) { - LOG.info("Updating database schema to version 12."); - template.execute("insert into version values (12)"); - } - - if (!columnExists(template, "technology", "player")) { - LOG.info("Database column 'player.technology' not found. Creating it."); - template.execute("alter table player add technology varchar default 'WEB' not null"); - LOG.info("Database column 'player.technology' was added successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema37.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema37.java deleted file mode 100644 index 7d29d7d6..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema37.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 3.7. - * - * @author Sindre Mehus - */ -public class Schema37 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema37.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 13",Integer.class) == 0) { - LOG.info("Updating database schema to version 13."); - template.execute("insert into version values (13)"); - } - - if (template.queryForObject("select count(*) from role where id = 9",Integer.class) == 0) { - LOG.info("Role 'settings' not found in database. Creating it."); - template.execute("insert into role values (9, 'settings')"); - template.execute("insert into user_role select distinct u.username, 9 from user u"); - LOG.info("Role 'settings' was created successfully."); - } - - if (template.queryForObject("select count(*) from role where id = 10",Integer.class) == 0) { - LOG.info("Role 'jukebox' not found in database. Creating it."); - template.execute("insert into role values (10, 'jukebox')"); - template.execute("insert into user_role " + - "select distinct u.username, 10 from user u, user_role ur " + - "where u.username = ur.username and ur.role_id = 1"); - LOG.info("Role 'jukebox' was created successfully."); - } - - if (!columnExists(template, "changed", "music_folder")) { - LOG.info("Database column 'music_folder.changed' not found. Creating it."); - template.execute("alter table music_folder add changed datetime default 0 not null"); - LOG.info("Database column 'music_folder.changed' was added successfully."); - } - - if (!columnExists(template, "changed", "internet_radio")) { - LOG.info("Database column 'internet_radio.changed' not found. Creating it."); - template.execute("alter table internet_radio add changed datetime default 0 not null"); - LOG.info("Database column 'internet_radio.changed' was added successfully."); - } - - if (!columnExists(template, "changed", "user_settings")) { - LOG.info("Database column 'user_settings.changed' not found. Creating it."); - template.execute("alter table user_settings add changed datetime default 0 not null"); - LOG.info("Database column 'user_settings.changed' was added successfully."); - } - - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema38.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema38.java deleted file mode 100644 index a3fdd4d6..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema38.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 3.8. - * - * @author Sindre Mehus - */ -public class Schema38 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema38.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 14",Integer.class) == 0) { - LOG.info("Updating database schema to version 14."); - template.execute("insert into version values (14)"); - } - - if (!columnExists(template, "client_id", "player")) { - LOG.info("Database column 'player.client_id' not found. Creating it."); - template.execute("alter table player add client_id varchar"); - LOG.info("Database column 'player.client_id' was added successfully."); - } - - if (!columnExists(template, "show_chat", "user_settings")) { - LOG.info("Database column 'user_settings.show_chat' not found. Creating it."); - template.execute("alter table user_settings add show_chat boolean default true not null"); - LOG.info("Database column 'user_settings.show_chat' was added successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema40.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema40.java deleted file mode 100644 index 4beaa679..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema40.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 4.0. - * - * @author Sindre Mehus - */ -public class Schema40 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema40.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 15",Integer.class) == 0) { - LOG.info("Updating database schema to version 15."); - template.execute("insert into version values (15)"); - - // Reset stream byte count since they have been wrong in earlier releases. - template.execute("update user set bytes_streamed = 0"); - LOG.info("Reset stream byte count statistics."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema43.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema43.java deleted file mode 100644 index a0422784..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema43.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import java.util.Arrays; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 4.3. - * - * @author Sindre Mehus - */ -public class Schema43 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema43.class); - - @Override - public void execute(JdbcTemplate template) { - - // version 16 was used for 4.3.beta1 - if (template.queryForObject("select count(*) from version where version = 16",Integer.class) == 0) { - LOG.info("Updating database schema to version 16."); - template.execute("insert into version values (16)"); - } - - if (template.queryForObject("select count(*) from version where version = 17",Integer.class) == 0) { - LOG.info("Updating database schema to version 17."); - template.execute("insert into version values (17)"); - - for (String format : Arrays.asList("avi", "mpg", "mpeg", "mp4", "m4v", "mkv", "mov", "wmv", "ogv")) { - template.update("delete from transcoding where source_format=? and target_format=?", new Object[] {format, "flv"}); - template.execute("insert into transcoding values(null,'" + format + " > flv' ,'" + format + "' ,'flv','ffmpeg -ss %o -i %s -async 1 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -',null,null,true,true)"); - template.execute("insert into player_transcoding select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = '" + format + " > flv'"); - } - LOG.info("Created video transcoding configuration."); - } - - if (!columnExists(template, "email", "user")) { - LOG.info("Database column 'user.email' not found. Creating it."); - template.execute("alter table user add email varchar"); - LOG.info("Database column 'user.email' was added successfully."); - } - - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema45.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema45.java deleted file mode 100644 index e03568ce..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema45.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 4.5. - * - * @author Sindre Mehus - */ -public class Schema45 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema45.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 18",Integer.class) == 0) { - LOG.info("Updating database schema to version 18."); - template.execute("insert into version values (18)"); - } - - if (template.queryForObject("select count(*) from role where id = 11",Integer.class) == 0) { - LOG.info("Role 'share' not found in database. Creating it."); - template.execute("insert into role values (11, 'share')"); - template.execute("insert into user_role " + - "select distinct u.username, 11 from user u, user_role ur " + - "where u.username = ur.username and ur.role_id = 1"); - LOG.info("Role 'share' was created successfully."); - } - - if (!tableExists(template, "share")) { - LOG.info("Table 'share' not found in database. Creating it."); - template.execute("create cached table share (" + - "id identity," + - "name varchar not null," + - "description varchar," + - "username varchar not null," + - "created datetime not null," + - "expires datetime," + - "last_visited datetime," + - "visit_count int default 0 not null," + - "unique (name)," + - "foreign key (username) references user(username) on delete cascade)"); - template.execute("create index idx_share_name on share(name)"); - - LOG.info("Table 'share' was created successfully."); - LOG.info("Table 'share_file' not found in database. Creating it."); - template.execute("create cached table share_file (" + - "id identity," + - "share_id int not null," + - "path varchar not null," + - "foreign key (share_id) references share(id) on delete cascade)"); - LOG.info("Table 'share_file' was created successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema46.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema46.java deleted file mode 100644 index 814467e5..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema46.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 4.6. - * - * @author Sindre Mehus - */ -public class Schema46 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema46.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 19",Integer.class) == 0) { - LOG.info("Updating database schema to version 19."); - template.execute("insert into version values (19)"); - } - - if (!tableExists(template, "transcoding2")) { - LOG.info("Database table 'transcoding2' not found. Creating it."); - template.execute("create table transcoding2 (" + - "id identity," + - "name varchar not null," + - "source_formats varchar not null," + - "target_format varchar not null," + - "step1 varchar not null," + - "step2 varchar," + - "step3 varchar)"); - - template.execute("insert into transcoding2(name, source_formats, target_format, step1) values('mp3 audio'," + - "'ogg oga aac m4a flac wav wma aif aiff ape mpc shn', 'mp3', " + - "'ffmpeg -i %s -ab %bk -v 0 -f mp3 -')"); - - template.execute("insert into transcoding2(name, source_formats, target_format, step1) values('flv/h264 video', " + - "'avi mpg mpeg mp4 m4v mkv mov wmv ogv divx m2ts', 'flv', " + - "'ffmpeg -ss %o -i %s -async 1 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f flv -vcodec libx264 -preset superfast -threads 0 -')"); - - LOG.info("Database table 'transcoding2' was created successfully."); - } - - if (!tableExists(template, "player_transcoding2")) { - LOG.info("Database table 'player_transcoding2' not found. Creating it."); - template.execute("create table player_transcoding2 (" + - "player_id int not null," + - "transcoding_id int not null," + - "primary key (player_id, transcoding_id)," + - "foreign key (player_id) references player(id) on delete cascade," + - "foreign key (transcoding_id) references transcoding2(id) on delete cascade)"); - - template.execute("insert into player_transcoding2(player_id, transcoding_id) " + - "select distinct p.id, t.id from player p, transcoding2 t"); - - LOG.info("Database table 'player_transcoding2' was created successfully."); - } - - if (!columnExists(template, "default_active", "transcoding2")) { - LOG.info("Database column 'transcoding2.default_active' not found. Creating it."); - template.execute("alter table transcoding2 add default_active boolean default true not null"); - LOG.info("Database column 'transcoding2.default_active' was added successfully."); - } - } - -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema47.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema47.java deleted file mode 100644 index cb23d28b..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema47.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -import org.springframework.jdbc.core.JdbcTemplate; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 4.7. - * - * @author Sindre Mehus - */ -public class Schema47 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema47.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 20",Integer.class) == 0) { - LOG.info("Updating database schema to version 20."); - template.execute("insert into version values (20)"); - } - - if (!tableExists(template, "media_file")) { - LOG.info("Database table 'media_file' not found. Creating it."); - template.execute("create cached table media_file (" + - "id identity," + - "path varchar not null," + - "folder varchar," + - "type varchar not null," + - "format varchar," + - "title varchar," + - "album varchar," + - "artist varchar," + - "album_artist varchar," + - "disc_number int," + - "track_number int," + - "year int," + - "genre varchar," + - "bit_rate int," + - "variable_bit_rate boolean not null," + - "duration_seconds int," + - "file_size bigint," + - "width int," + - "height int," + - "cover_art_path varchar," + - "parent_path varchar," + - "play_count int not null," + - "last_played datetime," + - "comment varchar," + - "created datetime not null," + - "changed datetime not null," + - "last_scanned datetime not null," + - "children_last_updated datetime not null," + - "present boolean not null," + - "version int not null," + - "unique (path))"); - - template.execute("create index idx_media_file_path on media_file(path)"); - template.execute("create index idx_media_file_parent_path on media_file(parent_path)"); - template.execute("create index idx_media_file_type on media_file(type)"); - template.execute("create index idx_media_file_album on media_file(album)"); - template.execute("create index idx_media_file_artist on media_file(artist)"); - template.execute("create index idx_media_file_album_artist on media_file(album_artist)"); - template.execute("create index idx_media_file_present on media_file(present)"); - template.execute("create index idx_media_file_genre on media_file(genre)"); - template.execute("create index idx_media_file_play_count on media_file(play_count)"); - template.execute("create index idx_media_file_created on media_file(created)"); - template.execute("create index idx_media_file_last_played on media_file(last_played)"); - - LOG.info("Database table 'media_file' was created successfully."); - } - - if (!tableExists(template, "artist")) { - LOG.info("Database table 'artist' not found. Creating it."); - template.execute("create cached table artist (" + - "id identity," + - "name varchar not null," + - "cover_art_path varchar," + - "album_count int default 0 not null," + - "last_scanned datetime not null," + - "present boolean not null," + - "unique (name))"); - - template.execute("create index idx_artist_name on artist(name)"); - template.execute("create index idx_artist_present on artist(present)"); - - LOG.info("Database table 'artist' was created successfully."); - } - - if (!tableExists(template, "album")) { - LOG.info("Database table 'album' not found. Creating it."); - template.execute("create cached table album (" + - "id identity," + - "path varchar not null," + - "name varchar not null," + - "artist varchar not null," + - "song_count int default 0 not null," + - "duration_seconds int default 0 not null," + - "cover_art_path varchar," + - "play_count int default 0 not null," + - "last_played datetime," + - "comment varchar," + - "created datetime not null," + - "last_scanned datetime not null," + - "present boolean not null," + - "unique (artist, name))"); - - template.execute("create index idx_album_artist_name on album(artist, name)"); - template.execute("create index idx_album_play_count on album(play_count)"); - template.execute("create index idx_album_last_played on album(last_played)"); - template.execute("create index idx_album_present on album(present)"); - - LOG.info("Database table 'album' was created successfully."); - } - - // Added in 4.7.beta3 - if (!rowExists(template, "table_name='ALBUM' and column_name='NAME' and ordinal_position=1", - "information_schema.system_indexinfo")) { - template.execute("create index idx_album_name on album(name)"); - } - - if (!tableExists(template, "starred_media_file")) { - LOG.info("Database table 'starred_media_file' not found. Creating it."); - template.execute("create table starred_media_file (" + - "id identity," + - "media_file_id int not null," + - "username varchar not null," + - "created datetime not null," + - "foreign key (media_file_id) references media_file(id) on delete cascade,"+ - "foreign key (username) references user(username) on delete cascade," + - "unique (media_file_id, username))"); - - template.execute("create index idx_starred_media_file_media_file_id on starred_media_file(media_file_id)"); - template.execute("create index idx_starred_media_file_username on starred_media_file(username)"); - - LOG.info("Database table 'starred_media_file' was created successfully."); - } - - if (!tableExists(template, "starred_album")) { - LOG.info("Database table 'starred_album' not found. Creating it."); - template.execute("create table starred_album (" + - "id identity," + - "album_id int not null," + - "username varchar not null," + - "created datetime not null," + - "foreign key (album_id) references album(id) on delete cascade," + - "foreign key (username) references user(username) on delete cascade," + - "unique (album_id, username))"); - - template.execute("create index idx_starred_album_album_id on starred_album(album_id)"); - template.execute("create index idx_starred_album_username on starred_album(username)"); - - LOG.info("Database table 'starred_album' was created successfully."); - } - - if (!tableExists(template, "starred_artist")) { - LOG.info("Database table 'starred_artist' not found. Creating it."); - template.execute("create table starred_artist (" + - "id identity," + - "artist_id int not null," + - "username varchar not null," + - "created datetime not null," + - "foreign key (artist_id) references artist(id) on delete cascade,"+ - "foreign key (username) references user(username) on delete cascade," + - "unique (artist_id, username))"); - - template.execute("create index idx_starred_artist_artist_id on starred_artist(artist_id)"); - template.execute("create index idx_starred_artist_username on starred_artist(username)"); - - LOG.info("Database table 'starred_artist' was created successfully."); - } - - if (!tableExists(template, "playlist")) { - LOG.info("Database table 'playlist' not found. Creating it."); - template.execute("create table playlist (" + - "id identity," + - "username varchar not null," + - "is_public boolean not null," + - "name varchar not null," + - "comment varchar," + - "file_count int default 0 not null," + - "duration_seconds int default 0 not null," + - "created datetime not null," + - "changed datetime not null," + - "foreign key (username) references user(username) on delete cascade)"); - - LOG.info("Database table 'playlist' was created successfully."); - } - - if (!columnExists(template, "imported_from", "playlist")) { - LOG.info("Database column 'playlist.imported_from' not found. Creating it."); - template.execute("alter table playlist add imported_from varchar"); - LOG.info("Database column 'playlist.imported_from' was added successfully."); - } - - if (!tableExists(template, "playlist_file")) { - LOG.info("Database table 'playlist_file' not found. Creating it."); - template.execute("create cached table playlist_file (" + - "id identity," + - "playlist_id int not null," + - "media_file_id int not null," + - "foreign key (playlist_id) references playlist(id) on delete cascade," + - "foreign key (media_file_id) references media_file(id) on delete cascade)"); - - LOG.info("Database table 'playlist_file' was created successfully."); - } - - if (!tableExists(template, "playlist_user")) { - LOG.info("Database table 'playlist_user' not found. Creating it."); - template.execute("create table playlist_user (" + - "id identity," + - "playlist_id int not null," + - "username varchar not null," + - "unique(playlist_id, username)," + - "foreign key (playlist_id) references playlist(id) on delete cascade," + - "foreign key (username) references user(username) on delete cascade)"); - - LOG.info("Database table 'playlist_user' was created successfully."); - } - - if (!tableExists(template, "bookmark")) { - LOG.info("Database table 'bookmark' not found. Creating it."); - template.execute("create table bookmark (" + - "id identity," + - "media_file_id int not null," + - "position_millis bigint not null," + - "username varchar not null," + - "comment varchar," + - "created datetime not null," + - "changed datetime not null," + - "foreign key (media_file_id) references media_file(id) on delete cascade,"+ - "foreign key (username) references user(username) on delete cascade," + - "unique (media_file_id, username))"); - - template.execute("create index idx_bookmark_media_file_id on bookmark(media_file_id)"); - template.execute("create index idx_bookmark_username on bookmark(username)"); - - LOG.info("Database table 'bookmark' was created successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema49.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema49.java deleted file mode 100644 index 59e7b447..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema49.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 4.9. - * - * @author Sindre Mehus - */ -public class Schema49 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema49.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 21",Integer.class) == 0) { - LOG.info("Updating database schema to version 21."); - template.execute("insert into version values (21)"); - } - - if (!columnExists(template, "year", "album")) { - LOG.info("Database column 'album.year' not found. Creating it."); - template.execute("alter table album add year int"); - LOG.info("Database column 'album.year' was added successfully."); - } - - if (!columnExists(template, "genre", "album")) { - LOG.info("Database column 'album.genre' not found. Creating it."); - template.execute("alter table album add genre varchar"); - LOG.info("Database column 'album.genre' was added successfully."); - } - - if (!tableExists(template, "genre")) { - LOG.info("Database table 'genre' not found. Creating it."); - template.execute("create table genre (" + - "name varchar not null," + - "song_count int not null)"); - - LOG.info("Database table 'genre' was created successfully."); - } - - if (!columnExists(template, "album_count", "genre")) { - LOG.info("Database column 'genre.album_count' not found. Creating it."); - template.execute("alter table genre add album_count int default 0 not null"); - LOG.info("Database column 'genre.album_count' was added successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema50.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema50.java deleted file mode 100644 index 6d3c9f52..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema50.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - This file is part of Libresonic. - - Libresonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Libresonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Libresonic. If not, see . - - Copyright 2016 (C) Libresonic Authors - Based upon Subsonic, Copyright 2009 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 5.0. - * - * @author Sindre Mehus - */ -public class Schema50 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema50.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 22",Integer.class) == 0) { - LOG.info("Updating database schema to version 22."); - template.execute("insert into version values (22)"); - - template.execute("insert into transcoding2(name, source_formats, target_format, step1, default_active) values('mkv video', " + - "'avi mpg mpeg mp4 m4v mkv mov wmv ogv divx m2ts', 'mkv', " + - "'ffmpeg -ss %o -i %s -c:v libx264 -preset superfast -b:v %bk -c:a libvorbis -f matroska -threads 0 -', 'true')"); - - template.execute("insert into player_transcoding2(player_id, transcoding_id) " + - "select distinct p.id, t.id from player p, transcoding2 t where t.name='mkv video'"); - LOG.info("Added mkv transcoding."); - } - - if (!columnExists(template, "song_notification", "user_settings")) { - LOG.info("Database column 'user_settings.song_notification' not found. Creating it."); - template.execute("alter table user_settings add song_notification boolean default true not null"); - LOG.info("Database column 'user_settings.song_notification' was added successfully."); - } - - // Added in 5.0.beta2 - if (template.queryForObject("select count(*) from version where version = 23",Integer.class) == 0) { - LOG.info("Updating database schema to version 23."); - template.execute("insert into version values (23)"); - template.execute("update transcoding2 set step1='ffmpeg -i %s -map 0:0 -b:a %bk -v 0 -f mp3 -' where name='mp3 audio'"); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema51.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema51.java deleted file mode 100644 index 4285d147..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema51.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of Libresonic. - * - * Libresonic is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Libresonic is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Libresonic. If not, see . - * - * Copyright 2014 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 5.1. - * - * @author Sindre Mehus - */ -public class Schema51 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema51.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 23",Integer.class) == 0) { - LOG.info("Updating database schema to version 23."); - template.execute("insert into version values (23)"); - } - - if (!columnExists(template, "show_artist_info", "user_settings")) { - LOG.info("Database column 'user_settings.show_artist_info' not found. Creating it."); - template.execute("alter table user_settings add show_artist_info boolean default true not null"); - LOG.info("Database column 'user_settings.show_artist_info' was added successfully."); - } - - if (!columnExists(template, "auto_hide_play_queue", "user_settings")) { - LOG.info("Database column 'user_settings.auto_hide_play_queue' not found. Creating it."); - template.execute("alter table user_settings add auto_hide_play_queue boolean default true not null"); - LOG.info("Database column 'user_settings.auto_hide_play_queue' was added successfully."); - } - - if (!columnExists(template, "view_as_list", "user_settings")) { - LOG.info("Database column 'user_settings.view_as_list' not found. Creating it."); - template.execute("alter table user_settings add view_as_list boolean default false not null"); - LOG.info("Database column 'user_settings.view_as_list' was added successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema52.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema52.java deleted file mode 100644 index a0c33dec..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema52.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of Libresonic. - * - * Libresonic is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Libresonic is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Libresonic. If not, see . - * - * Copyright 2015 (C) Sindre Mehus - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 5.2. - * - * @author Sindre Mehus - */ -public class Schema52 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema52.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 24",Integer.class) == 0) { - LOG.info("Updating database schema to version 24."); - template.execute("insert into version values (24)"); - } - - if (!tableExists(template, "music_folder_user")) { - LOG.info("Database table 'music_folder_user' not found. Creating it."); - template.execute("create table music_folder_user (" + - "music_folder_id int not null," + - "username varchar not null, " + - "foreign key (username) references user(username) on delete cascade, " + - "foreign key (music_folder_id) references music_folder(id) on delete cascade)"); - template.execute("create index idx_music_folder_user_username on music_folder_user(username)"); - template.execute("insert into music_folder_user select music_folder.id, user.username from music_folder, user"); - LOG.info("Database table 'music_folder_user' was created successfully."); - } - - if (!columnExists(template, "folder_id", "album")) { - LOG.info("Database column 'album.folder_id' not found. Creating it."); - template.execute("alter table album add folder_id int"); - LOG.info("Database column 'album.folder_id' was added successfully."); - } - - if (!tableExists(template, "play_queue")) { - LOG.info("Database table 'play_queue' not found. Creating it."); - template.execute("create table play_queue (" + - "id identity," + - "username varchar not null," + - "current int," + - "position_millis bigint," + - "changed datetime not null," + - "changed_by varchar not null," + - "foreign key (username) references user(username) on delete cascade)"); - LOG.info("Database table 'play_queue' was created successfully."); - } - - if (!tableExists(template, "play_queue_file")) { - LOG.info("Database table 'play_queue_file' not found. Creating it."); - template.execute("create cached table play_queue_file (" + - "id identity," + - "play_queue_id int not null," + - "media_file_id int not null," + - "foreign key (play_queue_id) references play_queue(id) on delete cascade," + - "foreign key (media_file_id) references media_file(id) on delete cascade)"); - - LOG.info("Database table 'play_queue_file' was created successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema53.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema53.java deleted file mode 100644 index caccee78..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema53.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of Libresonic. - * - * Libresonic is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Libresonic is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Libresonic. If not, see . - * - * Copyright 2015 (C) Sindre Mehus - */ - -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; -import org.libresonic.player.domain.AlbumListType; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 5.3. - * - * @author Sindre Mehus - */ -public class Schema53 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema53.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 25",Integer.class) == 0) { - LOG.info("Updating database schema to version 25."); - template.execute("insert into version values (25)"); - } - - if (!rowExists(template, "table_name='PODCAST_EPISODE' and column_name='URL' and ordinal_position=1", - "information_schema.system_indexinfo")) { - template.execute("create index idx_podcast_episode_url on podcast_episode(url)"); - LOG.info("Created index for podcast_episode.url"); - } - - if (!columnExists(template, "default_album_list", "user_settings")) { - LOG.info("Database column 'user_settings.default_album_list' not found. Creating it."); - template.execute("alter table user_settings add default_album_list varchar default '" + - AlbumListType.RANDOM.getId() + "' not null"); - LOG.info("Database column 'user_settings.default_album_list' was added successfully."); - } - - if (!columnExists(template, "queue_following_songs", "user_settings")) { - LOG.info("Database column 'user_settings.queue_following_songs' not found. Creating it."); - template.execute("alter table user_settings add queue_following_songs boolean default true not null"); - LOG.info("Database column 'user_settings.queue_following_songs' was added successfully."); - } - - if (!columnExists(template, "image_url", "podcast_channel")) { - LOG.info("Database column 'podcast_channel.image_url' not found. Creating it."); - template.execute("alter table podcast_channel add image_url varchar"); - LOG.info("Database column 'podcast_channel.image_url' was added successfully."); - } - - if (!columnExists(template, "show_side_bar", "user_settings")) { - LOG.info("Database column 'user_settings.show_side_bar' not found. Creating it."); - template.execute("alter table user_settings add show_side_bar boolean default true not null"); - LOG.info("Database column 'user_settings.show_side_bar' was added successfully."); - } - - if (!columnExists(template, "folder_id", "artist")) { - LOG.info("Database column 'artist.folder_id' not found. Creating it."); - template.execute("alter table artist add folder_id int"); - LOG.info("Database column 'artist.folder_id' was added successfully."); - } - } -} \ No newline at end of file diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema61.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema61.java deleted file mode 100644 index cf61876a..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema61.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of Libresonic. - * - * Libresonic is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Libresonic is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Libresonic. If not, see . - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 6.1. - * - * @author François-Xavier Thomas - */ -public class Schema61 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema61.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 26",Integer.class) == 0) { - LOG.info("Updating database schema to version 26."); - template.execute("insert into version values (26)"); - } - - if (!columnExists(template, "list_reload_delay", "user_settings")) { - LOG.info("Database column 'user_settings.list_reload_delay' not found. Creating it."); - template.execute("alter table user_settings add list_reload_delay int default 60 not null"); - LOG.info("Database column 'user_settings.list_reload_delay' was added successfully."); - } - - if (!columnExists(template, "keyboard_shortcuts_enabled", "user_settings")) { - LOG.info("Database column 'user_settings.keyboard_shortcuts_enabled' not found. Creating it."); - template.execute("alter table user_settings add keyboard_shortcuts_enabled boolean default false not null"); - LOG.info("Database column 'user_settings.keyboard_shortcuts_enabled' was added successfully."); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema62.java b/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema62.java deleted file mode 100644 index cdd233c2..00000000 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/schema/hsql/Schema62.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of Libresonic. - * - * Libresonic is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Libresonic is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Libresonic. If not, see . - */ -package org.libresonic.player.dao.schema.hsql; - -import org.springframework.jdbc.core.JdbcTemplate; - -import org.libresonic.player.Logger; -import org.libresonic.player.dao.schema.Schema; - -/** - * Used for creating and evolving the database schema. - * This class implements the database schema for Libresonic version 6.1. - * - * @author Shen-Ta Hsieh - */ -public class Schema62 extends Schema { - - private static final Logger LOG = Logger.getLogger(Schema62.class); - - @Override - public void execute(JdbcTemplate template) { - - if (template.queryForObject("select count(*) from version where version = 27",Integer.class) == 0) { - LOG.info("Updating database schema to version 27."); - template.execute("insert into version values (27)"); - } - - if (!columnExists(template, "m3u_bom_enabled", "player")) { - LOG.info("Database column 'player.m3u_bom_enabled' not found. Creating it."); - template.execute("alter table player add m3u_bom_enabled boolean default false not null"); - LOG.info("Database column 'player.m3u_bom_enabled' was added successfully."); - } - } -} diff --git a/libresonic-main/src/main/java/org/libresonic/player/spring/AdditionalPropertySourceConfigurer.java b/libresonic-main/src/main/java/org/libresonic/player/spring/AdditionalPropertySourceConfigurer.java index cb7ff9a6..fff66516 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/spring/AdditionalPropertySourceConfigurer.java +++ b/libresonic-main/src/main/java/org/libresonic/player/spring/AdditionalPropertySourceConfigurer.java @@ -14,7 +14,9 @@ public class AdditionalPropertySourceConfigurer implements ApacheCommonsConfigurationService configurationService = new ApacheCommonsConfigurationService(); ImmutableConfiguration snapshot = configurationService.getImmutableSnapshot(); - PropertySource ps = new CommonsConfigurationPropertySource("libresonic-pre-init-configs", snapshot); + PropertySource ps = new DatasourceProfileActivatorPropertySource(new CommonsConfigurationPropertySource( + "libresonic-pre-init-configs", + snapshot)); ctx.getEnvironment().getPropertySources().addLast(ps); } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/spring/DataSourceConfigType.java b/libresonic-main/src/main/java/org/libresonic/player/spring/DataSourceConfigType.java new file mode 100644 index 00000000..623259e3 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/spring/DataSourceConfigType.java @@ -0,0 +1,7 @@ +package org.libresonic.player.spring; + +public enum DataSourceConfigType { + JNDI, + EMBED, + LEGACY +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/spring/DatasourceProfileActivatorPropertySource.java b/libresonic-main/src/main/java/org/libresonic/player/spring/DatasourceProfileActivatorPropertySource.java new file mode 100644 index 00000000..cbfff912 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/spring/DatasourceProfileActivatorPropertySource.java @@ -0,0 +1,40 @@ +package org.libresonic.player.spring; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.core.env.PropertySource; + +public class DatasourceProfileActivatorPropertySource extends PropertySource { + public static final String SPRING_PROFILES_ACTIVE = "spring.profiles.active"; + public static final String DATASOURCE_CONFIG_TYPE = "database.config.type"; + final PropertySource parent; + + public DatasourceProfileActivatorPropertySource(PropertySource parent) { + super(parent.getName()); + this.parent = parent; + } + + @Override + public Object getProperty(String name) { + if(StringUtils.equalsIgnoreCase(name, SPRING_PROFILES_ACTIVE)) { + String appendTo = ""; + Object existing = parent.getProperty(SPRING_PROFILES_ACTIVE); + if(existing != null && existing instanceof String) { + appendTo += (String) existing; + } + DataSourceConfigType dataSourceConfigType; + Object rawType = parent.getProperty(DATASOURCE_CONFIG_TYPE); + if(rawType != null && rawType instanceof String) { + dataSourceConfigType = DataSourceConfigType.valueOf(StringUtils.upperCase((String) rawType)); + } else { + dataSourceConfigType = DataSourceConfigType.LEGACY; + } + if(StringUtils.isNotBlank(appendTo)) { + appendTo += ","; + } + appendTo += StringUtils.lowerCase(dataSourceConfigType.name()); + return appendTo; + } else { + return parent.getProperty(name); + } + } +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/spring/HsqlDatabase.java b/libresonic-main/src/main/java/org/libresonic/player/spring/HsqlDatabase.java new file mode 100644 index 00000000..e169194d --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/spring/HsqlDatabase.java @@ -0,0 +1,19 @@ +package org.libresonic.player.spring; + +import liquibase.exception.DatabaseException; + +public class HsqlDatabase extends liquibase.database.core.HsqlDatabase { + + @Override + public boolean supportsSchemas() { + try { + if(getDatabaseMajorVersion() < 2) { + return false; + } else { + return super.supportsSchemas(); + } + } catch (DatabaseException e) { + return false; + } + } +} diff --git a/libresonic-main/src/main/java/org/libresonic/player/spring/SpringLiquibase.java b/libresonic-main/src/main/java/org/libresonic/player/spring/SpringLiquibase.java new file mode 100644 index 00000000..0ff200b4 --- /dev/null +++ b/libresonic-main/src/main/java/org/libresonic/player/spring/SpringLiquibase.java @@ -0,0 +1,74 @@ +package org.libresonic.player.spring; + +import liquibase.database.Database; +import liquibase.database.DatabaseConnection; +import liquibase.database.DatabaseFactory; +import liquibase.database.OfflineConnection; +import liquibase.database.jvm.JdbcConnection; +import liquibase.exception.DatabaseException; +import liquibase.exception.LiquibaseException; +import liquibase.resource.ResourceAccessor; +import liquibase.util.StringUtils; +import org.libresonic.player.Logger; + +import java.sql.Connection; +import java.util.Iterator; +import java.util.List; + +public class SpringLiquibase extends liquibase.integration.spring.SpringLiquibase { + private static final Logger logger = Logger.getLogger(SpringLiquibase.class); + + @Override + public void afterPropertiesSet() throws LiquibaseException { + try { + super.afterPropertiesSet(); + } catch(Exception e) { + logger.error("==============================================="); + logger.error("An exception occurred during database migration"); + logger.error("A rollback file has been generated at " + rollbackFile); + logger.error("Execute it within your database to rollback any changes"); + logger.error("The exception is as follows\n", e); + logger.error("==============================================="); + throw(e); + } + } + + @Override + protected Database createDatabase( + Connection c, ResourceAccessor resourceAccessor + ) throws DatabaseException { + DatabaseConnection liquibaseConnection; + if (c == null) { + log.warning("Null connection returned by liquibase datasource. Using offline unknown database"); + liquibaseConnection = new OfflineConnection("offline:unknown", resourceAccessor); + + } else { + liquibaseConnection = new JdbcConnection(c); + } + DatabaseFactory factory = DatabaseFactory.getInstance(); + overrideHsqlDbImplementation(factory); + Database database = factory.findCorrectDatabaseImplementation(liquibaseConnection); + if (StringUtils.trimToNull(this.defaultSchema) != null) { + database.setDefaultSchemaName(this.defaultSchema); + } + return database; + } + + private void overrideHsqlDbImplementation(DatabaseFactory factory) { + List implementedDatabases = factory.getImplementedDatabases(); + factory.clearRegistry(); + removeCurrentHsqlDb(implementedDatabases); + implementedDatabases.forEach(factory::register); + factory.register(new HsqlDatabase()); + } + + private void removeCurrentHsqlDb(List implementedDatabases) { + Iterator iterator = implementedDatabases.iterator(); + while(iterator.hasNext()) { + Database db = iterator.next(); + if(db instanceof liquibase.database.core.HsqlDatabase) { + iterator.remove(); + } + } + } +} diff --git a/libresonic-main/src/main/resources/liquibase/db-changelog.xml b/libresonic-main/src/main/resources/liquibase/db-changelog.xml new file mode 100644 index 00000000..717e118d --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/db-changelog.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/libresonic-main/src/main/resources/liquibase/legacy/legacy-changelog.xml b/libresonic-main/src/main/resources/liquibase/legacy/legacy-changelog.xml new file mode 100644 index 00000000..f7d2a28a --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/legacy-changelog.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema25.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema25.xml new file mode 100644 index 00000000..32d05582 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema25.xml @@ -0,0 +1,131 @@ + + + + + + + + set property "hsqldb.cache_file_scale" 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema26.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema26.xml new file mode 100644 index 00000000..8f9a7c6d --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema26.xml @@ -0,0 +1,163 @@ + + + + select count(*) from version where version = 2 + + + + + + + version = 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select count(*) from role where id = 6 + + + + + + + insert into user_role(username, role_id) + select distinct u.username, 6 from ${userTableQuote}user${userTableQuote} u, user_role ur + where u.username = ur.username and ur.role_id in (1, 5) + + + + role_id = 6 + + + id = 6 + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema27.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema27.xml new file mode 100644 index 00000000..39cbd87c --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema27.xml @@ -0,0 +1,37 @@ + + + + + select count(*) from version where version = 3 + + + + + + + version = 3 + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema28.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema28.xml new file mode 100644 index 00000000..0c9fb776 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema28.xml @@ -0,0 +1,232 @@ + + + + select count(*) from version where version = 4 + + + + + + + version = 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema29.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema29.xml new file mode 100644 index 00000000..c9789c3f --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema29.xml @@ -0,0 +1,44 @@ + + + + select count(*) from version where version = 5 + + + + + + + version = 5 + + + + + + + + + + + + + + + + + + + + + + + insert into user_rating select 'admin', path, rating from music_file_info + where rating is not null and rating > 0 + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema30.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema30.xml new file mode 100644 index 00000000..37dedba6 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema30.xml @@ -0,0 +1,44 @@ + + + + select count(*) from version where version = 6 + + + + + + + version = 6 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema31.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema31.xml new file mode 100644 index 00000000..3d415016 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema31.xml @@ -0,0 +1,42 @@ + + + + select count(*) from version where version = 7 + + + + + + + version = 7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema32.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema32.xml new file mode 100644 index 00000000..e96ab14d --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema32.xml @@ -0,0 +1,120 @@ + + + + select count(*) from version where version = 8 + + + + + + + version = 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select count(*) from role where id = 7 + + + + + + + insert into user_role(username, role_id) + select distinct u.username, 7 from ${userTableQuote}user${userTableQuote} u, user_role ur + where u.username = ur.username and ur.role_id = 1 + + + + role_id = 7 + + + id = 7 + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema33.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema33.xml new file mode 100644 index 00000000..d1119df2 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema33.xml @@ -0,0 +1,30 @@ + + + + select count(*) from version where version = 9 + + + + + + + version = 9 + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema34.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema34.xml new file mode 100644 index 00000000..85b7a3fd --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema34.xml @@ -0,0 +1,42 @@ + + + + select count(*) from version where version = 10 + + + + + + + version = 10 + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema35.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema35.xml new file mode 100644 index 00000000..19d5fc92 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema35.xml @@ -0,0 +1,945 @@ + + + + select count(*) from version where version = 11 + + + + + + + version = 11 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select count(*) from role where id = 8 + + + + + + + insert into user_role(username, role_id) select distinct u.username, 8 from ${userTableQuote}user${userTableQuote} u + + + + role_id = 8 + + + id = 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select count(*) from system_avatar where name = 'Formal' + + + + + + + + + + + name = 'Formal' + + + + + + select count(*) from system_avatar where name = 'Engineer' + + + + + + + + + + + name = 'Engineer' + + + + + + select count(*) from system_avatar where name = 'Footballer' + + + + + + + + + + + name = 'Footballer' + + + + + + select count(*) from system_avatar where name = 'Green-Boy' + + + + + + + + + + + name = 'Green-Boy' + + + + + + select count(*) from system_avatar where name = 'Linux-Zealot' + + + + + + + + + + + name = 'Linux-Zealot' + + + + + + select count(*) from system_avatar where name = 'Mac-Zealot' + + + + + + + + + + + name = 'Mac-Zealot' + + + + + + select count(*) from system_avatar where name = 'Windows-Zealot' + + + + + + + + + + + name = 'Windows-Zealot' + + + + + + select count(*) from system_avatar where name = 'Army-Officer' + + + + + + + + + + + name = 'Army-Officer' + + + + + + select count(*) from system_avatar where name = 'Beatnik' + + + + + + + + + + + name = 'Beatnik' + + + + + + select count(*) from system_avatar where name = 'All-Caps' + + + + + + + + + + + name = 'All-Caps' + + + + + + select count(*) from system_avatar where name = 'Clown' + + + + + + + + + + + name = 'Clown' + + + + + + select count(*) from system_avatar where name = 'Commie-Pinko' + + + + + + + + + + + name = 'Commie-Pinko' + + + + + + select count(*) from system_avatar where name = 'Forum-Flirt' + + + + + + + + + + + name = 'Forum-Flirt' + + + + + + select count(*) from system_avatar where name = 'Gamer' + + + + + + + + + + + name = 'Gamer' + + + + + + select count(*) from system_avatar where name = 'Hopelessly-Addicted' + + + + + + + + + + + name = 'Hopelessly-Addicted' + + + + + + select count(*) from system_avatar where name = 'Jekyll-And-Hyde' + + + + + + + + + + + name = 'Jekyll-And-Hyde' + + + + + + select count(*) from system_avatar where name = 'Joker' + + + + + + + + + + + name = 'Joker' + + + + + + select count(*) from system_avatar where name = 'Lurker' + + + + + + + + + + + name = 'Lurker' + + + + + + select count(*) from system_avatar where name = 'Moderator' + + + + + + + + + + + name = 'Moderator' + + + + + + select count(*) from system_avatar where name = 'Newbie' + + + + + + + + + + + name = 'Newbie' + + + + + + select count(*) from system_avatar where name = 'No-Dissent' + + + + + + + + + + + name = 'No-Dissent' + + + + + + select count(*) from system_avatar where name = 'Performer' + + + + + + + + + + + name = 'Performer' + + + + + + select count(*) from system_avatar where name = 'Push-My-Button' + + + + + + + + + + + name = 'Push-My-Button' + + + + + + select count(*) from system_avatar where name = 'Ray-Of-Sunshine' + + + + + + + + + + + name = 'Ray-Of-Sunshine' + + + + + + select count(*) from system_avatar where name = 'Red-Hot-Chili-Peppers-1' + + + + + + + + + + + name = 'Red-Hot-Chili-Peppers-1' + + + + + + select count(*) from system_avatar where name = 'Red-Hot-Chili-Peppers-2' + + + + + + + + + + + name = 'Red-Hot-Chili-Peppers-2' + + + + + + select count(*) from system_avatar where name = 'Red-Hot-Chili-Peppers-3' + + + + + + + + + + + name = 'Red-Hot-Chili-Peppers-3' + + + + + + select count(*) from system_avatar where name = 'Red-Hot-Chili-Peppers-4' + + + + + + + + + + + name = 'Red-Hot-Chili-Peppers-4' + + + + + + select count(*) from system_avatar where name = 'Ringmaster' + + + + + + + + + + + name = 'Ringmaster' + + + + + + select count(*) from system_avatar where name = 'Rumor-Junkie' + + + + + + + + + + + name = 'Rumor-Junkie' + + + + + + select count(*) from system_avatar where name = 'Sozzled-Surfer' + + + + + + + + + + + name = 'Sozzled-Surfer' + + + + + + select count(*) from system_avatar where name = 'Statistician' + + + + + + + + + + + name = 'Statistician' + + + + + + select count(*) from system_avatar where name = 'Tech-Support' + + + + + + + + + + + name = 'Tech-Support' + + + + + + select count(*) from system_avatar where name = 'The-Guru' + + + + + + + + + + + name = 'The-Guru' + + + + + + select count(*) from system_avatar where name = 'The-Referee' + + + + + + + + + + + name = 'The-Referee' + + + + + + select count(*) from system_avatar where name = 'Troll' + + + + + + + + + + + name = 'Troll' + + + + + + select count(*) from system_avatar where name = 'Uptight' + + + + + + + + + + + name = 'Uptight' + + + + + + select count(*) from system_avatar where name = 'Fire-Guitar' + + + + + + + + + + + name = 'Fire-Guitar' + + + + + + select count(*) from system_avatar where name = 'Drum' + + + + + + + + + + + name = 'Drum' + + + + + + select count(*) from system_avatar where name = 'Headphones' + + + + + + + + + + + name = 'Headphones' + + + + + + select count(*) from system_avatar where name = 'Mic' + + + + + + + + + + + name = 'Mic' + + + + + + select count(*) from system_avatar where name = 'Turntable' + + + + + + + + + + + name = 'Turntable' + + + + + + select count(*) from system_avatar where name = 'Vinyl' + + + + + + + + + + + name = 'Vinyl' + + + + + + select count(*) from system_avatar where name = 'Cool' + + + + + + + + + + + name = 'Cool' + + + + + + select count(*) from system_avatar where name = 'Laugh' + + + + + + + + + + + name = 'Laugh' + + + + + + select count(*) from system_avatar where name = 'Study' + + + + + + + + + + + name = 'Study' + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema36.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema36.xml new file mode 100644 index 00000000..813405cd --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema36.xml @@ -0,0 +1,30 @@ + + + + select count(*) from version where version = 12 + + + + + + + version = 12 + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema37.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema37.xml new file mode 100644 index 00000000..66791bd0 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema37.xml @@ -0,0 +1,81 @@ + + + + + select count(*) from version where version = 13 + + + + + + + version = 13 + + + + + + select count(*) from role where id = 9 + + + + + + + insert into user_role(username, role_id) select distinct u.username, 9 from ${userTableQuote}user${userTableQuote} u + + + + + + select count(*) from role where id = 10 + + + + + + + insert into user_role(username, role_id) select distinct u.username, 10 from ${userTableQuote}user${userTableQuote} u + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema38.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema38.xml new file mode 100644 index 00000000..1ab6c9ad --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema38.xml @@ -0,0 +1,40 @@ + + + + select count(*) from version where version = 14 + + + + + + + version = 14 + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema40.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema40.xml new file mode 100644 index 00000000..8a324603 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema40.xml @@ -0,0 +1,22 @@ + + + + select count(*) from version where version = 15 + + + + + + + + + + + version = 15 + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema43.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema43.xml new file mode 100644 index 00000000..eadf978a --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema43.xml @@ -0,0 +1,130 @@ + + + + select count(*) from version where version = 16 + + + + + + + version = 16 + + + + + + select count(*) from version where version = 17 + + + + + + target_format = 'flv' and source_format in ('avi', 'mpg', 'mpeg', 'mp4', 'm4v', 'mkv', 'mov', 'wmv', 'ogv') + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'avi > flv' + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mpg > flv' + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mpeg > flv' + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mp4 > flv' + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'm4v > flv' + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mkv > flv' + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mov > flv' + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'wmv > flv' + + + + + + + + + + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'ogv > flv' + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema45.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema45.xml new file mode 100644 index 00000000..ebfdbde6 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema45.xml @@ -0,0 +1,84 @@ + + + + select count(*) from version where version = 18 + + + + + + + version = 18 + + + + + + select count(*) from role where id = 11 + + + + + + + insert into user_role(username, role_id) + select distinct u.username, 11 from ${userTableQuote}user${userTableQuote} u, user_role ur + where u.username = ur.username and ur.role_id = 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + set table share type cached + + + + + + + + + + + + + + set table share_file type cached + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema46.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema46.xml new file mode 100644 index 00000000..fd009415 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema46.xml @@ -0,0 +1,94 @@ + + + + select count(*) from version where version = 19 + + + + + + + version = 19 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into player_transcoding2(player_id, transcoding_id) + select distinct p.id, t.id from player p, transcoding2 t + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema47.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema47.xml new file mode 100644 index 00000000..603c06ea --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema47.xml @@ -0,0 +1,450 @@ + + + + select count(*) from version where version = 20 + + + + + + + version = 20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + set table media_file type cached + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + set table artist type cached + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + set table album type cached + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + set table playlist_file type cached + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema49.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema49.xml new file mode 100644 index 00000000..b5dd5b22 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema49.xml @@ -0,0 +1,65 @@ + + + + select count(*) from version where version = 21 + + + + + + + version = 21 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema50.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema50.xml new file mode 100644 index 00000000..327f4764 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema50.xml @@ -0,0 +1,64 @@ + + + + select count(*) from version where version = 22 + + + + + + + + + + + + + insert into player_transcoding2(player_id, transcoding_id) + select distinct p.id, t.id from player p, transcoding2 t where t.name='mkv video' + + + + version = 22 + + + transcoding_id in (select id from transcoding_2 where name = 'mkv video') + + + name = 'mkv video' + + + + + + + + + + + + + + + + + + select count(*) from version where version = 23 + + + + + + + name='mp3 audio' + + + + version = 23 + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema51.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema51.xml new file mode 100644 index 00000000..0d644555 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema51.xml @@ -0,0 +1,54 @@ + + + + select count(*) from version where version = 23 + + + + + + + version = 23 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema52.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema52.xml new file mode 100644 index 00000000..13652962 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema52.xml @@ -0,0 +1,96 @@ + + + + select count(*) from version where version = 24 + + + + + + + version = 24 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + set table play_queue_file type cached + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema53.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema53.xml new file mode 100644 index 00000000..1a9f1a23 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema53.xml @@ -0,0 +1,84 @@ + + + + select count(*) from version where version = 25 + + + + + + + version = 25 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema61.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema61.xml new file mode 100644 index 00000000..85fe2513 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema61.xml @@ -0,0 +1,42 @@ + + + + select count(*) from version where version = 26 + + + + + + + version = 26 + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema62.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema62.xml new file mode 100644 index 00000000..e6d23fc4 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema62.xml @@ -0,0 +1,30 @@ + + + + select count(*) from version where version = 27 + + + + + + + version = 27 + + + + + + + + + + + + + + + + diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-embed.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-embed.xml new file mode 100644 index 00000000..5ee2f378 --- /dev/null +++ b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-embed.xml @@ -0,0 +1,17 @@ + + + + + + + + + + \ No newline at end of file diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-jndi.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-jndi.xml new file mode 100644 index 00000000..19e08839 --- /dev/null +++ b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-jndi.xml @@ -0,0 +1,12 @@ + + + + \ No newline at end of file diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-legacy.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-legacy.xml new file mode 100644 index 00000000..862a228b --- /dev/null +++ b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db-legacy.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db.xml new file mode 100644 index 00000000..c0e7ebf3 --- /dev/null +++ b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-db.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-service.xml b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-service.xml index 7eb2a74d..44f53be4 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/applicationContext-service.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/applicationContext-service.xml @@ -2,7 +2,12 @@ + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> + + + + @@ -44,6 +49,7 @@ + @@ -66,9 +72,6 @@ - - - diff --git a/libresonic-main/src/test/java/org/libresonic/player/dao/DaoTestCaseBase.java b/libresonic-main/src/test/java/org/libresonic/player/dao/DaoTestCaseBase.java index 57897cfd..9617d227 100644 --- a/libresonic-main/src/test/java/org/libresonic/player/dao/DaoTestCaseBase.java +++ b/libresonic-main/src/test/java/org/libresonic/player/dao/DaoTestCaseBase.java @@ -1,11 +1,21 @@ package org.libresonic.player.dao; +import javax.sql.DataSource; import junit.framework.TestCase; +import liquibase.exception.LiquibaseException; import org.libresonic.player.TestCaseUtils; +import org.libresonic.player.service.SettingsService; +import org.libresonic.player.spring.SpringLiquibase; import org.libresonic.player.util.FileUtil; +import org.libresonic.player.util.Util; +import org.springframework.core.io.DefaultResourceLoader; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.datasource.DriverManagerDataSource; import java.io.File; +import java.util.HashMap; +import java.util.Map; /** * Superclass for all DAO test cases. @@ -32,7 +42,10 @@ public abstract class DaoTestCaseBase extends TestCase { protected PodcastDao podcastDao; protected DaoTestCaseBase() { - daoHelper = new HsqlDaoHelper(); + DataSource dataSource = createDataSource(); + daoHelper = new GenericDaoHelper(new JdbcTemplate(dataSource), new NamedParameterJdbcTemplate(dataSource)); + + runDatabaseMigration(dataSource); playerDao = new PlayerDao(); internetRadioDao = new InternetRadioDao(); @@ -57,6 +70,34 @@ public abstract class DaoTestCaseBase extends TestCase { getJdbcTemplate().execute("shutdown"); } + private void runDatabaseMigration(DataSource dataSource) { + SpringLiquibase springLiquibase = new SpringLiquibase(); + springLiquibase.setDataSource(dataSource); + springLiquibase.setChangeLog("classpath:liquibase/db-changelog.xml"); + springLiquibase.setResourceLoader(new DefaultResourceLoader()); + Map parameters = new HashMap<>(); + parameters.put("defaultMusicFolder", Util.getDefaultMusicFolder()); + parameters.put("varcharLimit", "512"); + parameters.put("userTableQuote", ""); + springLiquibase.setChangeLogParameters(parameters); + try { + springLiquibase.afterPropertiesSet(); + } catch (LiquibaseException e) { + throw new RuntimeException(e); + } + } + + private DataSource createDataSource() { + File libresonicHome = SettingsService.getLibresonicHome(); + DriverManagerDataSource ds = new DriverManagerDataSource(); + ds.setDriverClassName("org.hsqldb.jdbcDriver"); + ds.setUrl("jdbc:hsqldb:file:" + libresonicHome.getPath() + "/db/libresonic"); + ds.setUsername("sa"); + ds.setPassword(""); + + return ds; + } + protected JdbcTemplate getJdbcTemplate() { return daoHelper.getJdbcTemplate(); } diff --git a/libresonic-main/src/test/java/org/libresonic/player/service/SettingsServiceTestCase.java b/libresonic-main/src/test/java/org/libresonic/player/service/SettingsServiceTestCase.java index c5072890..dec43c4f 100644 --- a/libresonic-main/src/test/java/org/libresonic/player/service/SettingsServiceTestCase.java +++ b/libresonic-main/src/test/java/org/libresonic/player/service/SettingsServiceTestCase.java @@ -41,7 +41,13 @@ public class SettingsServiceTestCase extends TestCase { String libresonicHome = TestCaseUtils.libresonicHomePathForTest(); System.setProperty("libresonic.home", libresonicHome); new File(libresonicHome, "libresonic.properties").delete(); - settingsService = new SettingsService(); + settingsService = newSettingsService(); + } + + private SettingsService newSettingsService() { + SettingsService settingsService = new SettingsService(); + settingsService.setConfigurationService(new ApacheCommonsConfigurationService()); + return settingsService; } public void testLibresonicHome() { @@ -97,7 +103,7 @@ public class SettingsServiceTestCase extends TestCase { settingsService.save(); verifySettings(settingsService); - verifySettings(new SettingsService()); + verifySettings(newSettingsService()); } private void verifySettings(SettingsService ss) { diff --git a/libresonic-main/src/test/resources/org/libresonic/player/service/mediaScannerServiceTestCase/applicationContext-service.xml b/libresonic-main/src/test/resources/org/libresonic/player/service/mediaScannerServiceTestCase/applicationContext-service.xml index 2d0b320f..1eaa2d61 100644 --- a/libresonic-main/src/test/resources/org/libresonic/player/service/mediaScannerServiceTestCase/applicationContext-service.xml +++ b/libresonic-main/src/test/resources/org/libresonic/player/service/mediaScannerServiceTestCase/applicationContext-service.xml @@ -1,8 +1,8 @@ - + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> @@ -67,8 +67,45 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -87,12 +124,15 @@ + + +