2019-05-24 06:17:02 +00:00
using System ;
2019-08-30 17:55:24 +09:00
using BTCPayServer.Data ;
using Microsoft.EntityFrameworkCore.Infrastructure ;
2019-05-24 06:17:02 +00:00
using Microsoft.EntityFrameworkCore.Migrations ;
namespace BTCPayServer.Migrations
{
2019-08-30 17:55:24 +09:00
[DbContext(typeof(ApplicationDbContext))]
[Migration("20190225091644_AddOpenIddict")]
2019-05-24 06:17:02 +00:00
public partial class AddOpenIddict : Migration
{
protected override void Up ( MigrationBuilder migrationBuilder )
{
2019-12-23 14:56:21 +09:00
int? maxLength = this . IsMySql ( migrationBuilder . ActiveProvider ) ? ( int? ) 255 : null ;
2019-05-24 06:17:02 +00:00
migrationBuilder . CreateTable (
name : "OpenIddictApplications" ,
columns : table = > new
{
ClientId = table . Column < string > ( maxLength : 100 , nullable : false ) ,
ClientSecret = table . Column < string > ( nullable : true ) ,
ConcurrencyToken = table . Column < string > ( maxLength : 50 , nullable : true ) ,
ConsentType = table . Column < string > ( nullable : true ) ,
DisplayName = table . Column < string > ( nullable : true ) ,
2019-12-23 14:56:21 +09:00
Id = table . Column < string > ( nullable : false , maxLength : maxLength ) ,
2019-05-24 06:17:02 +00:00
Permissions = table . Column < string > ( nullable : true ) ,
PostLogoutRedirectUris = table . Column < string > ( nullable : true ) ,
Properties = table . Column < string > ( nullable : true ) ,
RedirectUris = table . Column < string > ( nullable : true ) ,
Type = table . Column < string > ( maxLength : 25 , nullable : false ) ,
2020-02-14 00:07:19 +09:00
// do not set the maxLength, else http://MySql.Data.MySqlClient.MySqlException (0x80004005): Can't create table `btcpay`.`OpenIddictApplications` (errno: 150 "Foreign key constraint is incorrectly formed")
ApplicationUserId = table . Column < string > ( nullable : true )
2019-05-24 06:17:02 +00:00
} ,
constraints : table = >
{
table . PrimaryKey ( "PK_OpenIddictApplications" , x = > x . Id ) ;
table . ForeignKey (
name : "FK_OpenIddictApplications_AspNetUsers_ApplicationUserId" ,
column : x = > x . ApplicationUserId ,
principalTable : "AspNetUsers" ,
principalColumn : "Id" ,
onDelete : ReferentialAction . Restrict ) ;
} ) ;
migrationBuilder . CreateTable (
name : "OpenIddictScopes" ,
columns : table = > new
{
ConcurrencyToken = table . Column < string > ( maxLength : 50 , nullable : true ) ,
Description = table . Column < string > ( nullable : true ) ,
DisplayName = table . Column < string > ( nullable : true ) ,
2019-12-23 14:56:21 +09:00
Id = table . Column < string > ( nullable : false , maxLength : maxLength ) ,
2019-05-24 06:17:02 +00:00
Name = table . Column < string > ( maxLength : 200 , nullable : false ) ,
Properties = table . Column < string > ( nullable : true ) ,
Resources = table . Column < string > ( nullable : true )
} ,
constraints : table = >
{
table . PrimaryKey ( "PK_OpenIddictScopes" , x = > x . Id ) ;
} ) ;
migrationBuilder . CreateTable (
name : "OpenIddictAuthorizations" ,
columns : table = > new
{
2019-12-23 14:56:21 +09:00
ApplicationId = table . Column < string > ( nullable : true , maxLength : maxLength ) ,
2019-05-24 06:17:02 +00:00
ConcurrencyToken = table . Column < string > ( maxLength : 50 , nullable : true ) ,
2019-12-23 14:56:21 +09:00
Id = table . Column < string > ( nullable : false , maxLength : maxLength ) ,
2019-05-24 06:17:02 +00:00
Properties = table . Column < string > ( nullable : true ) ,
Scopes = table . Column < string > ( nullable : true ) ,
Status = table . Column < string > ( maxLength : 25 , nullable : false ) ,
Subject = table . Column < string > ( maxLength : 450 , nullable : false ) ,
Type = table . Column < string > ( maxLength : 25 , nullable : false )
} ,
constraints : table = >
{
table . PrimaryKey ( "PK_OpenIddictAuthorizations" , x = > x . Id ) ;
table . ForeignKey (
name : "FK_OpenIddictAuthorizations_OpenIddictApplications_ApplicationId" ,
column : x = > x . ApplicationId ,
principalTable : "OpenIddictApplications" ,
principalColumn : "Id" ,
onDelete : ReferentialAction . Restrict ) ;
} ) ;
migrationBuilder . CreateTable (
name : "OpenIddictTokens" ,
columns : table = > new
{
2019-12-23 14:56:21 +09:00
ApplicationId = table . Column < string > ( nullable : true , maxLength : maxLength ) ,
AuthorizationId = table . Column < string > ( nullable : true , maxLength : maxLength ) ,
2019-05-24 06:17:02 +00:00
ConcurrencyToken = table . Column < string > ( maxLength : 50 , nullable : true ) ,
CreationDate = table . Column < DateTimeOffset > ( nullable : true ) ,
ExpirationDate = table . Column < DateTimeOffset > ( nullable : true ) ,
2019-12-23 14:56:21 +09:00
Id = table . Column < string > ( nullable : false , maxLength : maxLength ) ,
2019-05-24 06:17:02 +00:00
Payload = table . Column < string > ( nullable : true ) ,
Properties = table . Column < string > ( nullable : true ) ,
ReferenceId = table . Column < string > ( maxLength : 100 , nullable : true ) ,
Status = table . Column < string > ( maxLength : 25 , nullable : false ) ,
Subject = table . Column < string > ( maxLength : 450 , nullable : false ) ,
Type = table . Column < string > ( maxLength : 25 , nullable : false )
} ,
constraints : table = >
{
table . PrimaryKey ( "PK_OpenIddictTokens" , x = > x . Id ) ;
table . ForeignKey (
name : "FK_OpenIddictTokens_OpenIddictApplications_ApplicationId" ,
column : x = > x . ApplicationId ,
principalTable : "OpenIddictApplications" ,
principalColumn : "Id" ,
onDelete : ReferentialAction . Restrict ) ;
table . ForeignKey (
name : "FK_OpenIddictTokens_OpenIddictAuthorizations_AuthorizationId" ,
column : x = > x . AuthorizationId ,
principalTable : "OpenIddictAuthorizations" ,
principalColumn : "Id" ,
onDelete : ReferentialAction . Restrict ) ;
} ) ;
migrationBuilder . CreateIndex (
name : "IX_OpenIddictApplications_ApplicationUserId" ,
table : "OpenIddictApplications" ,
column : "ApplicationUserId" ) ;
migrationBuilder . CreateIndex (
name : "IX_OpenIddictApplications_ClientId" ,
table : "OpenIddictApplications" ,
column : "ClientId" ,
unique : true ) ;
migrationBuilder . CreateIndex (
name : "IX_OpenIddictAuthorizations_ApplicationId_Status_Subject_Type" ,
table : "OpenIddictAuthorizations" ,
columns : new [ ] { "ApplicationId" , "Status" , "Subject" , "Type" } ) ;
migrationBuilder . CreateIndex (
name : "IX_OpenIddictScopes_Name" ,
table : "OpenIddictScopes" ,
column : "Name" ,
unique : true ) ;
migrationBuilder . CreateIndex (
name : "IX_OpenIddictTokens_AuthorizationId" ,
table : "OpenIddictTokens" ,
column : "AuthorizationId" ) ;
migrationBuilder . CreateIndex (
name : "IX_OpenIddictTokens_ReferenceId" ,
table : "OpenIddictTokens" ,
column : "ReferenceId" ,
unique : true ) ;
migrationBuilder . CreateIndex (
name : "IX_OpenIddictTokens_ApplicationId_Status_Subject_Type" ,
table : "OpenIddictTokens" ,
columns : new [ ] { "ApplicationId" , "Status" , "Subject" , "Type" } ) ;
}
protected override void Down ( MigrationBuilder migrationBuilder )
{
migrationBuilder . DropTable (
name : "OpenIddictScopes" ) ;
migrationBuilder . DropTable (
name : "OpenIddictTokens" ) ;
migrationBuilder . DropTable (
name : "OpenIddictAuthorizations" ) ;
migrationBuilder . DropTable (
name : "OpenIddictApplications" ) ;
}
}
}