diff options
author | crupest <crupest@outlook.com> | 2020-02-21 20:19:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-21 20:19:10 +0800 |
commit | 15371296c7b4b6a3a9a75b844ade5ccf00ec53bb (patch) | |
tree | bc3da9df67e73dff6578da9a0f4cd3982f4cd5f2 /Timeline | |
parent | 32765bc2009d36cd3bc124e2a9bb769fc3ec9b4b (diff) | |
parent | 90e5eb7672e58745d1c41c28051375582d22e6ec (diff) | |
download | timeline-15371296c7b4b6a3a9a75b844ade5ccf00ec53bb.tar.gz timeline-15371296c7b4b6a3a9a75b844ade5ccf00ec53bb.tar.bz2 timeline-15371296c7b4b6a3a9a75b844ade5ccf00ec53bb.zip |
Merge pull request #59 from crupest/dev
Migrate to sqlite.
Diffstat (limited to 'Timeline')
30 files changed, 436 insertions, 1552 deletions
diff --git a/Timeline/Configs/DatabaseConfig.cs b/Timeline/Configs/DatabaseConfig.cs deleted file mode 100644 index e1231bcd..00000000 --- a/Timeline/Configs/DatabaseConfig.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Timeline.Configs
-{
- public class DatabaseConfig
- {
- public bool UseDevelopment { get; set; } = false;
-
- public string ConnectionString { get; set; } = default!;
-
- public string DevelopmentConnectionString { get; set; } = default!;
- }
-}
diff --git a/Timeline/Configs/JwtConfig.cs b/Timeline/Configs/JwtConfiguration.cs index 8a17825e..af8052de 100644 --- a/Timeline/Configs/JwtConfig.cs +++ b/Timeline/Configs/JwtConfiguration.cs @@ -1,10 +1,9 @@ -namespace Timeline.Configs
+namespace Timeline.Configs
{
- public class JwtConfig
+ public class JwtConfiguration
{
public string Issuer { get; set; } = default!;
public string Audience { get; set; } = default!;
- public string SigningKey { get; set; } = default!;
/// <summary>
/// Set the default value of expire offset of jwt token.
diff --git a/Timeline/Entities/DatabaseContext.cs b/Timeline/Entities/DatabaseContext.cs index cac33379..039cbd51 100644 --- a/Timeline/Entities/DatabaseContext.cs +++ b/Timeline/Entities/DatabaseContext.cs @@ -2,12 +2,11 @@ using Microsoft.EntityFrameworkCore; namespace Timeline.Entities
{
- public abstract class DatabaseContext : DbContext
+ public class DatabaseContext : DbContext
{
- public DatabaseContext(DbContextOptions options)
+ public DatabaseContext(DbContextOptions<DatabaseContext> options)
: base(options)
{
-
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
@@ -21,22 +20,6 @@ namespace Timeline.Entities public DbSet<TimelineEntity> Timelines { get; set; } = default!;
public DbSet<TimelinePostEntity> TimelinePosts { get; set; } = default!;
public DbSet<TimelineMemberEntity> TimelineMembers { get; set; } = default!;
- }
- public class ProductionDatabaseContext : DatabaseContext
- {
- public ProductionDatabaseContext(DbContextOptions<ProductionDatabaseContext> options)
- : base(options)
- {
-
- }
- }
-
- public class DevelopmentDatabaseContext : DatabaseContext
- {
- public DevelopmentDatabaseContext(DbContextOptions<DevelopmentDatabaseContext> options)
- : base(options)
- {
-
- }
+ public DbSet<JwtTokenEntity> JwtToken { get; set; } = default!;
}
}
diff --git a/Timeline/Entities/JwtTokenEntity.cs b/Timeline/Entities/JwtTokenEntity.cs new file mode 100644 index 00000000..40cb230a --- /dev/null +++ b/Timeline/Entities/JwtTokenEntity.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace Timeline.Entities
+{
+ [Table("jwt_token")]
+ public class JwtTokenEntity
+ {
+ [Column("id"), Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
+ public long Id { get; set; }
+
+ [Required, Column("key")]
+#pragma warning disable CA1819 // Properties should not return arrays
+ public byte[] Key { get; set; } = default!;
+#pragma warning restore CA1819 // Properties should not return arrays
+ }
+}
diff --git a/Timeline/Migrations/DevelopmentDatabase/20200105150407_Initialize.Designer.cs b/Timeline/Migrations/20200105150407_Initialize.Designer.cs index 6fe1044c..ca93fcb3 100644 --- a/Timeline/Migrations/DevelopmentDatabase/20200105150407_Initialize.Designer.cs +++ b/Timeline/Migrations/20200105150407_Initialize.Designer.cs @@ -6,9 +6,9 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Timeline.Entities;
-namespace Timeline.Migrations.DevelopmentDatabase
+namespace Timeline.Migrations
{
- [DbContext(typeof(DevelopmentDatabaseContext))]
+ [DbContext(typeof(DatabaseContext))]
[Migration("20200105150407_Initialize")]
partial class Initialize
{
diff --git a/Timeline/Migrations/DevelopmentDatabase/20200105150407_Initialize.cs b/Timeline/Migrations/20200105150407_Initialize.cs index c6efaa4b..2881ee64 100644 --- a/Timeline/Migrations/DevelopmentDatabase/20200105150407_Initialize.cs +++ b/Timeline/Migrations/20200105150407_Initialize.cs @@ -1,7 +1,7 @@ using System;
using Microsoft.EntityFrameworkCore.Migrations;
-namespace Timeline.Migrations.DevelopmentDatabase
+namespace Timeline.Migrations
{
public partial class Initialize : Migration
{
diff --git a/Timeline/Migrations/DevelopmentDatabase/20200131100517_RefactorUser.Designer.cs b/Timeline/Migrations/20200131100517_RefactorUser.Designer.cs index 13e322c8..fb5e8a30 100644 --- a/Timeline/Migrations/DevelopmentDatabase/20200131100517_RefactorUser.Designer.cs +++ b/Timeline/Migrations/20200131100517_RefactorUser.Designer.cs @@ -6,9 +6,9 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Timeline.Entities;
-namespace Timeline.Migrations.DevelopmentDatabase
+namespace Timeline.Migrations
{
- [DbContext(typeof(DevelopmentDatabaseContext))]
+ [DbContext(typeof(DatabaseContext))]
[Migration("20200131100517_RefactorUser")]
partial class RefactorUser
{
diff --git a/Timeline/Migrations/DevelopmentDatabase/20200131100517_RefactorUser.cs b/Timeline/Migrations/20200131100517_RefactorUser.cs index ade65eb1..533f4bc4 100644 --- a/Timeline/Migrations/DevelopmentDatabase/20200131100517_RefactorUser.cs +++ b/Timeline/Migrations/20200131100517_RefactorUser.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore.Migrations;
-namespace Timeline.Migrations.DevelopmentDatabase
+namespace Timeline.Migrations
{
public partial class RefactorUser : Migration
{
diff --git a/Timeline/Migrations/ProductionDatabase/20200131152033_RefactorUser.Designer.cs b/Timeline/Migrations/20200221064341_AddJwtToken.Designer.cs index bb0bb5af..56596249 100644 --- a/Timeline/Migrations/ProductionDatabase/20200131152033_RefactorUser.Designer.cs +++ b/Timeline/Migrations/20200221064341_AddJwtToken.Designer.cs @@ -6,45 +6,61 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Timeline.Entities;
-namespace Timeline.Migrations.ProductionDatabase
+namespace Timeline.Migrations
{
- [DbContext(typeof(ProductionDatabaseContext))]
- [Migration("20200131152033_RefactorUser")]
- partial class RefactorUser
+ [DbContext(typeof(DatabaseContext))]
+ [Migration("20200221064341_AddJwtToken")]
+ partial class AddJwtToken
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
- .HasAnnotation("ProductVersion", "3.1.1")
- .HasAnnotation("Relational:MaxIdentifierLength", 64);
+ .HasAnnotation("ProductVersion", "3.1.2");
+
+ modelBuilder.Entity("Timeline.Entities.JwtTokenEntity", b =>
+ {
+ b.Property<long>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnName("id")
+ .HasColumnType("INTEGER");
+
+ b.Property<byte[]>("Token")
+ .IsRequired()
+ .HasColumnName("token")
+ .HasColumnType("BLOB");
+
+ b.HasKey("Id");
+
+ b.ToTable("jwt_token");
+ });
modelBuilder.Entity("Timeline.Entities.TimelineEntity", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.Property<DateTime>("CreateTime")
.HasColumnName("create_time")
- .HasColumnType("datetime(6)");
+ .HasColumnType("TEXT");
b.Property<string>("Description")
.HasColumnName("description")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
+ .HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnName("name")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
+ .HasColumnType("TEXT");
b.Property<long>("OwnerId")
.HasColumnName("owner")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.Property<int>("Visibility")
.HasColumnName("visibility")
- .HasColumnType("int");
+ .HasColumnType("INTEGER");
b.HasKey("Id");
@@ -58,15 +74,15 @@ namespace Timeline.Migrations.ProductionDatabase b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.Property<long>("TimelineId")
.HasColumnName("timeline")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.Property<long>("UserId")
.HasColumnName("user")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.HasKey("Id");
@@ -82,27 +98,27 @@ namespace Timeline.Migrations.ProductionDatabase b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.Property<long>("AuthorId")
.HasColumnName("author")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.Property<string>("Content")
.HasColumnName("content")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
+ .HasColumnType("TEXT");
b.Property<DateTime>("LastUpdated")
.HasColumnName("last_updated")
- .HasColumnType("datetime(6)");
+ .HasColumnType("TEXT");
b.Property<DateTime>("Time")
.HasColumnName("time")
- .HasColumnType("datetime(6)");
+ .HasColumnType("TEXT");
b.Property<long>("TimelineId")
.HasColumnName("timeline")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.HasKey("Id");
@@ -118,28 +134,28 @@ namespace Timeline.Migrations.ProductionDatabase b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.Property<byte[]>("Data")
.HasColumnName("data")
- .HasColumnType("longblob");
+ .HasColumnType("BLOB");
b.Property<string>("ETag")
.HasColumnName("etag")
- .HasColumnType("varchar(30) CHARACTER SET utf8mb4")
+ .HasColumnType("TEXT")
.HasMaxLength(30);
b.Property<DateTime>("LastModified")
.HasColumnName("last_modified")
- .HasColumnType("datetime(6)");
+ .HasColumnType("TEXT");
b.Property<string>("Type")
.HasColumnName("type")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
+ .HasColumnType("TEXT");
b.Property<long>("UserId")
.HasColumnName("user")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.HasKey("Id");
@@ -154,33 +170,33 @@ namespace Timeline.Migrations.ProductionDatabase b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnName("id")
- .HasColumnType("bigint");
+ .HasColumnType("INTEGER");
b.Property<string>("Nickname")
.HasColumnName("nickname")
- .HasColumnType("varchar(100) CHARACTER SET utf8mb4")
+ .HasColumnType("TEXT")
.HasMaxLength(100);
b.Property<string>("Password")
.IsRequired()
.HasColumnName("password")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
+ .HasColumnType("TEXT");
b.Property<string>("Roles")
.IsRequired()
.HasColumnName("roles")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
+ .HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnName("username")
- .HasColumnType("varchar(26) CHARACTER SET utf8mb4")
+ .HasColumnType("TEXT")
.HasMaxLength(26);
b.Property<long>("Version")
.ValueGeneratedOnAdd()
.HasColumnName("version")
- .HasColumnType("bigint")
+ .HasColumnType("INTEGER")
.HasDefaultValue(0L);
b.HasKey("Id");
diff --git a/Timeline/Migrations/20200221064341_AddJwtToken.cs b/Timeline/Migrations/20200221064341_AddJwtToken.cs new file mode 100644 index 00000000..628970c6 --- /dev/null +++ b/Timeline/Migrations/20200221064341_AddJwtToken.cs @@ -0,0 +1,45 @@ +using System;
+using System.Security.Cryptography;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace Timeline.Migrations
+{
+ public static class JwtTokenGenerateHelper
+ {
+ public static byte[] GenerateKey()
+ {
+ using var random = RandomNumberGenerator.Create();
+ var key = new byte[16];
+ random.GetBytes(key);
+ return key;
+ }
+ }
+
+ public partial class AddJwtToken : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "jwt_token",
+ columns: table => new
+ {
+ id = table.Column<long>(nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ key = table.Column<byte[]>(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_jwt_token", x => x.id);
+ });
+
+
+ migrationBuilder.InsertData("jwt_token", "key", JwtTokenGenerateHelper.GenerateKey());
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "jwt_token");
+ }
+ }
+}
diff --git a/Timeline/Migrations/DevelopmentDatabase/DevelopmentDatabaseContextModelSnapshot.cs b/Timeline/Migrations/DatabaseContextModelSnapshot.cs index 5da49dbe..d5f9c0e4 100644 --- a/Timeline/Migrations/DevelopmentDatabase/DevelopmentDatabaseContextModelSnapshot.cs +++ b/Timeline/Migrations/DatabaseContextModelSnapshot.cs @@ -5,16 +5,33 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Timeline.Entities;
-namespace Timeline.Migrations.DevelopmentDatabase
+namespace Timeline.Migrations
{
- [DbContext(typeof(DevelopmentDatabaseContext))]
- partial class DevelopmentDatabaseContextModelSnapshot : ModelSnapshot
+ [DbContext(typeof(DatabaseContext))]
+ partial class DatabaseContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
- .HasAnnotation("ProductVersion", "3.1.1");
+ .HasAnnotation("ProductVersion", "3.1.2");
+
+ modelBuilder.Entity("Timeline.Entities.JwtTokenEntity", b =>
+ {
+ b.Property<long>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnName("id")
+ .HasColumnType("INTEGER");
+
+ b.Property<byte[]>("Token")
+ .IsRequired()
+ .HasColumnName("token")
+ .HasColumnType("BLOB");
+
+ b.HasKey("Id");
+
+ b.ToTable("jwt_token");
+ });
modelBuilder.Entity("Timeline.Entities.TimelineEntity", b =>
{
diff --git a/Timeline/Migrations/ProductionDatabase/20191031064541_Initialize.Designer.cs b/Timeline/Migrations/ProductionDatabase/20191031064541_Initialize.Designer.cs deleted file mode 100644 index cd584b3c..00000000 --- a/Timeline/Migrations/ProductionDatabase/20191031064541_Initialize.Designer.cs +++ /dev/null @@ -1,137 +0,0 @@ -// <auto-generated />
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Timeline.Entities;
-
-namespace Timeline.Migrations.ProductionDatabase
-{
- [DbContext(typeof(ProductionDatabaseContext))]
- [Migration("20191031064541_Initialize")]
- partial class Initialize
- {
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "3.0.0")
- .HasAnnotation("Relational:MaxIdentifierLength", 64);
-
- modelBuilder.Entity("Timeline.Entities.User", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<string>("EncryptedPassword")
- .IsRequired()
- .HasColumnName("password")
- .HasColumnType("longtext");
-
- b.Property<string>("Name")
- .IsRequired()
- .HasColumnName("name")
- .HasColumnType("varchar(26)")
- .HasMaxLength(26);
-
- b.Property<string>("RoleString")
- .IsRequired()
- .HasColumnName("roles")
- .HasColumnType("longtext");
-
- b.Property<long>("Version")
- .ValueGeneratedOnAdd()
- .HasColumnName("version")
- .HasColumnType("bigint")
- .HasDefaultValue(0L);
-
- b.HasKey("Id");
-
- b.HasIndex("Name")
- .IsUnique();
-
- b.ToTable("users");
- });
-
- modelBuilder.Entity("Timeline.Entities.UserAvatar", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<byte[]>("Data")
- .HasColumnName("data")
- .HasColumnType("longblob");
-
- b.Property<string>("ETag")
- .HasColumnName("etag")
- .HasColumnType("varchar(30)")
- .HasMaxLength(30);
-
- b.Property<DateTime>("LastModified")
- .HasColumnName("last_modified")
- .HasColumnType("datetime(6)");
-
- b.Property<string>("Type")
- .HasColumnName("type")
- .HasColumnType("longtext");
-
- b.Property<long>("UserId")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("UserId")
- .IsUnique();
-
- b.ToTable("user_avatars");
- });
-
- modelBuilder.Entity("Timeline.Entities.UserDetail", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<string>("Nickname")
- .HasColumnName("nickname")
- .HasColumnType("varchar(26)")
- .HasMaxLength(26);
-
- b.Property<long>("UserId")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("UserId")
- .IsUnique();
-
- b.ToTable("user_details");
- });
-
- modelBuilder.Entity("Timeline.Entities.UserAvatar", b =>
- {
- b.HasOne("Timeline.Entities.User", null)
- .WithOne("Avatar")
- .HasForeignKey("Timeline.Entities.UserAvatar", "UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-
- modelBuilder.Entity("Timeline.Entities.UserDetail", b =>
- {
- b.HasOne("Timeline.Entities.User", null)
- .WithOne("Detail")
- .HasForeignKey("Timeline.Entities.UserDetail", "UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/Timeline/Migrations/ProductionDatabase/20191031064541_Initialize.cs b/Timeline/Migrations/ProductionDatabase/20191031064541_Initialize.cs deleted file mode 100644 index dc989a96..00000000 --- a/Timeline/Migrations/ProductionDatabase/20191031064541_Initialize.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System;
-using Microsoft.EntityFrameworkCore.Metadata;
-using Microsoft.EntityFrameworkCore.Migrations;
-
-namespace Timeline.Migrations.ProductionDatabase
-{
- public partial class Initialize : Migration
- {
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.CreateTable(
- name: "users",
- columns: table => new
- {
- id = table.Column<long>(nullable: false)
- .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
- name = table.Column<string>(maxLength: 26, nullable: false),
- password = table.Column<string>(nullable: false),
- roles = table.Column<string>(nullable: false),
- version = table.Column<long>(nullable: false, defaultValue: 0L)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_users", x => x.id);
- });
-
- migrationBuilder.CreateTable(
- name: "user_avatars",
- columns: table => new
- {
- id = table.Column<long>(nullable: false)
- .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
- data = table.Column<byte[]>(nullable: true),
- type = table.Column<string>(nullable: true),
- etag = table.Column<string>(maxLength: 30, nullable: true),
- last_modified = table.Column<DateTime>(nullable: false),
- UserId = table.Column<long>(nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_user_avatars", x => x.id);
- table.ForeignKey(
- name: "FK_user_avatars_users_UserId",
- column: x => x.UserId,
- principalTable: "users",
- principalColumn: "id",
- onDelete: ReferentialAction.Cascade);
- });
-
- migrationBuilder.CreateTable(
- name: "user_details",
- columns: table => new
- {
- id = table.Column<long>(nullable: false)
- .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
- nickname = table.Column<string>(maxLength: 26, nullable: true),
- UserId = table.Column<long>(nullable: false)
- },
- constraints: table =>
- {
- table.PrimaryKey("PK_user_details", x => x.id);
- table.ForeignKey(
- name: "FK_user_details_users_UserId",
- column: x => x.UserId,
- principalTable: "users",
- principalColumn: "id",
- onDelete: ReferentialAction.Cascade);
- });
-
- migrationBuilder.CreateIndex(
- name: "IX_user_avatars_UserId",
- table: "user_avatars",
- column: "UserId",
- unique: true);
-
- migrationBuilder.CreateIndex(
- name: "IX_user_details_UserId",
- table: "user_details",
- column: "UserId",
- unique: true);
-
- migrationBuilder.CreateIndex(
- name: "IX_users_name",
- table: "users",
- column: "name",
- unique: true);
-
- // Add a init user. Username is "administrator". Password is "crupest".
- migrationBuilder.InsertData("users", new string[] { "name", "password", "roles" },
- new object[] { "administrator", "AQAAAAEAACcQAAAAENsspZrk8Wo+UuMyg6QuWJsNvRg6gVu4K/TumVod3h9GVLX9zDVuQQds3o7V8QWJ2w==", "user,admin" });
- }
-
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropTable(
- name: "user_avatars");
-
- migrationBuilder.DropTable(
- name: "user_details");
-
- migrationBuilder.DropTable(
- name: "users");
- }
- }
-}
diff --git a/Timeline/Migrations/ProductionDatabase/20191120104512_InitTimeline.Designer.cs b/Timeline/Migrations/ProductionDatabase/20191120104512_InitTimeline.Designer.cs deleted file mode 100644 index d50e8330..00000000 --- a/Timeline/Migrations/ProductionDatabase/20191120104512_InitTimeline.Designer.cs +++ /dev/null @@ -1,270 +0,0 @@ -// <auto-generated /> -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Timeline.Entities; - -namespace Timeline.Migrations.ProductionDatabase -{ - [DbContext(typeof(ProductionDatabaseContext))] - [Migration("20191120104512_InitTimeline")] - partial class InitTimeline - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("Timeline.Entities.TimelineEntity", b => - { - b.Property<long>("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint"); - - b.Property<DateTime>("CreateTime") - .HasColumnName("create_time") - .HasColumnType("datetime(6)"); - - b.Property<string>("Description") - .HasColumnName("description") - .HasColumnType("longtext CHARACTER SET utf8mb4"); - - b.Property<string>("Name") - .HasColumnName("name") - .HasColumnType("longtext CHARACTER SET utf8mb4"); - - b.Property<long>("OwnerId") - .HasColumnName("owner") - .HasColumnType("bigint"); - - b.Property<int>("Visibility") - .HasColumnName("visibility") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("OwnerId"); - - b.ToTable("timelines"); - }); - - modelBuilder.Entity("Timeline.Entities.TimelineMemberEntity", b => - { - b.Property<long>("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint"); - - b.Property<long>("TimelineId") - .HasColumnName("timeline") - .HasColumnType("bigint"); - - b.Property<long>("UserId") - .HasColumnName("user") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("TimelineId"); - - b.HasIndex("UserId"); - - b.ToTable("TimelineMembers"); - }); - - modelBuilder.Entity("Timeline.Entities.TimelinePostEntity", b => - { - b.Property<long>("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint"); - - b.Property<long>("AuthorId") - .HasColumnName("author") - .HasColumnType("bigint"); - - b.Property<string>("Content") - .HasColumnName("content") - .HasColumnType("longtext CHARACTER SET utf8mb4"); - - b.Property<DateTime>("LastUpdated") - .HasColumnName("last_updated") - .HasColumnType("datetime(6)"); - - b.Property<DateTime>("Time") - .HasColumnName("time") - .HasColumnType("datetime(6)"); - - b.Property<long>("TimelineId") - .HasColumnName("timeline") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("AuthorId"); - - b.HasIndex("TimelineId"); - - b.ToTable("timeline_posts"); - }); - - modelBuilder.Entity("Timeline.Entities.User", b => - { - b.Property<long>("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint"); - - b.Property<string>("EncryptedPassword") - .IsRequired() - .HasColumnName("password") - .HasColumnType("longtext CHARACTER SET utf8mb4"); - - b.Property<string>("Name") - .IsRequired() - .HasColumnName("name") - .HasColumnType("varchar(26) CHARACTER SET utf8mb4") - .HasMaxLength(26); - - b.Property<string>("RoleString") - .IsRequired() - .HasColumnName("roles") - .HasColumnType("longtext CHARACTER SET utf8mb4"); - - b.Property<long>("Version") - .ValueGeneratedOnAdd() - .HasColumnName("version") - .HasColumnType("bigint") - .HasDefaultValue(0L); - - b.HasKey("Id"); - - b.HasIndex("Name") - .IsUnique(); - - b.ToTable("users"); - }); - - modelBuilder.Entity("Timeline.Entities.UserAvatar", b => - { - b.Property<long>("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint"); - - b.Property<byte[]>("Data") - .HasColumnName("data") - .HasColumnType("longblob"); - - b.Property<string>("ETag") - .HasColumnName("etag") - .HasColumnType("varchar(30) CHARACTER SET utf8mb4") - .HasMaxLength(30); - - b.Property<DateTime>("LastModified") - .HasColumnName("last_modified") - .HasColumnType("datetime(6)"); - - b.Property<string>("Type") - .HasColumnName("type") - .HasColumnType("longtext CHARACTER SET utf8mb4"); - - b.Property<long>("UserId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_avatars"); - }); - - modelBuilder.Entity("Timeline.Entities.UserDetail", b => - { - b.Property<long>("Id") - .ValueGeneratedOnAdd() - .HasColumnName("id") - .HasColumnType("bigint"); - - b.Property<string>("Nickname") - .HasColumnName("nickname") - .HasColumnType("varchar(26) CHARACTER SET utf8mb4") - .HasMaxLength(26); - - b.Property<long>("UserId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique(); - - b.ToTable("user_details"); - }); - - modelBuilder.Entity("Timeline.Entities.TimelineEntity", b => - { - b.HasOne("Timeline.Entities.User", "Owner") - .WithMany("Timelines") - .HasForeignKey("OwnerId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Timeline.Entities.TimelineMemberEntity", b => - { - b.HasOne("Timeline.Entities.TimelineEntity", "Timeline") - .WithMany("Members") - .HasForeignKey("TimelineId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Timeline.Entities.User", "User") - .WithMany("TimelinesJoined") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Timeline.Entities.TimelinePostEntity", b => - { - b.HasOne("Timeline.Entities.User", "Author") - .WithMany("TimelinePosts") - .HasForeignKey("AuthorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Timeline.Entities.TimelineEntity", "Timeline") - .WithMany("Posts") - .HasForeignKey("TimelineId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Timeline.Entities.UserAvatar", b => - { - b.HasOne("Timeline.Entities.User", null) - .WithOne("Avatar") - .HasForeignKey("Timeline.Entities.UserAvatar", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Timeline.Entities.UserDetail", b => - { - b.HasOne("Timeline.Entities.User", null) - .WithOne("Detail") - .HasForeignKey("Timeline.Entities.UserDetail", "UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Timeline/Migrations/ProductionDatabase/20191120104512_InitTimeline.cs b/Timeline/Migrations/ProductionDatabase/20191120104512_InitTimeline.cs deleted file mode 100644 index 9b80ad30..00000000 --- a/Timeline/Migrations/ProductionDatabase/20191120104512_InitTimeline.cs +++ /dev/null @@ -1,229 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Timeline.Migrations.ProductionDatabase -{ - public partial class InitTimeline : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn<string>( - name: "roles", - table: "users", - nullable: false, - oldClrType: typeof(string), - oldType: "longtext"); - - migrationBuilder.AlterColumn<string>( - name: "name", - table: "users", - maxLength: 26, - nullable: false, - oldClrType: typeof(string), - oldType: "varchar(26)", - oldMaxLength: 26); - - migrationBuilder.AlterColumn<string>( - name: "password", - table: "users", - nullable: false, - oldClrType: typeof(string), - oldType: "longtext"); - - migrationBuilder.AlterColumn<string>( - name: "nickname", - table: "user_details", - maxLength: 26, - nullable: true, - oldClrType: typeof(string), - oldType: "varchar(26)", - oldMaxLength: 26, - oldNullable: true); - - migrationBuilder.AlterColumn<string>( - name: "type", - table: "user_avatars", - nullable: true, - oldClrType: typeof(string), - oldType: "longtext", - oldNullable: true); - - migrationBuilder.AlterColumn<string>( - name: "etag", - table: "user_avatars", - maxLength: 30, - nullable: true, - oldClrType: typeof(string), - oldType: "varchar(30)", - oldMaxLength: 30, - oldNullable: true); - - migrationBuilder.CreateTable( - name: "timelines", - columns: table => new - { - id = table.Column<long>(nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - name = table.Column<string>(nullable: true), - description = table.Column<string>(nullable: true), - owner = table.Column<long>(nullable: false), - visibility = table.Column<int>(nullable: false), - create_time = table.Column<DateTime>(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_timelines", x => x.id); - table.ForeignKey( - name: "FK_timelines_users_owner", - column: x => x.owner, - principalTable: "users", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "timeline_posts", - columns: table => new - { - id = table.Column<long>(nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - timeline = table.Column<long>(nullable: false), - author = table.Column<long>(nullable: false), - content = table.Column<string>(nullable: true), - time = table.Column<DateTime>(nullable: false), - last_updated = table.Column<DateTime>(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_timeline_posts", x => x.id); - table.ForeignKey( - name: "FK_timeline_posts_users_author", - column: x => x.author, - principalTable: "users", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_timeline_posts_timelines_timeline", - column: x => x.timeline, - principalTable: "timelines", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "TimelineMembers", - columns: table => new - { - id = table.Column<long>(nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - user = table.Column<long>(nullable: false), - timeline = table.Column<long>(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_TimelineMembers", x => x.id); - table.ForeignKey( - name: "FK_TimelineMembers_timelines_timeline", - column: x => x.timeline, - principalTable: "timelines", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_TimelineMembers_users_user", - column: x => x.user, - principalTable: "users", - principalColumn: "id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_timeline_posts_author", - table: "timeline_posts", - column: "author"); - - migrationBuilder.CreateIndex( - name: "IX_timeline_posts_timeline", - table: "timeline_posts", - column: "timeline"); - - migrationBuilder.CreateIndex( - name: "IX_TimelineMembers_timeline", - table: "TimelineMembers", - column: "timeline"); - - migrationBuilder.CreateIndex( - name: "IX_TimelineMembers_user", - table: "TimelineMembers", - column: "user"); - - migrationBuilder.CreateIndex( - name: "IX_timelines_owner", - table: "timelines", - column: "owner"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "timeline_posts"); - - migrationBuilder.DropTable( - name: "TimelineMembers"); - - migrationBuilder.DropTable( - name: "timelines"); - - migrationBuilder.AlterColumn<string>( - name: "roles", - table: "users", - type: "longtext", - nullable: false, - oldClrType: typeof(string)); - - migrationBuilder.AlterColumn<string>( - name: "name", - table: "users", - type: "varchar(26)", - maxLength: 26, - nullable: false, - oldClrType: typeof(string), - oldMaxLength: 26); - - migrationBuilder.AlterColumn<string>( - name: "password", - table: "users", - type: "longtext", - nullable: false, - oldClrType: typeof(string)); - - migrationBuilder.AlterColumn<string>( - name: "nickname", - table: "user_details", - type: "varchar(26)", - maxLength: 26, - nullable: true, - oldClrType: typeof(string), - oldMaxLength: 26, - oldNullable: true); - - migrationBuilder.AlterColumn<string>( - name: "type", - table: "user_avatars", - type: "longtext", - nullable: true, - oldClrType: typeof(string), - oldNullable: true); - - migrationBuilder.AlterColumn<string>( - name: "etag", - table: "user_avatars", - type: "varchar(30)", - maxLength: 30, - nullable: true, - oldClrType: typeof(string), - oldMaxLength: 30, - oldNullable: true); - } - } -} diff --git a/Timeline/Migrations/ProductionDatabase/20200105151839_RenameTimelineMember.Designer.cs b/Timeline/Migrations/ProductionDatabase/20200105151839_RenameTimelineMember.Designer.cs deleted file mode 100644 index 356406fa..00000000 --- a/Timeline/Migrations/ProductionDatabase/20200105151839_RenameTimelineMember.Designer.cs +++ /dev/null @@ -1,270 +0,0 @@ -// <auto-generated />
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Migrations;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Timeline.Entities;
-
-namespace Timeline.Migrations.ProductionDatabase
-{
- [DbContext(typeof(ProductionDatabaseContext))]
- [Migration("20200105151839_RenameTimelineMember")]
- partial class RenameTimelineMember
- {
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "3.1.0")
- .HasAnnotation("Relational:MaxIdentifierLength", 64);
-
- modelBuilder.Entity("Timeline.Entities.TimelineEntity", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<DateTime>("CreateTime")
- .HasColumnName("create_time")
- .HasColumnType("datetime(6)");
-
- b.Property<string>("Description")
- .HasColumnName("description")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<string>("Name")
- .HasColumnName("name")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<long>("OwnerId")
- .HasColumnName("owner")
- .HasColumnType("bigint");
-
- b.Property<int>("Visibility")
- .HasColumnName("visibility")
- .HasColumnType("int");
-
- b.HasKey("Id");
-
- b.HasIndex("OwnerId");
-
- b.ToTable("timelines");
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelineMemberEntity", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<long>("TimelineId")
- .HasColumnName("timeline")
- .HasColumnType("bigint");
-
- b.Property<long>("UserId")
- .HasColumnName("user")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("TimelineId");
-
- b.HasIndex("UserId");
-
- b.ToTable("timeline_members");
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelinePostEntity", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<long>("AuthorId")
- .HasColumnName("author")
- .HasColumnType("bigint");
-
- b.Property<string>("Content")
- .HasColumnName("content")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<DateTime>("LastUpdated")
- .HasColumnName("last_updated")
- .HasColumnType("datetime(6)");
-
- b.Property<DateTime>("Time")
- .HasColumnName("time")
- .HasColumnType("datetime(6)");
-
- b.Property<long>("TimelineId")
- .HasColumnName("timeline")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("AuthorId");
-
- b.HasIndex("TimelineId");
-
- b.ToTable("timeline_posts");
- });
-
- modelBuilder.Entity("Timeline.Entities.User", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<string>("EncryptedPassword")
- .IsRequired()
- .HasColumnName("password")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<string>("Name")
- .IsRequired()
- .HasColumnName("name")
- .HasColumnType("varchar(26) CHARACTER SET utf8mb4")
- .HasMaxLength(26);
-
- b.Property<string>("RoleString")
- .IsRequired()
- .HasColumnName("roles")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<long>("Version")
- .ValueGeneratedOnAdd()
- .HasColumnName("version")
- .HasColumnType("bigint")
- .HasDefaultValue(0L);
-
- b.HasKey("Id");
-
- b.HasIndex("Name")
- .IsUnique();
-
- b.ToTable("users");
- });
-
- modelBuilder.Entity("Timeline.Entities.UserAvatar", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<byte[]>("Data")
- .HasColumnName("data")
- .HasColumnType("longblob");
-
- b.Property<string>("ETag")
- .HasColumnName("etag")
- .HasColumnType("varchar(30) CHARACTER SET utf8mb4")
- .HasMaxLength(30);
-
- b.Property<DateTime>("LastModified")
- .HasColumnName("last_modified")
- .HasColumnType("datetime(6)");
-
- b.Property<string>("Type")
- .HasColumnName("type")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<long>("UserId")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("UserId")
- .IsUnique();
-
- b.ToTable("user_avatars");
- });
-
- modelBuilder.Entity("Timeline.Entities.UserDetail", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<string>("Nickname")
- .HasColumnName("nickname")
- .HasColumnType("varchar(26) CHARACTER SET utf8mb4")
- .HasMaxLength(26);
-
- b.Property<long>("UserId")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("UserId")
- .IsUnique();
-
- b.ToTable("user_details");
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelineEntity", b =>
- {
- b.HasOne("Timeline.Entities.User", "Owner")
- .WithMany("Timelines")
- .HasForeignKey("OwnerId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelineMemberEntity", b =>
- {
- b.HasOne("Timeline.Entities.TimelineEntity", "Timeline")
- .WithMany("Members")
- .HasForeignKey("TimelineId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("Timeline.Entities.User", "User")
- .WithMany("TimelinesJoined")
- .HasForeignKey("UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelinePostEntity", b =>
- {
- b.HasOne("Timeline.Entities.User", "Author")
- .WithMany("TimelinePosts")
- .HasForeignKey("AuthorId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("Timeline.Entities.TimelineEntity", "Timeline")
- .WithMany("Posts")
- .HasForeignKey("TimelineId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-
- modelBuilder.Entity("Timeline.Entities.UserAvatar", b =>
- {
- b.HasOne("Timeline.Entities.User", null)
- .WithOne("Avatar")
- .HasForeignKey("Timeline.Entities.UserAvatar", "UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-
- modelBuilder.Entity("Timeline.Entities.UserDetail", b =>
- {
- b.HasOne("Timeline.Entities.User", null)
- .WithOne("Detail")
- .HasForeignKey("Timeline.Entities.UserDetail", "UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/Timeline/Migrations/ProductionDatabase/20200105151839_RenameTimelineMember.cs b/Timeline/Migrations/ProductionDatabase/20200105151839_RenameTimelineMember.cs deleted file mode 100644 index 8aef42d7..00000000 --- a/Timeline/Migrations/ProductionDatabase/20200105151839_RenameTimelineMember.cs +++ /dev/null @@ -1,107 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations;
-
-namespace Timeline.Migrations.ProductionDatabase
-{
- public partial class RenameTimelineMember : Migration
- {
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropForeignKey(
- name: "FK_TimelineMembers_timelines_timeline",
- table: "TimelineMembers");
-
- migrationBuilder.DropForeignKey(
- name: "FK_TimelineMembers_users_user",
- table: "TimelineMembers");
-
- migrationBuilder.DropPrimaryKey(
- name: "PK_TimelineMembers",
- table: "TimelineMembers");
-
- migrationBuilder.RenameTable(
- name: "TimelineMembers",
- newName: "timeline_members");
-
- migrationBuilder.RenameIndex(
- name: "IX_TimelineMembers_user",
- table: "timeline_members",
- newName: "IX_timeline_members_user");
-
- migrationBuilder.RenameIndex(
- name: "IX_TimelineMembers_timeline",
- table: "timeline_members",
- newName: "IX_timeline_members_timeline");
-
- migrationBuilder.AddPrimaryKey(
- name: "PK_timeline_members",
- table: "timeline_members",
- column: "id");
-
- migrationBuilder.AddForeignKey(
- name: "FK_timeline_members_timelines_timeline",
- table: "timeline_members",
- column: "timeline",
- principalTable: "timelines",
- principalColumn: "id",
- onDelete: ReferentialAction.Cascade);
-
- migrationBuilder.AddForeignKey(
- name: "FK_timeline_members_users_user",
- table: "timeline_members",
- column: "user",
- principalTable: "users",
- principalColumn: "id",
- onDelete: ReferentialAction.Cascade);
- }
-
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.DropForeignKey(
- name: "FK_timeline_members_timelines_timeline",
- table: "timeline_members");
-
- migrationBuilder.DropForeignKey(
- name: "FK_timeline_members_users_user",
- table: "timeline_members");
-
- migrationBuilder.DropPrimaryKey(
- name: "PK_timeline_members",
- table: "timeline_members");
-
- migrationBuilder.RenameTable(
- name: "timeline_members",
- newName: "TimelineMembers");
-
- migrationBuilder.RenameIndex(
- name: "IX_timeline_members_user",
- table: "TimelineMembers",
- newName: "IX_TimelineMembers_user");
-
- migrationBuilder.RenameIndex(
- name: "IX_timeline_members_timeline",
- table: "TimelineMembers",
- newName: "IX_TimelineMembers_timeline");
-
- migrationBuilder.AddPrimaryKey(
- name: "PK_TimelineMembers",
- table: "TimelineMembers",
- column: "id");
-
- migrationBuilder.AddForeignKey(
- name: "FK_TimelineMembers_timelines_timeline",
- table: "TimelineMembers",
- column: "timeline",
- principalTable: "timelines",
- principalColumn: "id",
- onDelete: ReferentialAction.Cascade);
-
- migrationBuilder.AddForeignKey(
- name: "FK_TimelineMembers_users_user",
- table: "TimelineMembers",
- column: "user",
- principalTable: "users",
- principalColumn: "id",
- onDelete: ReferentialAction.Cascade);
- }
- }
-}
diff --git a/Timeline/Migrations/ProductionDatabase/20200131152033_RefactorUser.cs b/Timeline/Migrations/ProductionDatabase/20200131152033_RefactorUser.cs deleted file mode 100644 index a0ca5212..00000000 --- a/Timeline/Migrations/ProductionDatabase/20200131152033_RefactorUser.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata;
-using Microsoft.EntityFrameworkCore.Migrations;
-
-namespace Timeline.Migrations.ProductionDatabase
-{
- public partial class RefactorUser : Migration
- {
- protected override void Up(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.Sql(@"
-START TRANSACTION;
-
-ALTER TABLE `users`
- CHANGE COLUMN `name` `username` varchar (26) NOT NULL,
- RENAME INDEX IX_users_name TO IX_users_username,
- ADD `nickname` varchar(100) CHARACTER SET utf8mb4 NULL;
-
-UPDATE users
- SET nickname = (
- SELECT nickname
- FROM user_details
- WHERE user_details.UserId = users.id
- );
-
-ALTER TABLE `user_avatars`
- CHANGE COLUMN `UserId` `user` bigint (20) NOT NULL,
- RENAME INDEX IX_user_avatars_UserId TO IX_user_avatars_user,
- DROP FOREIGN KEY FK_user_avatars_users_UserId,
- ADD CONSTRAINT FK_user_avatars_users_user FOREIGN KEY (`user`) REFERENCES `users` (`id`) ON DELETE CASCADE;
-
-COMMIT;
- ");
- }
-
- protected override void Down(MigrationBuilder migrationBuilder)
- {
- migrationBuilder.Sql(@"
-START TRANSACTION;
-
-ALTER TABLE `users`
- CHANGE COLUMN `username` `name` varchar (26) NOT NULL,
- RENAME INDEX IX_users_username TO IX_users_name,
- DROP COLUMN `nickname`;
-
-ALTER TABLE `user_avatars`
- CHANGE COLUMN `user` `UserId` bigint (20) NOT NULL,
- RENAME INDEX IX_user_avatars_user TO IX_user_avatars_UserId,
- DROP FOREIGN KEY FK_user_avatars_users_user,
- ADD CONSTRAINT FK_user_avatars_users_UserId FOREIGN KEY (`UserId`) REFERENCES `users` (`id`) ON DELETE CASCADE;
-
-COMMIT;
- ");
- }
- }
-}
diff --git a/Timeline/Migrations/ProductionDatabase/ProductionDatabaseContextModelSnapshot.cs b/Timeline/Migrations/ProductionDatabase/ProductionDatabaseContextModelSnapshot.cs deleted file mode 100644 index bfc9b768..00000000 --- a/Timeline/Migrations/ProductionDatabase/ProductionDatabaseContextModelSnapshot.cs +++ /dev/null @@ -1,242 +0,0 @@ -// <auto-generated />
-using System;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Infrastructure;
-using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
-using Timeline.Entities;
-
-namespace Timeline.Migrations.ProductionDatabase
-{
- [DbContext(typeof(ProductionDatabaseContext))]
- partial class ProductionDatabaseContextModelSnapshot : ModelSnapshot
- {
- protected override void BuildModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "3.1.1")
- .HasAnnotation("Relational:MaxIdentifierLength", 64);
-
- modelBuilder.Entity("Timeline.Entities.TimelineEntity", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<DateTime>("CreateTime")
- .HasColumnName("create_time")
- .HasColumnType("datetime(6)");
-
- b.Property<string>("Description")
- .HasColumnName("description")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<string>("Name")
- .HasColumnName("name")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<long>("OwnerId")
- .HasColumnName("owner")
- .HasColumnType("bigint");
-
- b.Property<int>("Visibility")
- .HasColumnName("visibility")
- .HasColumnType("int");
-
- b.HasKey("Id");
-
- b.HasIndex("OwnerId");
-
- b.ToTable("timelines");
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelineMemberEntity", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<long>("TimelineId")
- .HasColumnName("timeline")
- .HasColumnType("bigint");
-
- b.Property<long>("UserId")
- .HasColumnName("user")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("TimelineId");
-
- b.HasIndex("UserId");
-
- b.ToTable("timeline_members");
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelinePostEntity", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<long>("AuthorId")
- .HasColumnName("author")
- .HasColumnType("bigint");
-
- b.Property<string>("Content")
- .HasColumnName("content")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<DateTime>("LastUpdated")
- .HasColumnName("last_updated")
- .HasColumnType("datetime(6)");
-
- b.Property<DateTime>("Time")
- .HasColumnName("time")
- .HasColumnType("datetime(6)");
-
- b.Property<long>("TimelineId")
- .HasColumnName("timeline")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("AuthorId");
-
- b.HasIndex("TimelineId");
-
- b.ToTable("timeline_posts");
- });
-
- modelBuilder.Entity("Timeline.Entities.UserAvatarEntity", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<byte[]>("Data")
- .HasColumnName("data")
- .HasColumnType("longblob");
-
- b.Property<string>("ETag")
- .HasColumnName("etag")
- .HasColumnType("varchar(30) CHARACTER SET utf8mb4")
- .HasMaxLength(30);
-
- b.Property<DateTime>("LastModified")
- .HasColumnName("last_modified")
- .HasColumnType("datetime(6)");
-
- b.Property<string>("Type")
- .HasColumnName("type")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<long>("UserId")
- .HasColumnName("user")
- .HasColumnType("bigint");
-
- b.HasKey("Id");
-
- b.HasIndex("UserId")
- .IsUnique();
-
- b.ToTable("user_avatars");
- });
-
- modelBuilder.Entity("Timeline.Entities.UserEntity", b =>
- {
- b.Property<long>("Id")
- .ValueGeneratedOnAdd()
- .HasColumnName("id")
- .HasColumnType("bigint");
-
- b.Property<string>("Nickname")
- .HasColumnName("nickname")
- .HasColumnType("varchar(100) CHARACTER SET utf8mb4")
- .HasMaxLength(100);
-
- b.Property<string>("Password")
- .IsRequired()
- .HasColumnName("password")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<string>("Roles")
- .IsRequired()
- .HasColumnName("roles")
- .HasColumnType("longtext CHARACTER SET utf8mb4");
-
- b.Property<string>("Username")
- .IsRequired()
- .HasColumnName("username")
- .HasColumnType("varchar(26) CHARACTER SET utf8mb4")
- .HasMaxLength(26);
-
- b.Property<long>("Version")
- .ValueGeneratedOnAdd()
- .HasColumnName("version")
- .HasColumnType("bigint")
- .HasDefaultValue(0L);
-
- b.HasKey("Id");
-
- b.HasIndex("Username")
- .IsUnique();
-
- b.ToTable("users");
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelineEntity", b =>
- {
- b.HasOne("Timeline.Entities.UserEntity", "Owner")
- .WithMany("Timelines")
- .HasForeignKey("OwnerId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelineMemberEntity", b =>
- {
- b.HasOne("Timeline.Entities.TimelineEntity", "Timeline")
- .WithMany("Members")
- .HasForeignKey("TimelineId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("Timeline.Entities.UserEntity", "User")
- .WithMany("TimelinesJoined")
- .HasForeignKey("UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-
- modelBuilder.Entity("Timeline.Entities.TimelinePostEntity", b =>
- {
- b.HasOne("Timeline.Entities.UserEntity", "Author")
- .WithMany("TimelinePosts")
- .HasForeignKey("AuthorId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
-
- b.HasOne("Timeline.Entities.TimelineEntity", "Timeline")
- .WithMany("Posts")
- .HasForeignKey("TimelineId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-
- modelBuilder.Entity("Timeline.Entities.UserAvatarEntity", b =>
- {
- b.HasOne("Timeline.Entities.UserEntity", "User")
- .WithOne("Avatar")
- .HasForeignKey("Timeline.Entities.UserAvatarEntity", "UserId")
- .OnDelete(DeleteBehavior.Cascade)
- .IsRequired();
- });
-#pragma warning restore 612, 618
- }
- }
-}
diff --git a/Timeline/Program.cs b/Timeline/Program.cs index b44aafde..c49f74b0 100644 --- a/Timeline/Program.cs +++ b/Timeline/Program.cs @@ -1,9 +1,10 @@ using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.FileProviders;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Resources;
+using Timeline.Entities;
[assembly: NeutralResourcesLanguage("en")]
@@ -13,13 +14,19 @@ namespace Timeline {
public static void Main(string[] args)
{
- CreateWebHostBuilder(args)
- .ConfigureAppConfiguration((context, config) =>
+ var host = CreateWebHostBuilder(args).Build();
+
+ var env = host.Services.GetRequiredService<IWebHostEnvironment>();
+ if (env.IsProduction())
{
- if (context.HostingEnvironment.IsProduction())
- config.AddJsonFile(new PhysicalFileProvider("/etc/webapp/timeline/"), "config.json", true, true);
- })
- .Build().Run();
+ using (var scope = host.Services.CreateScope())
+ {
+ var databaseContext = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
+ databaseContext.Database.Migrate();
+ }
+ }
+
+ host.Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
diff --git a/Timeline/Properties/launchSettings.json b/Timeline/Properties/launchSettings.json index 2daf38db..4bae443c 100644 --- a/Timeline/Properties/launchSettings.json +++ b/Timeline/Properties/launchSettings.json @@ -3,7 +3,8 @@ "Timeline": { "commandName": "Project", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ASPNETCORE_WORKDIR": "D:\\timeline-development" } } } diff --git a/Timeline/Resources/Services/UserTokenService.Designer.cs b/Timeline/Resources/Services/UserTokenService.Designer.cs new file mode 100644 index 00000000..3c3c7e41 --- /dev/null +++ b/Timeline/Resources/Services/UserTokenService.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Timeline.Resources.Services {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class UserTokenService {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal UserTokenService() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.UserTokenService", typeof(UserTokenService).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Jwt token key is not set in database. Maybe you forget to migrate the database..
+ /// </summary>
+ internal static string JwtKeyNotExist {
+ get {
+ return ResourceManager.GetString("JwtKeyNotExist", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/Timeline/Resources/Services/UserTokenService.resx b/Timeline/Resources/Services/UserTokenService.resx new file mode 100644 index 00000000..1ce78427 --- /dev/null +++ b/Timeline/Resources/Services/UserTokenService.resx @@ -0,0 +1,123 @@ +<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="JwtKeyNotExist" xml:space="preserve">
+ <value>Jwt token key is not set in database. Maybe you forget to migrate the database.</value>
+ </data>
+</root>
\ No newline at end of file diff --git a/Timeline/Services/PathProvider.cs b/Timeline/Services/PathProvider.cs new file mode 100644 index 00000000..15e66972 --- /dev/null +++ b/Timeline/Services/PathProvider.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Timeline.Services
+{
+ public interface IPathProvider
+ {
+ public string GetWorkingDirectory();
+ public string GetDatabaseFilePath();
+ }
+
+ public class PathProvider : IPathProvider
+ {
+ const string DatabaseFileName = "timeline.db";
+
+ private readonly IConfiguration _configuration;
+
+ private readonly string _workingDirectory;
+
+
+ public PathProvider(IConfiguration configuration)
+ {
+ _configuration = configuration;
+ _workingDirectory = configuration.GetValue<string>("WorkDir");
+ }
+
+ public string GetWorkingDirectory()
+ {
+ return _workingDirectory;
+ }
+
+ public string GetDatabaseFilePath()
+ {
+ return Path.Combine(_workingDirectory, DatabaseFileName);
+ }
+ }
+}
diff --git a/Timeline/Services/UserTokenService.cs b/Timeline/Services/UserTokenService.cs index cf7286f4..86f3a0f7 100644 --- a/Timeline/Services/UserTokenService.cs +++ b/Timeline/Services/UserTokenService.cs @@ -3,9 +3,10 @@ using Microsoft.IdentityModel.Tokens; using System;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
+using System.Linq;
using System.Security.Claims;
-using System.Text;
using Timeline.Configs;
+using Timeline.Entities;
namespace Timeline.Services
{
@@ -43,22 +44,25 @@ namespace Timeline.Services {
private const string VersionClaimType = "timeline_version";
- private readonly IOptionsMonitor<JwtConfig> _jwtConfig;
+ private readonly IOptionsMonitor<JwtConfiguration> _jwtConfig;
private readonly IClock _clock;
private readonly JwtSecurityTokenHandler _tokenHandler = new JwtSecurityTokenHandler();
private SymmetricSecurityKey _tokenSecurityKey;
- public JwtUserTokenService(IOptionsMonitor<JwtConfig> jwtConfig, IClock clock)
+ public JwtUserTokenService(IOptionsMonitor<JwtConfiguration> jwtConfig, IClock clock, DatabaseContext database)
{
_jwtConfig = jwtConfig;
_clock = clock;
- _tokenSecurityKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtConfig.CurrentValue.SigningKey));
- jwtConfig.OnChange(config =>
+ var key = database.JwtToken.Select(t => t.Key).SingleOrDefault();
+
+ if (key == null)
{
- _tokenSecurityKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(config.SigningKey));
- });
+ throw new InvalidOperationException(Resources.Services.UserTokenService.JwtKeyNotExist);
+ }
+
+ _tokenSecurityKey = new SymmetricSecurityKey(key);
}
public string GenerateToken(UserTokenInfo tokenInfo)
@@ -77,8 +81,7 @@ namespace Timeline.Services Subject = identity,
Issuer = config.Issuer,
Audience = config.Audience,
- SigningCredentials = new SigningCredentials(
- new SymmetricSecurityKey(Encoding.ASCII.GetBytes(config.SigningKey)), SecurityAlgorithms.HmacSha384),
+ SigningCredentials = new SigningCredentials(_tokenSecurityKey, SecurityAlgorithms.HmacSha384),
IssuedAt = _clock.GetCurrentTime(),
Expires = tokenInfo.ExpireAt.GetValueOrDefault(_clock.GetCurrentTime().AddSeconds(config.DefaultExpireOffset)),
NotBefore = _clock.GetCurrentTime() // I must explicitly set this or it will use the current time by default and mock is not work in which case test will not pass.
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs index 2640a061..14bd14cc 100644 --- a/Timeline/Startup.cs +++ b/Timeline/Startup.cs @@ -8,8 +8,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
-using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
-using Pomelo.EntityFrameworkCore.MySql.Storage;
using System;
using System.Text.Json.Serialization;
using Timeline.Auth;
@@ -37,6 +35,12 @@ namespace Timeline // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
+ var workDir = Configuration.GetValue<string?>("WorkDir");
+ if (workDir == null)
+ {
+ throw new InvalidOperationException("Please set a work directory first.");
+ }
+
services.AddControllers(setup =>
{
setup.InputFormatters.Add(new StringInputFormatter());
@@ -51,7 +55,7 @@ namespace Timeline options.InvalidModelStateResponseFactory = InvalidModelResponseFactory.Factory;
});
- services.Configure<JwtConfig>(Configuration.GetSection(nameof(JwtConfig)));
+ services.Configure<JwtConfiguration>(Configuration.GetSection("Jwt"));
services.AddAuthentication(AuthenticationConstants.Scheme)
.AddScheme<MyAuthenticationOptions, MyAuthenticationHandler>(AuthenticationConstants.Scheme, AuthenticationConstants.DisplayName, o => { });
services.AddAuthorization();
@@ -79,6 +83,8 @@ namespace Timeline });
}
+ services.AddScoped<IPathProvider, PathProvider>();
+
services.AddAutoMapper(GetType().Assembly);
services.AddTransient<IClock, Clock>();
@@ -94,27 +100,11 @@ namespace Timeline services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>();
- var databaseConfig = Configuration.GetSection(nameof(DatabaseConfig)).Get<DatabaseConfig>();
-
- if (databaseConfig.UseDevelopment)
- {
- services.AddDbContext<DatabaseContext, DevelopmentDatabaseContext>(options =>
- {
- if (databaseConfig.DevelopmentConnectionString == null)
- throw new InvalidOperationException("DatabaseConfig.DevelopmentConnectionString is not set. Please set it as a sqlite connection string.");
- options.UseSqlite(databaseConfig.DevelopmentConnectionString);
- });
- }
- else
+ services.AddDbContext<DatabaseContext>((services, options )=>
{
- services.AddDbContext<DatabaseContext, ProductionDatabaseContext>(options =>
- {
- if (databaseConfig.ConnectionString == null)
- throw new InvalidOperationException("DatabaseConfig.ConnectionString is not set. Please set it as a mysql connection string.");
- options.UseMySql(databaseConfig.ConnectionString,
- mySqlOptions => mySqlOptions.ServerVersion(new ServerVersion(new Version(5, 7), ServerType.MySql)));
- });
- }
+ var pathProvider = services.GetRequiredService<IPathProvider>();
+ options.UseSqlite($"Data Source={pathProvider.GetDatabaseFilePath()}");
+ });
}
diff --git a/Timeline/Timeline.csproj b/Timeline/Timeline.csproj index 08999f82..2dcc3c9f 100644 --- a/Timeline/Timeline.csproj +++ b/Timeline/Timeline.csproj @@ -21,15 +21,13 @@ <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.1" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.1" />
- <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
+ <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.2" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.2" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.2" />
+ <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
- <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.1" />
- <PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-dev002868" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
</ItemGroup>
@@ -119,6 +117,11 @@ <AutoGen>True</AutoGen>
<DependentUpon>UserService.resx</DependentUpon>
</Compile>
+ <Compile Update="Resources\Services\UserTokenService.Designer.cs">
+ <DesignTime>True</DesignTime>
+ <AutoGen>True</AutoGen>
+ <DependentUpon>UserTokenService.resx</DependentUpon>
+ </Compile>
</ItemGroup>
<ItemGroup>
@@ -187,5 +190,9 @@ <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>UserService.Designer.cs</LastGenOutput>
</EmbeddedResource>
+ <EmbeddedResource Update="Resources\Services\UserTokenService.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>UserTokenService.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
</ItemGroup>
</Project>
diff --git a/Timeline/appsettings.Development.json b/Timeline/appsettings.Development.json index 50eb9256..a2880cbf 100644 --- a/Timeline/appsettings.Development.json +++ b/Timeline/appsettings.Development.json @@ -5,11 +5,5 @@ "System": "Information",
"Microsoft": "Information"
}
- },
- "DatabaseConfig": {
- "UseDevelopment": true
- },
- "JwtConfig": {
- "SigningKey": "this is very very very very very long secret"
}
}
diff --git a/Timeline/appsettings.Production.json b/Timeline/appsettings.Production.json deleted file mode 100644 index 5d3db1bc..00000000 --- a/Timeline/appsettings.Production.json +++ /dev/null @@ -1,5 +0,0 @@ -{
- "DatabaseConfig": {
- "UseDevelopment": false
- }
-}
diff --git a/Timeline/appsettings.json b/Timeline/appsettings.json index 61491ff5..09840cd6 100644 --- a/Timeline/appsettings.json +++ b/Timeline/appsettings.json @@ -4,9 +4,9 @@ "Default": "Warning"
}
},
- "JwtConfig": {
+ "Jwt": {
"Issuer": "api.crupest.xyz",
- "Audience": "api.crupest.xyz"
+ "Audience": "api.crupest.xyz",
},
"Cors": [ "https://www.crupest.xyz", "https://crupest.xyz" ]
}
|