protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "SearchCaches", columns: table => new { Id = table.Column <int>(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), TrackId = table.Column <int>(type: "integer", nullable: false), Cache = table.Column <NpgsqlTsVector>(type: "tsvector", nullable: true) }, constraints: table => { table.PrimaryKey("PK_SearchCaches", x => x.Id); table.ForeignKey( name: "FK_SearchCaches_Tracks_TrackId", column: x => x.TrackId, principalTable: "Tracks", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_SearchCaches_TrackId", table: "SearchCaches", column: "TrackId"); DatabaseSqlFilesExecuter.ExcuteSqlFilesForMigration(nameof(AddSearchCache), migrationBuilder); }
protected override void Up(MigrationBuilder migrationBuilder) { DatabaseSqlFilesExecuter.ExcuteSqlFilesForMigration(nameof(FillInitialData), migrationBuilder); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { DatabaseSqlFilesExecuter.SetContentPath(env.ContentRootPath); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // Обработка ошибок на сервере и отправка текста ошибки на клиент. app.UseExceptionHandler(c => c.Run(async context => { var exception = context.Features .Get <IExceptionHandlerPathFeature>() .Error; await context.Response.WriteAsJsonAsync(exception.Message); })); //app.UseHttpsRedirection(); app.UseStaticFiles(); var path = Path.Combine(env.ContentRootPath, @"covers"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(env.ContentRootPath, @"images"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider( Path.Combine(env.ContentRootPath, @"covers")), RequestPath = new PathString("/covers"), }); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider( Path.Combine(env.ContentRootPath, @"images")), RequestPath = new PathString("/images"), }); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSpaStaticFiles(); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 if (env.IsDevelopment()) { spa.Options.SourcePath = "musicServiceApp"; //Использование внешнего сервера для клиента. //Необходимо запустить ng serve в каталоге клиента spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); } }); // Запуск миграции БД using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { using (var context = scope.ServiceProvider.GetService <MusicServiceDbContext>()) { context.Database.Migrate(); //создание базы // подключение к порту базы - файл ConnectionString.json (сервер, порт, логин, пароль) } } }