| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,16 +7,32 @@ | |||
| 7 | 7 | import java.nio.file.*; | |
| 8 | 8 | import java.util.HashMap; | |
| 9 | 9 | import java.util.Map; | |
| 10 | + import java.util.Objects; | ||
| 10 | 11 | ||
| 12 | + import lombok.extern.slf4j.Slf4j; | ||
| 11 | 13 | import net.discordjug.javabot.data.h2db.commands.MigrationsListSubcommand; | |
| 12 | 14 | ||
| 13 | 15 | /** | |
| 14 | 16 | * Utility class that handles SQL Migrations. | |
| 15 | 17 | */ | |
| 18 | + @Slf4j | ||
| 16 | 19 | public class MigrationUtils { | |
| 20 | + | ||
| 21 | + private static final Path migrationDirectory; | ||
| 17 | 22 | ||
| 18 | 23 | private MigrationUtils() { | |
| 19 | 24 | } | |
| 25 | + | ||
| 26 | + static { | ||
| 27 | + Path dir; | ||
| 28 | + try { | ||
| 29 | + dir = createMigrationsDirectory(); | ||
| 30 | + } catch (IOException | URISyntaxException e) { | ||
| 31 | + log.error("Cannot create database migration directory", e); | ||
| 32 | + dir = null; | ||
| 33 | + } | ||
| 34 | + migrationDirectory = dir; | ||
| 35 | + } | ||
| 20 | 36 | ||
| 21 | 37 | /** | |
| 22 | 38 | * Tries to get the Migrations Directories' Path. | |
@@ -26,6 +42,10 @@ private MigrationUtils() { | |||
| 26 | 42 | * @throws IOException If an error occurs. | |
| 27 | 43 | */ | |
| 28 | 44 | public static Path getMigrationsDirectory() throws URISyntaxException, IOException { | |
| 45 | + return Objects.requireNonNull(migrationDirectory); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + private static Path createMigrationsDirectory() throws IOException, URISyntaxException { | ||
| 29 | 49 | URL resource = MigrationsListSubcommand.class.getResource("/database/migrations/"); | |
| 30 | 50 | if (resource == null) throw new IOException("Missing resource /migrations/"); | |
| 31 | 51 | URI uri = resource.toURI(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,6 @@ public ExportTableSubcommand(ExecutorService asyncPool, SystemsConfig systemsCon | |||
| 52 | 52 | .addChoice("Message Cache", "MESSAGE_CACHE") | |
| 53 | 53 | .addChoice("Question of the Week Accounts", "QOTW_POINTS") | |
| 54 | 54 | .addChoice("Question of the Week Questions", "QOTW_QUESTION") | |
| 55 | - .addChoice("Reserved Help Channels", "RESERVED_HELP_CHANNELS") | ||
| 56 | 55 | .addChoice("Starboard", "STARBOARD") | |
| 57 | 56 | .addChoice("Warns", "WARN") | |
| 58 | 57 | .addChoice("User Preferences", "USER_PREFERENCES"), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,7 +93,6 @@ public void execute(@NotNull SlashCommandInteractionEvent event) { | |||
| 93 | 93 | return; | |
| 94 | 94 | } | |
| 95 | 95 | String sql = Files.readString(migrationFile); | |
| 96 | - migrationsDir.getFileSystem().close(); | ||
| 97 | 96 | String[] statements = sql.split("\\s*;\\s*"); | |
| 98 | 97 | if (statements.length == 0) { | |
| 99 | 98 | Responses.error(event, "The migration `" + migrationName + "` does not contain any statements. Please remove or edit it before running again.").queue(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments