db cleanup
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -3,6 +3,7 @@
|
||||
|
||||
"cSpell.words": [
|
||||
"appsettings",
|
||||
"Cratie",
|
||||
"Newtonsoft",
|
||||
"Npgsql",
|
||||
"Yavsc"
|
||||
|
3445
src/Yavsc.Server/Migrations/20250715144838_dbCleanup.Designer.cs
generated
Normal file
3445
src/Yavsc.Server/Migrations/20250715144838_dbCleanup.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
117
src/Yavsc.Server/Migrations/20250715144838_dbCleanup.cs
Normal file
117
src/Yavsc.Server/Migrations/20250715144838_dbCleanup.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Yavsc.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class dbCleanup : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_BankBook_BankStatus_BalanceId",
|
||||
table: "BankBook");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "OAuth2Tokens");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "RefreshTokens");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_BankBook",
|
||||
table: "BankBook");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "BankBook",
|
||||
newName: "BalanceImpact");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_BankBook_BalanceId",
|
||||
table: "BalanceImpact",
|
||||
newName: "IX_BalanceImpact_BalanceId");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_BalanceImpact",
|
||||
table: "BalanceImpact",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_BalanceImpact_BankStatus_BalanceId",
|
||||
table: "BalanceImpact",
|
||||
column: "BalanceId",
|
||||
principalTable: "BankStatus",
|
||||
principalColumn: "UserId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_BalanceImpact_BankStatus_BalanceId",
|
||||
table: "BalanceImpact");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_BalanceImpact",
|
||||
table: "BalanceImpact");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "BalanceImpact",
|
||||
newName: "BankBook");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_BalanceImpact_BalanceId",
|
||||
table: "BankBook",
|
||||
newName: "IX_BankBook_BalanceId");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_BankBook",
|
||||
table: "BankBook",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "OAuth2Tokens",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<string>(type: "text", nullable: false),
|
||||
AccessToken = table.Column<string>(type: "text", nullable: false),
|
||||
Expiration = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
ExpiresIn = table.Column<string>(type: "text", nullable: false),
|
||||
RefreshToken = table.Column<string>(type: "text", nullable: false),
|
||||
TokenType = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_OAuth2Tokens", x => x.UserId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "RefreshTokens",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<string>(type: "text", nullable: false),
|
||||
ClientId = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
ExpiresUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
IssuedUtc = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
ProtectedTicket = table.Column<string>(type: "text", nullable: false),
|
||||
Subject = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_RefreshTokens", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_BankBook_BankStatus_BalanceId",
|
||||
table: "BankBook",
|
||||
column: "BalanceId",
|
||||
principalTable: "BankStatus",
|
||||
principalColumn: "UserId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
@ -471,65 +471,6 @@ namespace Yavsc.Migrations
|
||||
b.ToTable("Applications");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yavsc.Models.Auth.OAuth2Tokens", b =>
|
||||
{
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("AccessToken")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Expiration")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ExpiresIn")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("RefreshToken")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("TokenType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("UserId");
|
||||
|
||||
b.ToTable("OAuth2Tokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yavsc.Models.Auth.RefreshToken", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ClientId")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.Property<DateTime>("ExpiresUtc")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime>("IssuedUtc")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("ProtectedTicket")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Subject")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("character varying(50)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("RefreshTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yavsc.Models.Auth.Scope", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
@ -571,7 +512,7 @@ namespace Yavsc.Migrations
|
||||
|
||||
b.HasIndex("BalanceId");
|
||||
|
||||
b.ToTable("BankBook");
|
||||
b.ToTable("BalanceImpact");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yavsc.Models.Bank.BankIdentity", b =>
|
||||
|
@ -66,7 +66,7 @@ namespace Yavsc.Models
|
||||
builder.Entity<HairTaintInstance>().HasKey(ti => new { ti.TaintId, ti.PrestationId });
|
||||
builder.Entity<HyperLink>().HasKey(l => new { l.HRef, l.Method });
|
||||
builder.Entity<Period>().HasKey(l => new { l.Start, l.End });
|
||||
builder.Entity<Models.Cratie.Option>().HasKey(o => new { o.Code, o.CodeScrutin });
|
||||
builder.Entity<Cratie.Option>().HasKey(o => new { o.Code, o.CodeScrutin });
|
||||
builder.Entity<Notification>().Property(n => n.icon).HasDefaultValue("exclam");
|
||||
builder.Entity<ChatRoomAccess>().HasKey(p => new { room = p.ChannelName, user = p.UserId });
|
||||
builder.Entity<InstrumentRating>().HasAlternateKey(i => new { Instrument = i.InstrumentId, owner = i.OwnerId });
|
||||
@ -89,7 +89,6 @@ namespace Yavsc.Models
|
||||
}
|
||||
public DbSet<Client> Applications { get; set; }
|
||||
|
||||
public DbSet<RefreshToken> RefreshTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Activities referenced on this site
|
||||
@ -130,14 +129,7 @@ namespace Yavsc.Models
|
||||
|
||||
public DbSet<Estimate> Estimates { get; set; }
|
||||
public DbSet<AccountBalance> BankStatus { get; set; }
|
||||
public DbSet<BalanceImpact> BankBook { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Google Calendar offline
|
||||
/// open auth tokens
|
||||
/// </summary>
|
||||
/// <returns>tokens</returns>
|
||||
public DbSet<OAuth2Tokens> OAuth2Tokens { get; set; }
|
||||
public DbSet<BalanceImpact> BalanceImpact { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// References all declared external NativeConfidential devices
|
||||
@ -211,7 +203,6 @@ namespace Yavsc.Models
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<int> SaveChangesAsync(string userId, CancellationToken ctoken = default(CancellationToken))
|
||||
{
|
||||
AddTimestamps(userId);
|
||||
|
@ -1,57 +0,0 @@
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Yavsc.Helpers.Auth
|
||||
{
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Auth;
|
||||
public static class ExternalAuthStoreHelper {
|
||||
|
||||
public static Task<OAuth2Tokens> GetTokensAsync(this ApplicationDbContext context, string externalUserId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(externalUserId))
|
||||
{
|
||||
throw new ArgumentException("externalUserId MUST have a value");
|
||||
}
|
||||
|
||||
var item = context.OAuth2Tokens.FirstOrDefault(x => x.UserId == externalUserId);
|
||||
// TODO Refresh token
|
||||
|
||||
return Task.FromResult(item);
|
||||
}
|
||||
|
||||
public static Task StoreTokenAsync(this ApplicationDbContext context, string externalUserId, JObject response, string accessToken,
|
||||
string tokenType, string refreshToken, string expiresIn
|
||||
)
|
||||
{
|
||||
if (string.IsNullOrEmpty(externalUserId))
|
||||
{
|
||||
throw new ArgumentException("googleUserId MUST have a value");
|
||||
}
|
||||
|
||||
var item = context.OAuth2Tokens.SingleOrDefaultAsync(x => x.UserId == externalUserId).Result;
|
||||
if (item == null)
|
||||
{
|
||||
context.OAuth2Tokens.Add(new OAuth2Tokens
|
||||
{
|
||||
TokenType = "Bearer",
|
||||
AccessToken = accessToken,
|
||||
RefreshToken = refreshToken,
|
||||
Expiration = DateTime.Now.AddSeconds(int.Parse(expiresIn)),
|
||||
UserId = externalUserId
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
item.AccessToken = accessToken;
|
||||
item.Expiration = DateTime.Now.AddMinutes(int.Parse(expiresIn));
|
||||
if (refreshToken != null)
|
||||
item.RefreshToken = refreshToken;
|
||||
context.OAuth2Tokens.Update(item);
|
||||
}
|
||||
context.SaveChanges(externalUserId);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user