Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TelegramSearchBot.Database.Migrations.SearchCache
{
/// <inheritdoc />
public partial class InitSearchCacheDatabase : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "SearchPageCaches",
columns: table => new
{
Id = table.Column<Guid>(type: "TEXT", nullable: false),
UUID = table.Column<string>(type: "TEXT", nullable: false),
SearchOptionJson = table.Column<string>(type: "TEXT", nullable: false),
CreatedTime = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SearchPageCaches", x => x.Id);
});

migrationBuilder.CreateIndex(
name: "IX_SearchPageCaches_UUID",
table: "SearchPageCaches",
column: "UUID",
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "SearchPageCaches");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using TelegramSearchBot.Model;

#nullable disable

namespace TelegramSearchBot.Database.Migrations.SearchCache
{
[DbContext(typeof(SearchCacheDbContext))]
partial class SearchCacheDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "10.0.3");

modelBuilder.Entity("TelegramSearchBot.Model.Data.SearchPageCache", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");

b.Property<DateTime>("CreatedTime")
.HasColumnType("TEXT");

b.Property<string>("SearchOptionJson")
.IsRequired()
.HasColumnType("TEXT");

b.Property<string>("UUID")
.IsRequired()
.HasColumnType("TEXT");

b.HasKey("Id");

b.HasIndex("UUID")
.IsUnique();

b.ToTable("SearchPageCaches");
});
#pragma warning restore 612, 618
}
}
}
17 changes: 17 additions & 0 deletions TelegramSearchBot.Database/Model/SearchCacheDbContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using TelegramSearchBot.Common;

namespace TelegramSearchBot.Model {
public class SearchCacheDbContextFactory : IDesignTimeDbContextFactory<SearchCacheDbContext> {
public SearchCacheDbContext CreateDbContext(string[] args) {
var optionsBuilder = new DbContextOptionsBuilder<SearchCacheDbContext>();
var databasePath = Path.Combine(Env.WorkDir, "SearchCache.sqlite");

optionsBuilder.UseSqlite($"Data Source={databasePath};Cache=Shared;Mode=ReadWriteCreate;");

return new SearchCacheDbContext(optionsBuilder.Options);
}
}
}
2 changes: 1 addition & 1 deletion TelegramSearchBot/AppBootstrap/GeneralBootstrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static async Task Startup(string[] args) {
var searchCacheContext = serviceScope.ServiceProvider.GetRequiredService<SearchCacheDbContext>();
//context.Database.EnsureCreated();
context.Database.Migrate();
await searchCacheContext.Database.EnsureCreatedAsync();
await searchCacheContext.Database.MigrateAsync();
}

// 启动Host,SchedulerService作为HostedService会自动启动
Expand Down
Loading