20210521032224_AddDevices.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma warning disable CS1591
  2. #pragma warning disable SA1601
  3. using System;
  4. using Microsoft.EntityFrameworkCore.Migrations;
  5. namespace Jellyfin.Server.Implementations.Migrations
  6. {
  7. public partial class AddDevices : Migration
  8. {
  9. protected override void Up(MigrationBuilder migrationBuilder)
  10. {
  11. migrationBuilder.CreateTable(
  12. name: "ApiKeys",
  13. schema: "jellyfin",
  14. columns: table => new
  15. {
  16. Id = table.Column<int>(type: "INTEGER", nullable: false)
  17. .Annotation("Sqlite:Autoincrement", true),
  18. DateCreated = table.Column<DateTime>(type: "TEXT", nullable: false),
  19. Name = table.Column<string>(type: "TEXT", maxLength: 64, nullable: false),
  20. AccessToken = table.Column<Guid>(type: "TEXT", nullable: false)
  21. },
  22. constraints: table =>
  23. {
  24. table.PrimaryKey("PK_ApiKeys", x => x.Id);
  25. });
  26. migrationBuilder.CreateTable(
  27. name: "DeviceOptions",
  28. schema: "jellyfin",
  29. columns: table => new
  30. {
  31. Id = table.Column<int>(type: "INTEGER", nullable: false)
  32. .Annotation("Sqlite:Autoincrement", true),
  33. DeviceId = table.Column<string>(type: "TEXT", nullable: false),
  34. CustomName = table.Column<string>(type: "TEXT", nullable: true)
  35. },
  36. constraints: table =>
  37. {
  38. table.PrimaryKey("PK_DeviceOptions", x => x.Id);
  39. });
  40. migrationBuilder.CreateTable(
  41. name: "Devices",
  42. schema: "jellyfin",
  43. columns: table => new
  44. {
  45. Id = table.Column<int>(type: "INTEGER", nullable: false)
  46. .Annotation("Sqlite:Autoincrement", true),
  47. UserId = table.Column<Guid>(type: "TEXT", nullable: false),
  48. AccessToken = table.Column<string>(type: "TEXT", nullable: false),
  49. AppName = table.Column<string>(type: "TEXT", maxLength: 64, nullable: false),
  50. AppVersion = table.Column<string>(type: "TEXT", maxLength: 32, nullable: false),
  51. DeviceName = table.Column<string>(type: "TEXT", maxLength: 64, nullable: false),
  52. DeviceId = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
  53. IsActive = table.Column<bool>(type: "INTEGER", nullable: false),
  54. DateCreated = table.Column<DateTime>(type: "TEXT", nullable: false),
  55. DateLastActivity = table.Column<DateTime>(type: "TEXT", nullable: false)
  56. },
  57. constraints: table =>
  58. {
  59. table.PrimaryKey("PK_Devices", x => x.Id);
  60. table.ForeignKey(
  61. name: "FK_Devices_Users_UserId",
  62. column: x => x.UserId,
  63. principalSchema: "jellyfin",
  64. principalTable: "Users",
  65. principalColumn: "Id",
  66. onDelete: ReferentialAction.Cascade);
  67. });
  68. migrationBuilder.CreateIndex(
  69. name: "IX_ApiKeys_AccessToken",
  70. schema: "jellyfin",
  71. table: "ApiKeys",
  72. column: "AccessToken",
  73. unique: true);
  74. migrationBuilder.CreateIndex(
  75. name: "IX_DeviceOptions_DeviceId",
  76. schema: "jellyfin",
  77. table: "DeviceOptions",
  78. column: "DeviceId",
  79. unique: true);
  80. migrationBuilder.CreateIndex(
  81. name: "IX_Devices_AccessToken_DateLastActivity",
  82. schema: "jellyfin",
  83. table: "Devices",
  84. columns: new[] { "AccessToken", "DateLastActivity" });
  85. migrationBuilder.CreateIndex(
  86. name: "IX_Devices_DeviceId",
  87. schema: "jellyfin",
  88. table: "Devices",
  89. column: "DeviceId");
  90. migrationBuilder.CreateIndex(
  91. name: "IX_Devices_DeviceId_DateLastActivity",
  92. schema: "jellyfin",
  93. table: "Devices",
  94. columns: new[] { "DeviceId", "DateLastActivity" });
  95. migrationBuilder.CreateIndex(
  96. name: "IX_Devices_UserId_DeviceId",
  97. schema: "jellyfin",
  98. table: "Devices",
  99. columns: new[] { "UserId", "DeviceId" });
  100. }
  101. protected override void Down(MigrationBuilder migrationBuilder)
  102. {
  103. migrationBuilder.DropTable(
  104. name: "ApiKeys",
  105. schema: "jellyfin");
  106. migrationBuilder.DropTable(
  107. name: "DeviceOptions",
  108. schema: "jellyfin");
  109. migrationBuilder.DropTable(
  110. name: "Devices",
  111. schema: "jellyfin");
  112. }
  113. }
  114. }