From a1a18f77a50804e0127dfa4b0f5240c49c541184 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 2 Jul 2012 21:24:02 -0700 Subject: Initial Commit --- .../sourceforge/subsonic/dao/schema/Schema25.java | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 subsonic-main/src/main/java/net/sourceforge/subsonic/dao/schema/Schema25.java (limited to 'subsonic-main/src/main/java/net/sourceforge/subsonic/dao/schema/Schema25.java') diff --git a/subsonic-main/src/main/java/net/sourceforge/subsonic/dao/schema/Schema25.java b/subsonic-main/src/main/java/net/sourceforge/subsonic/dao/schema/Schema25.java new file mode 100644 index 00000000..33cc2525 --- /dev/null +++ b/subsonic-main/src/main/java/net/sourceforge/subsonic/dao/schema/Schema25.java @@ -0,0 +1,81 @@ +/* + This file is part of Subsonic. + + Subsonic 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. + + Subsonic 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 Subsonic. If not, see . + + Copyright 2009 (C) Sindre Mehus + */ +package net.sourceforge.subsonic.dao.schema; + +import org.springframework.jdbc.core.*; +import net.sourceforge.subsonic.*; + +/** + * Used for creating and evolving the database schema. + * This class implementes the database schema for Subsonic 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")) { + 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."); + } + } +} -- cgit v1.2.3