Skip to content

Commit dc7a6ca

Browse files
authored
Updated size of token columns for new installs and upgrades. (#41)
* Updated size of token columns for new installs and upgrades. * Updated to field size of 5000 and used constant.
1 parent 89903f0 commit dc7a6ca

File tree

6 files changed

+65
-7
lines changed

6 files changed

+65
-7
lines changed

src/Umbraco.AuthorizedServices/Constants.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public static class TableNames
7474
public const string OAuth1Token = "umbracoAuthorizedServiceOAuth1Token";
7575
}
7676

77+
public const int TokenFieldSize = 5000;
78+
7779
public static class Migrations
7880
{
7981

@@ -88,6 +90,8 @@ public static class TargetStates
8890
public const string AddKeyTable = "authorizedServices-key-db";
8991

9092
public const string AddOAuth1TokenTable = "authorizedServices-oauth1_token-db";
93+
94+
public const string AlterTokenColumnLengths = "authorizedServices-alter-token-column-lengths-db";
9195
}
9296
}
9397
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Microsoft.Extensions.Logging;
2+
using Umbraco.Cms.Infrastructure.Migrations;
3+
using Umbraco.Cms.Infrastructure.Persistence;
4+
5+
namespace Umbraco.AuthorizedServices.Migrations;
6+
7+
public class AlterTokenColumnLengths : MigrationBase
8+
{
9+
public AlterTokenColumnLengths(IMigrationContext context) : base(context)
10+
{
11+
}
12+
13+
protected override void Migrate()
14+
{
15+
Logger.LogDebug($"Running migration {nameof(AlterTokenColumnLengths)}");
16+
17+
// SQLite doesn't support alter table but fortunately the fields are variable text length anyway.
18+
// So skip unless running on SQL Server.
19+
if (IsSqlite(Database.SqlContext))
20+
{
21+
Logger.LogDebug($"Skipping altering udi field column lengths in Authorized Services tables as running on SQLite.");
22+
return;
23+
}
24+
25+
Alter.Table(Constants.Database.TableNames.OAuth2Token)
26+
.AlterColumn("accessToken")
27+
.AsString(Constants.Database.TokenFieldSize)
28+
.NotNullable()
29+
.Do();
30+
31+
Alter.Table(Constants.Database.TableNames.OAuth2Token)
32+
.AlterColumn("refreshToken")
33+
.AsString(Constants.Database.TokenFieldSize)
34+
.NotNullable()
35+
.Do();
36+
37+
Alter.Table(Constants.Database.TableNames.OAuth1Token)
38+
.AlterColumn("oauthToken")
39+
.AsString(Constants.Database.TokenFieldSize)
40+
.NotNullable()
41+
.Do();
42+
43+
Alter.Table(Constants.Database.TableNames.OAuth1Token)
44+
.AlterColumn("oauthTokenSecret")
45+
.AsString(Constants.Database.TokenFieldSize)
46+
.NotNullable()
47+
.Do();
48+
}
49+
50+
private static bool IsSqlite(ISqlContext sqlContext) => Type.GetType("Umbraco.Cms.Persistence.Sqlite.Services.SqliteSyntaxProvider, Umbraco.Cms.Persistence.Sqlite") == sqlContext.SqlSyntax.GetType();
51+
}

src/Umbraco.AuthorizedServices/Migrations/AuthorizedServicesMigrationPlan.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ public AuthorizedServicesMigrationPlan()
1717
/// <inheritdoc />
1818
protected override void DefinePlan()
1919
{
20-
// 0.2
20+
// 0.2.0
2121
To<AddOAuth2TokenTable>(Constants.Database.Migrations.TargetStates.AddOAuth2TokenTable);
2222

23-
// 0.3
23+
// 0.3.0
2424
To<RenameOAuth2TokenTable>(Constants.Database.Migrations.TargetStates.RenameOAuth2TokenTable);
2525
To<AddKeyTable>(Constants.Database.Migrations.TargetStates.AddKeyTable);
2626
To<AddOAuth1TokenTable>(Constants.Database.Migrations.TargetStates.AddOAuth1TokenTable);
27+
28+
// 0.3.3
29+
To<AlterTokenColumnLengths>(Constants.Database.Migrations.TargetStates.AlterTokenColumnLengths);
2730
}
2831
}

src/Umbraco.AuthorizedServices/Persistence/Dtos/OAuth1TokenDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public class OAuth1TokenDto
1414
public string ServiceAlias { get; set; } = string.Empty;
1515

1616
[Column("oauthToken")]
17-
[Length(1000)]
17+
[Length(Constants.Database.TokenFieldSize)]
1818
public string OAuthToken { get; set; } = string.Empty;
1919

2020
[Column("oauthTokenSecret")]
21-
[Length(1000)]
21+
[Length(Constants.Database.TokenFieldSize)]
2222
public string OAuthTokenSecret { get; set; } = string.Empty;
2323
}

src/Umbraco.AuthorizedServices/Persistence/Dtos/OAuth2TokenDto.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public class OAuth2TokenDto
1515
public string ServiceAlias { get; set; } = string.Empty;
1616

1717
[Column("accessToken")]
18-
[Length(1000)]
18+
[Length(Constants.Database.TokenFieldSize)]
1919
public string AccessToken { get; set; } = string.Empty;
2020

2121
[Column("refreshToken")]
22-
[Length(1000)]
22+
[Length(Constants.Database.TokenFieldSize)]
2323
[NullSetting(NullSetting = NullSettings.Null)]
2424
public string? RefreshToken { get; set; }
2525

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"assemblyVersion": {
55
"precision": "build"
66
},

0 commit comments

Comments
 (0)