using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace FutureMailAPI.Migrations { /// public partial class AddOAuthEntities : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "OAuthClients", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), ClientId = table.Column(type: "TEXT", nullable: false), ClientSecret = table.Column(type: "TEXT", nullable: false), Name = table.Column(type: "TEXT", nullable: false), RedirectUris = table.Column(type: "TEXT", nullable: false), Scopes = table.Column(type: "TEXT", nullable: false), IsActive = table.Column(type: "INTEGER", nullable: false), CreatedAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"), UpdatedAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP") }, constraints: table => { table.PrimaryKey("PK_OAuthClients", x => x.Id); }); migrationBuilder.CreateTable( name: "OAuthAccessTokens", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Token = table.Column(type: "TEXT", nullable: false), ClientId = table.Column(type: "INTEGER", nullable: false), UserId = table.Column(type: "INTEGER", nullable: false), Scopes = table.Column(type: "TEXT", nullable: false), IsRevoked = table.Column(type: "INTEGER", nullable: false), ExpiresAt = table.Column(type: "TEXT", nullable: false), CreatedAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP") }, constraints: table => { table.PrimaryKey("PK_OAuthAccessTokens", x => x.Id); table.ForeignKey( name: "FK_OAuthAccessTokens_OAuthClients_ClientId", column: x => x.ClientId, principalTable: "OAuthClients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_OAuthAccessTokens_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "OAuthAuthorizationCodes", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Code = table.Column(type: "TEXT", nullable: false), ClientId = table.Column(type: "INTEGER", nullable: false), UserId = table.Column(type: "INTEGER", nullable: false), RedirectUri = table.Column(type: "TEXT", nullable: false), Scopes = table.Column(type: "TEXT", nullable: false), IsUsed = table.Column(type: "INTEGER", nullable: false), ExpiresAt = table.Column(type: "TEXT", nullable: false), CreatedAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP") }, constraints: table => { table.PrimaryKey("PK_OAuthAuthorizationCodes", x => x.Id); table.ForeignKey( name: "FK_OAuthAuthorizationCodes_OAuthClients_ClientId", column: x => x.ClientId, principalTable: "OAuthClients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_OAuthAuthorizationCodes_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "OAuthRefreshTokens", columns: table => new { Id = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Token = table.Column(type: "TEXT", nullable: false), ClientId = table.Column(type: "INTEGER", nullable: false), UserId = table.Column(type: "INTEGER", nullable: false), IsUsed = table.Column(type: "INTEGER", nullable: false), ExpiresAt = table.Column(type: "TEXT", nullable: false), CreatedAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP") }, constraints: table => { table.PrimaryKey("PK_OAuthRefreshTokens", x => x.Id); table.ForeignKey( name: "FK_OAuthRefreshTokens_OAuthClients_ClientId", column: x => x.ClientId, principalTable: "OAuthClients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_OAuthRefreshTokens_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_OAuthAccessTokens_ClientId", table: "OAuthAccessTokens", column: "ClientId"); migrationBuilder.CreateIndex( name: "IX_OAuthAccessTokens_UserId", table: "OAuthAccessTokens", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_OAuthAuthorizationCodes_ClientId", table: "OAuthAuthorizationCodes", column: "ClientId"); migrationBuilder.CreateIndex( name: "IX_OAuthAuthorizationCodes_UserId", table: "OAuthAuthorizationCodes", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_OAuthClients_ClientId", table: "OAuthClients", column: "ClientId", unique: true); migrationBuilder.CreateIndex( name: "IX_OAuthRefreshTokens_ClientId", table: "OAuthRefreshTokens", column: "ClientId"); migrationBuilder.CreateIndex( name: "IX_OAuthRefreshTokens_UserId", table: "OAuthRefreshTokens", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "OAuthAccessTokens"); migrationBuilder.DropTable( name: "OAuthAuthorizationCodes"); migrationBuilder.DropTable( name: "OAuthRefreshTokens"); migrationBuilder.DropTable( name: "OAuthClients"); } } }