2020-04-02 18:27:55 +00:00
|
|
|
|
using Npgsql;
|
|
|
|
|
|
2021-10-18 23:14:46 +00:00
|
|
|
|
namespace BirthdayBot.Data;
|
|
|
|
|
|
2022-03-19 21:53:53 +00:00
|
|
|
|
[Obsolete(ObsoleteReason, error: false)]
|
2021-10-18 23:14:46 +00:00
|
|
|
|
internal static class Database {
|
2022-03-19 21:53:53 +00:00
|
|
|
|
public const string ObsoleteReason = "Will be removed in favor of EF6 stuff when text commands are removed";
|
|
|
|
|
|
2022-03-20 00:04:16 +00:00
|
|
|
|
public static string DBConnectionString { get; set; } = null!;
|
2021-10-18 23:14:46 +00:00
|
|
|
|
|
2020-04-02 18:27:55 +00:00
|
|
|
|
/// <summary>
|
2021-10-18 23:14:46 +00:00
|
|
|
|
/// Sets up and opens a database connection.
|
2020-04-02 18:27:55 +00:00
|
|
|
|
/// </summary>
|
2021-10-18 23:14:46 +00:00
|
|
|
|
public static async Task<NpgsqlConnection> OpenConnectionAsync() {
|
|
|
|
|
var db = new NpgsqlConnection(DBConnectionString);
|
|
|
|
|
await db.OpenAsync().ConfigureAwait(false);
|
|
|
|
|
return db;
|
|
|
|
|
}
|
2020-04-02 18:27:55 +00:00
|
|
|
|
|
2021-10-18 23:14:46 +00:00
|
|
|
|
public static async Task DoInitialDatabaseSetupAsync() {
|
|
|
|
|
using var db = await OpenConnectionAsync().ConfigureAwait(false);
|
2020-07-16 18:55:26 +00:00
|
|
|
|
|
2021-10-18 23:14:46 +00:00
|
|
|
|
// Refer to the methods being called for information on how the database is set up.
|
|
|
|
|
// Note: The order these are called is important. (Foreign reference constraints.)
|
|
|
|
|
await GuildConfiguration.DatabaseSetupAsync(db).ConfigureAwait(false);
|
|
|
|
|
await GuildUserConfiguration.DatabaseSetupAsync(db).ConfigureAwait(false);
|
2020-04-02 18:27:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|