aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-06 19:18:32 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-06 19:18:32 -0500
commita4f0bd664849652893dea35055a186eeab25b06b (patch)
tree8b30c2d0a754242265d94547bb2ef5d4d84f70e5 /src
parenteec45b7ddaa7fb33cc3831af4d4c849a5c39ca40 (diff)
downloadslskd-a4f0bd664849652893dea35055a186eeab25b06b.tar.gz
stub migration for batches table
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Data/Migrations/Z2026_05_06_AddBatchesTableMigration.cs107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/slskd/Core/Data/Migrations/Z2026_05_06_AddBatchesTableMigration.cs b/src/slskd/Core/Data/Migrations/Z2026_05_06_AddBatchesTableMigration.cs
new file mode 100644
index 00000000..89d718ef
--- /dev/null
+++ b/src/slskd/Core/Data/Migrations/Z2026_05_06_AddBatchesTableMigration.cs
@@ -0,0 +1,107 @@
+// <copyright file="Z2026_05_06_AddBatchesTableMigration.cs" company="JP Dillingham">
+// ▄▄▄▄ ▄▄▄▄ ▄▄▄▄
+// ▄▄▄▄▄▄█ █▄▄▄▄▄█ █▄▄▄▄▄█ █
+// █__ --█ █__ --█ ◄█ - █
+// █▄▄▄▄▄█▄▄█▄▄▄▄▄█▄▄█▄▄█▄▄▄▄▄█
+// ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━ ━ ━┉ ┉ ┉
+// │ Copyright (c) JP Dillingham.
+// │
+// │ This program is free software: you can redistribute it and/or modify
+// │ it under the terms of the GNU Affero General Public License as published
+// │ by the Free Software Foundation, version 3.
+// │
+// │ This program 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 Affero General Public License for more details.
+// │
+// │ You should have received a copy of the GNU Affero General Public License
+// │ along with this program. If not, see https://www.gnu.org/licenses/.
+// │
+// │ This program is distributed with Additional Terms pursuant to Section 7
+// │ of the AGPLv3. See the LICENSE file in the root directory of this
+// │ project for the complete terms and conditions.
+// │
+// │ https://slskd.org
+// │
+// ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ╌ ╌╌╌╌ ╌
+// │ SPDX-FileCopyrightText: JP Dillingham
+// │ SPDX-License-Identifier: AGPL-3.0-only
+// ╰───────────────────────────────────────────╶──── ─ ─── ─ ── ──┈ ┈
+// </copyright>
+
+namespace slskd.Migrations;
+
+using System;
+using Microsoft.Data.Sqlite;
+using Serilog;
+
+/// <summary>
+/// Creates the Batches table in the Transfers database.
+/// </summary>
+public class Z2026_05_06_AddBatchesTableMigration : IMigration
+{
+ public Z2026_05_06_AddBatchesTableMigration(ConnectionStringDictionary connectionStrings)
+ {
+ ConnectionString = connectionStrings[Database.Transfers];
+ }
+
+ private ILogger Log { get; } = Serilog.Log.ForContext<Z2026_04_30_DropTransferStartOffsetMigration>();
+ private string ConnectionString { get; }
+
+ public bool NeedsToBeApplied()
+ {
+ var schema = SchemaInspector.GetDatabaseSchema(ConnectionString);
+
+ if (schema.ContainsKey("Batches"))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public void Apply()
+ {
+ if (!NeedsToBeApplied())
+ {
+ Log.Information("> Migration {Name} is not necessary or has already been applied", nameof(Z2026_05_06_AddBatchesTableMigration));
+ return;
+ }
+
+ using var connection = new SqliteConnection(ConnectionString);
+ connection.Open();
+
+ using var transaction = connection.BeginTransaction();
+
+ try
+ {
+ void Exec(string sql)
+ {
+ using var command = new SqliteCommand(sql, connection, transaction);
+ command.ExecuteNonQuery();
+ }
+
+ Log.Information("> Creating the Batches table...");
+
+ Exec(@"
+ CREATE TABLE Batches (
+ Id TEXT NOT NULL,
+ SearchId TEXT,
+ Username TEXT,
+ Direction INTEGER NOT NULL,
+ CreatedAt TEXT NOT NULL,
+ Options TEXT,
+ CONSTRAINT PK_Batches PRIMARY KEY(Id)
+ );");
+
+ transaction.Commit();
+ Log.Information("> Done!");
+ }
+ catch (Exception)
+ {
+ transaction.Rollback();
+ throw;
+ }
+ }
+}