2018-02-11 03:34:13 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Noikoio.RegexBot.Module.ModLogs
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains common constants and static methods used for accessing the log database.
|
|
|
|
|
/// </summary>
|
|
|
|
|
class Sql
|
|
|
|
|
{
|
|
|
|
|
public const string TableLog = "modlogs_entries";
|
|
|
|
|
public const string TableLogIncr = TableLog + "_id";
|
|
|
|
|
public const string TableMsgCache = "modlogs_msgcache";
|
|
|
|
|
|
|
|
|
|
static void CreateTables()
|
|
|
|
|
{
|
2018-02-17 08:46:26 +00:00
|
|
|
|
using (var db = RegexBot.Config.GetOpenDatabaseConnectionAsync().GetAwaiter().GetResult())
|
2018-02-11 03:34:13 +00:00
|
|
|
|
{
|
|
|
|
|
using (var c = db.CreateCommand())
|
|
|
|
|
{
|
|
|
|
|
c.CommandText = "CREATE TABLE IF NOT EXISTS " + TableLog + " ("
|
|
|
|
|
+ "id int primary key, "
|
|
|
|
|
+ "entry_ts timestamptz not null, "
|
|
|
|
|
+ "guild_id bigint not null, "
|
|
|
|
|
+ "target_id bigint not null, "
|
2018-02-17 08:46:26 +00:00
|
|
|
|
+ $"invoke_id bigint null references {EntityCache.SqlHelper.TableUser}.user_id, "
|
2018-02-11 03:34:13 +00:00
|
|
|
|
+ "target_channel_id bigint null, " // TODO channel cache reference?
|
|
|
|
|
+ "category text not null, "
|
|
|
|
|
+ "message text not null, "
|
2018-02-17 08:46:26 +00:00
|
|
|
|
+ $"FOREIGN KEY (target_id, guild_id) REFERENCES {EntityCache.SqlHelper.TableUser} (user_id, guild_id)";
|
2018-02-11 03:34:13 +00:00
|
|
|
|
c.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
using (var c = db.CreateCommand())
|
|
|
|
|
{
|
|
|
|
|
c.CommandText = $"CREATE SEQUENCE IF NOT EXISTS {TableLogIncr} "
|
|
|
|
|
+ $"START 100 MAXVALUE {int.MaxValue}";
|
|
|
|
|
c.ExecuteNonQuery();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Log entry manipulation
|
|
|
|
|
// what was I doing again
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|