Prevent problems migrating to SQLite

This commit is contained in:
GeorgH93 2020-05-02 01:33:53 +02:00
parent fb3c94d17d
commit d01f91edc9
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 17 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 GeorgH93
* Copyright (C) 2020 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -28,6 +28,7 @@
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.text.DateFormat;
@ -59,7 +60,11 @@ protected ToSQLMigration(@NotNull Minepacks plugin, @NotNull Database oldDb, @No
switch(dbType)
{
case "mysql": newDb = new MySQL(plugin, connectionProvider); break;
case "sqlite": newDb = new SQLite(plugin, connectionProvider); break;
case "sqlite":
final File dbFile = new File(SQLite.getDbFile(plugin));
if(dbFile.exists()) dbFile.renameTo(new File(SQLite.getDbFile(plugin) + ".old_" + System.currentTimeMillis()));
newDb = new SQLite(plugin, connectionProvider);
break;
default: newDb = null;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 GeorgH93
* Copyright (C) 2020 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -34,10 +34,15 @@
public class SQLite extends SQL
{
//TODO add cooldown sync table
public SQLite(@NotNull Minepacks plugin, @Nullable ConnectionProvider connectionProvider)
public static String getDbFile(final @NotNull Minepacks plugin)
{
super(plugin, (connectionProvider == null) ? new SQLiteConnectionProvider(plugin.getLogger(), plugin.getDescription().getName(), plugin.getDataFolder().getAbsolutePath() + File.separator + "backpack.db") : connectionProvider);
return plugin.getDataFolder().getAbsolutePath() + File.separator + "backpack.db";
}
//TODO add cooldown sync table
public SQLite(final @NotNull Minepacks plugin, final @Nullable ConnectionProvider connectionProvider)
{
super(plugin, (connectionProvider == null) ? new SQLiteConnectionProvider(plugin.getLogger(), plugin.getDescription().getName(), getDbFile(plugin)) : connectionProvider);
}
@Override

View File

@ -7,7 +7,7 @@
<packaging>pom</packaging>
<properties>
<revision>2.3.6</revision>
<revision>2.3.7-RC1</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>