Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update datetime to datetime2 on TMDB Tables for MSSQL #1210

Merged
merged 4 commits into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion Shoko.Server/Databases/SQLServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Shoko.Server.Databases;
public class SQLServer : BaseDatabase<SqlConnection>
{
public override string Name { get; } = "SQLServer";
public override int RequiredVersion { get; } = 137;
public override int RequiredVersion { get; } = 138;

public override void BackupDatabase(string fullfilename)
{
Expand Down Expand Up @@ -794,6 +794,26 @@ public override bool HasVersionsTable()
new DatabaseCommand(137, 3, "ALTER TABLE TMDB_Show ADD HiddenEpisodeCount int NOT NULL DEFAULT 0;"),
new DatabaseCommand(137, 4, "ALTER TABLE TMDB_AlternateOrdering_Season ADD HiddenEpisodeCount int NOT NULL DEFAULT 0;"),
new DatabaseCommand(137, 5, "ALTER TABLE TMDB_AlternateOrdering ADD HiddenEpisodeCount int NOT NULL DEFAULT 0;"),
new DatabaseCommand(138, 1, "ALTER TABLE TMDB_Person ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 2, "ALTER TABLE TMDB_Person ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 3, "ALTER TABLE TMDB_Movie ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 4, "ALTER TABLE TMDB_Movie ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 5, "ALTER TABLE TMDB_Show ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 6, "ALTER TABLE TMDB_Show ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 7, "ALTER TABLE TMDB_Season ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 8, "ALTER TABLE TMDB_Season ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 9, "ALTER TABLE TMDB_Episode ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 10, "ALTER TABLE TMDB_Episode ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 11, "ALTER TABLE TMDB_AlternateOrdering ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 12, "ALTER TABLE TMDB_AlternateOrdering ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 13, "ALTER TABLE TMDB_AlternateOrdering_Season ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 14, "ALTER TABLE TMDB_AlternateOrdering_Season ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 15, "ALTER TABLE TMDB_AlternateOrdering_Episode ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 16, "ALTER TABLE TMDB_AlternateOrdering_Episode ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 17, "ALTER TABLE TMDB_Collection ALTER COLUMN CreatedAt datetime2;"),
new DatabaseCommand(138, 18, "ALTER TABLE TMDB_Collection ALTER COLUMN LastUpdatedAt datetime2;"),
new DatabaseCommand(138, 19, DropDefaultOnCreatorLastUpdatedAt),
new DatabaseCommand(138, 20, "ALTER TABLE AniDB_Creator ALTER COLUMN LastUpdatedAt datetime2;"),
};

private static void AlterImdbMovieIDType()
Expand Down Expand Up @@ -1026,6 +1046,11 @@ SELECT column_id FROM sys.columns
session.CreateSQLQuery(query).ExecuteUpdate();
trans.Commit();
}
private static Tuple<bool, string> DropDefaultOnCreatorLastUpdatedAt(object connection)
{
DropDefaultConstraint("AniDB_Creator", "LastUpdatedAt");
return Tuple.Create<bool, string>(true, null);
}

protected override Tuple<bool, string> ExecuteCommand(SqlConnection connection, string command)
{
Expand Down